Jsf 更新h:outputText并使用escape=";假;和值,其中包含'\u001c';
我有以下Java代码:Jsf 更新h:outputText并使用escape=";假;和值,其中包含'\u001c';,jsf,Jsf,我有以下Java代码: @Named @SessionScoped public class TestClass implements Serializable { private String stringValue; @PostConstruct private void init() { initStringValueDefault(); } public void initStringValue1() { st
@Named
@SessionScoped
public class TestClass implements Serializable {
private String stringValue;
@PostConstruct
private void init() {
initStringValueDefault();
}
public void initStringValue1() {
stringValue = "ABCD";
}
public void initStringValue2() {
stringValue = "EFGH" + '\u001c';
}
public void initStringValueDefault() {
stringValue = "LABEL TEXT";
}
public String getStringValue() {
return stringValue;
}
}
和.xhtml
<h:form id="testForm" prependId="true">
<h:outputText id="stringValueLabel" value="#{testClass.stringValue}" escape="false"/>
<br/>
<h:commandButton value="Set ABCD" actionListener="#{testClass.initStringValue1()}">
<f:ajax execute="@form" render="stringValueLabel"/>
</h:commandButton>
<span style="margin-left: 10px"/>
<h:commandButton value="Set EFGH + \u001c" actionListener="#{testClass.initStringValue2()}">
<f:ajax execute="@form" render="stringValueLabel"/>
</h:commandButton>
<span style="margin-left: 10px"/>
<h:commandButton value="Set default" actionListener="#{testClass.initStringValueDefault()}">
<f:ajax execute="@form" render="stringValueLabel"/>
</h:commandButton>
</h:form>
当我单击“设置ABCD”按钮时,更新工作成功。但单击“设置EFGH+\u001c”后,我得到错误:
使用escape=“true”一切正常,但我需要escape=“false”。通过使用org.apache.commons.lang3.StringEscapeUtils的方法escapeXml11(字符串输入)处理变量来解决问题:
import static org.apache.commons.lang3.StringEscapeUtils.escapeXml11;
...
public void initStringValue2() {
stringValue = "EFGH" + '\u001c';
stringValue = escapeXml11(stringValue);
}
...
通过使用org.apache.commons.lang3.StringEscapeUtils的方法escapeXml11(字符串输入)处理变量,问题得以解决:
import static org.apache.commons.lang3.StringEscapeUtils.escapeXml11;
...
public void initStringValue2() {
stringValue = "EFGH" + '\u001c';
stringValue = escapeXml11(stringValue);
}
...
你是说它不需要
f:ajax
?你是说它不需要f:ajax
?