2017-04-24 61 views
0

如何在tag屬性內添加outputFormat?如何在output屬性中添加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

'#{of:format1('one {0}','two')}'http://showcase.omnifaces.org/functions/Strings –

+0

jsf或primefaces的任何其他選項? – Joe

+1

向bean中添加一個格式化方法,並在那裏進行格式化。另見https://github.com/omnifaces/omnifaces/blob/2.6/src/main/java/org/omnifaces/el/functions/Strings.java#L255 –

回答

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(); 
}