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

Petras commented on MYFACES-4055:
---------------------------------

I'm sorry, English is not my native language and therefore I do not catch the 
controversy you see in the spec. If application provides it's own message 
bundle in <messagebundle> element, they are "new" to JSF implementation. If it 
contains the keys for standard messages, they meant to override the standard 
messages. MyFaces should follow the algorithm laid in section 2.5.2.4:
{quote}
The following algorithm must be used to create a FacesMessage instance given a 
message key.
Call getMessageBundle() on the Application instance for this web application, 
to determine if the
application has defined a resource bundle name. If so, load that ResourceBundle 
and look for the message there.
If not there, look in the javax.faces.Messages resource bundle.
{quote}
To my understanding it clearly states that MyFaces should always check web 
application resources first. If so, it also should be consistent with this 
algorithm (despite whether submit  was with or without Ajax).

Our localized bundle is not complete, it only contains messages for validations 
we used and its format does not follow the standard like:
{quote}
\{2\}: "\{0\}" \[Validation error:\] message
{quote}
I'll check maybe I could change it to be universally used and attach to this 
thread.

> 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)

Reply via email to