문제

I am working on JSF2.2 at my work place. My faces-config.xml has the resource bundle tag which helps me to assign a variable to a property file and use the variable in a EL.

   <resource-bundle>
    <base-name>properties.common</base-name>
    <var>prop</var>
   </resource-bundle>

I also found another way of achieving this by using the f:loadBundle tag like this

<f:loadBundle basename="properties.common" var="prop"/>

But this is a localized solution, meaning I would have to write this in every page.

  1. Would this work if i define this in a template ? If yes, how do i achieve it.

  2. Is there any other way that i can declare the resource globally with a variable to be used in an EL(like in the case of faces-config.xml)

도움이 되었습니까?

해결책

Would this work if i define this in a template ?

Yes.


If yes, how do i achieve it.

Just do exactly as you said. Define it in a template.


Is there any other way that i can declare the resource globally with a variable to be used in an EL(like in the case of faces-config.xml)

Put it in request map yourself in (post)constructor of a request scoped bean which is referenced in the view.

ResourceBundle bundle = ResourceBundle.getBundle("properties.common", facesContext.getViewRoot().getLocale());
externalContext.getRequestMap().put("prop", bundle);

It can even be referenced as a property of a request scoped bean and this guarantees construction of the bean even if it's not referenced elsewhere in the view.

다른 팁

This is exactly what Iam looking for, see my post https://stackoverflow.com/questions/24461307/jsf-2-external-resource-bundle

ResourceBundle bundle = ResourceBundle.getBundle("properties.common",facesContext.getViewRoot().getLocale());
externalContext.getRequestMap().put("prop", bundle);

thanks all...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top