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

試したことはありませんが、次のようなカスタムコンバーターを使用できます(Converts \nto <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 に答える
0

h:outputTextとの両方がh:inputTextデフォルトですでにXML エンティティをエスケープしています。でできるように、 でオフにすることさえh:inputTextできませんh:outputText。あなたの問題は別の場所にあります。「エスケープ XML」の理解/定義が間違っている可能性があります。また、あなたの例は、 XML エスケープを無効<context-param>にすることを示唆しています。Web アプリケーションがXSS攻撃を受けやすくなるため、これを行うことはできません。あなたはそれをしたくありません。h:inputText

于 2010-10-16T17:03:56.870 に答える
0

レンダラーをオーバーライドし<h:outputText>、テキストをエスケープする部分をコメントアウトします。次に、レンダラーを に登録しますfaces.config.xml

もちろん、これはそのタグを使用している場合にのみ機能します。式を出力するだけでは機能しません#{bean.value}

個人的には、エスケープ属性を追加する必要があることに固執したいと思います。

于 2009-09-28T19:16:35.773 に答える