2015-07-11 17 views
1

我在webapp中使用國際化,我想再次使用一些消息。
faces-config.xml中爲什麼f:param值未被設置爲來自資源包的消息?

<locale-config> 
     <default-locale>en</default-locale> 
     <supported-locale>uk</supported-locale> 
    </locale-config> 
    <resource-bundle> 
     <base-name>international.message-labels</base-name> 
     <var>msgLabel</var> 
    </resource-bundle> 

消息從資源束

inputLength=Length should be {0} or more 

實施例:

<p:inputText id="firstName" value="#{user.firstName}" 
       placeholder="#{msgLabel.namePlaceHolder}" size="25" required="true" 
       styleClass="logRegLabel" validatorMessage="#{msgLabel.inputLength}" 
       requiredMessage="#{msgLabel.fieldCannotEmpty}"> 
       <f:param value="3" /> 
       <f:validateLength minimum="3" /> 
       <p:ajax event="blur" update="firstNameMsg" global="false" /> 
      </p:inputText> 

在我看到它的工作原理的例子。但在我的情況下,我總是得到Length should be {0} or more而不是Length should be 3 or more
我想這validatorMessage="#{msgLabel['inputLength']}"
另外,我試圖刪除的p:inputText所有其它參數,但它並沒有幫助

回答

2

<f:param>參數化捆綁消息作品裏面只有<h:outputFormat>

<h:outputFormat value="#{bundle.key}"> 
    <f:param value="value for {0}" /> 
    <f:param value="value for {1}" /> 
    <f:param value="value for {2}" /> 
</h:outputFormat> 

JSF不提供任何參數化任意屬性值的工具。你最好的選擇是建立一個custom EL function其做工作象下面這樣:

<p:inputText ... validatorMessage="#{my:format1(msgLabel.inputLength, '3')}" /> 

如果你碰巧使用JSF工具庫OmniFaces,那麼你可以使用它的of:format1()了點。

<p:inputText ... validatorMessage="#{of:format1(msgLabel.inputLength, '3')}" /> 

或其<o:outputFormat>其支持在EL變量中捕獲輸出。

<o:outputFormat value="#{msgLabel.inputLength}" var="validatorMessage"> 
    <f:param value="3" /> 
</o:outputFormat> 
<p:inputText ... validatorMessage="#{validatorMessage}" /> 
相關問題