You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Thomas Fischer <fi...@seitenbau.net> on 2007/10/02 10:16:31 UTC

Re: [core] display label from resource bundle in validation message

Hi Volker,

thanks for the hint, the sandbox component works for us.

Would it be a feature to incorporate this into the standard release ? I
must admit I do not understand the sandbox implementation. There, at the
start of (almost) every phase, the bundles are put in the request. I do not
think this is necessary, as the request lives on between the phases, so
there is no need to replace the variables every time.

IMHO, a cleaner way would be to store the information which bundle should
be loaded in the view root. Then, in the "restore view" phase, the view
root could load the bundles again and store them in the request, so they
would be available in every phase.

The only drawback to this is that in a postback, two (possibly) different
sets of resource bundles are stored in the request: The first set is the
one by the postback'ed view root, and the second one is that of the new
view to render. So there could be resource bundles available in the new
view which were not defined in the new view, which can lead to
hard-to-trace errors (but this problem also exists in the current sandbox
implementation). One could solve this by removing the "old" bundles before
the "render response" phase.

If the myfaces developers think this approach could make it into the
standard release, I would offer to propose a patch.

   regards,

       Thomas



weber.volker@googlemail.com schrieb am 28.09.2007 20:40:20:

> Hi Thomas,
>
> f:loadBundle stores the bundle in request-scope,
> you can use the loadBundle from sandbox as replacement:
> http://myfaces.apache.
>
org/sandbox/apidocs/org/apache/myfaces/custom/loadbundle/LoadBundleTag.html
>
>
> Regards,
>     Volker
>
>
>
> 2007/9/28, Thomas Fischer <fi...@seitenbau.net>:
> >
> > Hi all,
> >
> > We have an input field that looks like:
> >
> > <h:inputText
> >     id="street"
> >     required="true"
> >     value="#{someController.street}"
> >     binding="#{someController.streetInput}"
> >     label="street" />
> >
> > If the "required" validation fails, the label is be replaced into
> > placeholder {0} of the validation message "{0}: Validation Error: Value
is
> > required."
> >
> > Trying to internationalize the application, we now load the label from
a
> > resource bundle:
> >
> > <f:loadBundle basename="com.mycompany.messages.labels" var="labels"/>
> > <h:inputText
> >     id="street"
> >     required="true"
> >     value="#{someController.street}"
> >     binding="#{someController.streetInput}"
> >     label="#{labels['label.address.street']}" />
> >
> > Now, the label is not correctly replaced in the message; instead "null"
is
> > inserted into the placeholder. We have checked that the label is
accessed
> > correctly, the same expression in an outputText does find the message.
> >
> > I assume the following happens: The label replacement takes place in
the
> > processValidations phase (when the validation fails). In this phase.
the
> > message bundle is not yet registered (this happens in the
> > renderResponsePhase when the jsp page with the loadBundle is executed).
> >
> > I have also found the following remark in the class
> > org.apache.myfaces.taglib.core.LoadBundleTag, which points in the same
> > direction:
> >  * TODO:
> >  * We should find a way to save loaded bundles in the state, because
> > otherwise
> >  * on the next request the bundle map will not be present before the
render
> > phase
> >  * and value bindings that reference to the bundle will always log
annoying
> >  * "Variable 'xxx' could not be resolved" error messages.
> >
> > Does anybody have an idea how one could achieve this ?
> >
> >     Regards
> >
> >         Thomas
> >
> >
> >