Jsf 更新h:outputText并使用escape=";假;和值,其中包含'\u001c';

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

我有以下Java代码:

@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”后,我得到错误:

  • Chrome:“localhost:8080上的页面显示:emptyResponse:从服务器接收到一个空响应。”
  • Firefox:'malformedXML:XML解析错误:格式不正确'
  • 而且标签还没有更新。重新加载页面后,标签更新为“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