myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leonardo Uribe (JIRA)" <...@myfaces.apache.org>
Subject [jira] [Commented] (MYFACES-4055) Localized JSF error and information messages not displayed
Date Thu, 11 Aug 2016 02:31:20 GMT

    [ https://issues.apache.org/jira/browse/MYFACES-4055?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15416400#comment-15416400
] 

Leonardo Uribe commented on MYFACES-4055:
-----------------------------------------

First of all, MyFaces is JSR-344 compliant. It is just some things has changed over time.
Let me explain this a bit.

The code comes from JSF 1.0 and it has not been changed since that time. In that time, jsf
jars were bundled inside WEB-INF/lib. But in JSF 2.0 and now with new containers like TomEE
or compatible with OSGi, the jsf jars has become a library shared by different web applications
at the same time. So, the classloader logic in some cases became a bit blurry.

I can remember cases like with JBoss 4 were the server get confused about which jsf jar instance
should it pick. The code you can see tackle those cases, trying to get Messages.properties
from MyFaces jars, so in that context, the code is correct.

Reading the spec, JSF 2.2 section 2.5.2.4 says this: "... A JSF application may provide its
own messages, or overrides to the standard messages by supplying a <messagebundle> element
to in the application configuration resources ...". But this line is a bit controversial,
because it is supposed to mean "by supplying to add a new ".

If you are trying to override the standard, adding a new translation, why don't just contribute
the file? 

Is this a bug? no, instead it is a side effect caused by the container. I guess the logic
used in org.apache.myfaces.shared.util.MessageUtils (call context classloader, then call local
classloader) is the right one, so there is merit to fix it at least in 2.2.x branch. But it
is better if we can include a new translation of Messages.properties (if any) on the way.



> Localized JSF error and information messages not displayed
> ----------------------------------------------------------
>
>                 Key: MYFACES-4055
>                 URL: https://issues.apache.org/jira/browse/MYFACES-4055
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: JSR-344
>    Affects Versions: 2.2.10
>         Environment: Java 8, TomEE 7, Primefaces 6.0, Omnifaces 2.3
>            Reporter: Petras
>              Labels: localization, messages
>         Attachments: full-submit.png, partial-submit.png
>
>
> I have localized JSF error and information messages as described in JSR-344 Section "2.5.2.4
Localized Application Messages", which defines how applications may provide own JSF messages,
 and prepared resource bundle "javax.faces.Messages". In _faces-config.xml_ I set:
> {{<message-bundle>javax.faces.Messages</message-bundle>}}.
> But these resources are not always used, when value validation in UI input component
fail. Consider the following snippet which illustrates the issue. It contains 2 input text
fields, the first one has "required" attribute. The second field is validated using Bean Validation
framework:
> {code:xml}
> <h:form id="form">
>     <p:panel header="Validate">
>         <h:panelGrid columns="3" cellpadding="5">
>             
>             <!-- JSF validation -->
>             <h:outputLabel for="client1" value="JSF Validation" />
>             <h:inputText id="client1" label="JSF Validation" value="#{validationModel.requiredClient}"
required="true"/>
>             <h:message for="client1" display="both" errorStyle="color: red" />
>             
>             <!-- Bean validation -->
>             <h:outputLabel for="bean0" value="Bean Validation" />
>             <h:inputText id="bean0" label="Bean Validation" value="#{validationModel.requiredAnnotated}"
/>
>             <h:message for="bean0" display="both" errorStyle="color: red" />
>         </h:panelGrid>
>         <!-- submit without ajax -->
>         <h:commandButton value="Save" action="#{validationModel.save}" />
>         <!-- submit with ajax -->
>         <h:commandButton value="Save (ajax)" actionListener="#{validationModel.save}"
>
>             <f:ajax execute="form" render="form"/>
>         </h:commandButton>
>     </p:panel>
> </h:form>
> {code}
> The backing bean:
> {code:java}
> @Named @RequestScoped
> public class ValidationModel implements DecisionProcessable {
>     @NotNull @Length(min = 1, max = 64)
>     private String requiredAnnotated;
>     private String requiredClient;
>     // getters and setters
>     public void save() {
>         System.out.println(this);
>     }
> }
> {code}
> If I click the button "Save", which performs full submit, I get localized error message.
If I click "Save (ajax)", which performs partial submit with ajax, the JSF validation error
message is not localized.
> I did some debugging and noticed that validation logic uses {{_MessageUtils}} class to
obtain resource bundle for the messages, but this utility class uses FacesContext class ClassLoader
to find resource bundle. The problem is that this ClassLoader does not always refer to web
application classloader. When the partial submit is performed, it refers to Tomcat common
classloader, which surely does not see web application resources.
> The fix probably would be the same as implemented in {{MessageUtils}}, which uses Thread.currentThread().getContextClassLoader()
on ResourceBundle (MYFACES-338).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message