JSF EL expressions to check empty string in propery file?

百般思念 提交于 2019-12-09 03:56:29

问题


I have to check if my property file is empty for certain label based on that I have to render the element but even when the label is empty i still get the element displaying key:

           <h:panelGroup  rendered="#{not empty I18N['key_hint_message'] }">
          <h:outputLabel id="hint_label" value="#{I18N['key_label_hint']}
           "></h:outputLabel>
          <h:outputText value="#{I18N['key_hint_message']}" ></h:outputText>
          </h:panelGroup>

回答1:


You can use ResourceBundle#containsKey() for this.

<h:panelGroup rendered="#{I18N.containsKey('key_hint_message')}">
    <h:outputLabel value="#{I18N['key_label_hint']}" />
    <h:outputText value="#{I18N['key_hint_message']}" />
</h:panelGroup>

You'd better not rely on default format of missing keys as this can be overriden by a custom resource bundle resolver.




回答2:


JSF implementation displays by defaults missing resources as ???resource???, So you can use the fn:contains JSTL function in your rendered attribute like this:

 <h:panelGroup  rendered="${not fn:contains(I18N['key_hint_message'], '???')}">
      <h:outputLabel id="hint_label" value="#{I18N['key_label_hint']}"/>
      <h:outputText value="#{I18N['key_hint_message']}" />
 </h:panelGroup>


来源:https://stackoverflow.com/questions/28047100/jsf-el-expressions-to-check-empty-string-in-propery-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!