2015-12-17 50 views
1

我有以下的Java代码:更新H:用的outputText逃逸= “假” 和值,包含 ' u001c'

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

  1. 铬:“在本地主机页面:8080说:emptyResponse:一个空的响应是从服务器接收到的。”
  2. 火狐: 'malformedXML:XML解析错误:没有很好地形成'

和标签尚未更新。在页面重新加载标签更新为'EFGH'后。

任何人都知道,为什么由于向变量添加'\ u001c',点击按钮后更新不起作用?

使用escape =“true”一切正常,但我需要escape =“false”。

+0

你说这工作没有'F:ajax'? – Kukeltje

回答

0

问题是由与org.apache.commons.lang3.StringEscapeUtils的方法escapeXml11(字符串输入)治疗变量解决:

import static org.apache.commons.lang3.StringEscapeUtils.escapeXml11; 
... 
    public void initStringValue2() { 
     stringValue = "EFGH" + '\u001c'; 
     stringValue = escapeXml11(stringValue); 
    } 
...