0

我总是使用这样的 el 表达式;

<h:outputText value="#{bean.value}" escape="true" />;

而且我无法在输入字段中从 xml 中逃脱:

<h:inputText value="#{bean.value}" />

有没有办法在 facelets 中完全转义 xml。

例如上下文参数;

<context-param>
  <param-name>facelets.ESCAPE_XML</param-name>
  <param-value>false</param-value>
</context-param>
4

3 回答 3

0

h:outputTexth:inputText默认情况下都已经转义了 XML 实体。你甚至不能h:inputText像在h:outputText. 你的问题出在其他地方。也许您对“转义 XML”的理解/定义是错误的。此外,您的<context-param>示例建议您要禁用XML 转义。你不能这样做,h:inputText因为你的 webapp 很容易受到XSS 攻击。你不想拥有那个。

于 2010-10-16T17:03:56.870 回答
0

覆盖渲染器<h:outputText>注释掉它转义文本的部分。然后在你的faces.config.xml.

当然,这仅在您使用该标签时才有效。如果你只输出一个表达式,它就行不通,例如#{bean.value}

就个人而言,我宁愿坚持必须添加转义属性。

于 2009-09-28T19:16:35.773 回答
0

没有尝试过,但您可以使用像下面这样的自定义转换器(转换\n<br/>

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.apache.commons.lang.StringUtils;

public class BreakLineConverter implements Converter {

    /**
     * No conversion required 
     */
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        return value;
    }

    /**
     * Converts All \r  \n  \r\n  into break
     */
    public String getAsString(FacesContext context, UIComponent component, Object value) {      
        if (null==value || StringUtils.isEmpty((String)value))
            return "";      
        String val=value.toString();
        //This will take care of Windows and *nix based line separators
        return val.replaceAll("\r\n", "<br />").replaceAll("\r", "<br />").replaceAll("\n", "<br />");
    }

}

在 faces-config.xml 中注册转换器

<converter>
    <description>Converts data to be displayed in web format
    </description>
     <converter-id>BreakLineConverter</converter-id>
    <converter-class>comp.web.converter.BreakLineConverter</converter-class>
</converter>
于 2009-09-30T16:11:37.403 回答