如何使用outputFormat inside tag属性添加参数化消息属性

时间:2017-04-24 12:24:19

标签: jsf primefaces properties internationalization jsf-2.2

如何在标记属性中添加outputFormat?

示例

...
<p:column headerText="#{msgs.actions}">
    <p:commandButton id="btnDelEspai" icon="fa fa-trash Fs16 White"
                     styleClass="Fright RedButton" iconPos="right"
                     action="#{espaisBean.deleteEspai()}"
                     title="#{msgs.esp_delete}"
                     update="frmEspais:tblEspais frmEspais:error_panel">
        <p:confirm header="#{msgs.delconfirmation}"
                   message="ADD CODE HERE" icon="ui-icon-alert">
        </p:confirm>
        <f:setPropertyActionListener value="#{e}"
                                     target="#{espaisBean.selEspai}" />
    </p:commandButton>
</p:column>
...

要添加的代码

<h:outputFormat value="#{msgs.esp_delconfirmation_id}" >
    <f:param value="#{e.id}"/>
</h:outputFormat>

1 个答案:

答案 0 :(得分:0)

只需使用EL调用方法即可。您可以使用OmniFaces中已有此类方法的String functions

#{of:format1('one {0}', 'two')}

或者您可以在bean中创建自己的方法:

XHTML:

#{yourBean.format1('one {0}', 'two')}

豆:

public String format1(String pattern, Object param) {
    StringBuffer result = new StringBuffer();
    new MessageFormat(pattern, getLocale()).format(param, result, null);
    return result.toString();
}