Thanks to all,
this is a working solution, but i didn't want to instantiate another
ResourceBundle, struts already have one.
I solve the problem after i check the struts source:
[...]
if (orgName == null || orgName.equals("")) {
//errors.add("orgName", new
ActionMessage("employer.orgName.requiredfield"));
MessageResources resources = ((MessageResources)
request.getAttribute(Globals.MESSAGES_KEY));
Locale locale = RequestUtils.getUserLocale(request, null);
String fieldName = resources.getMessage(locale, "employer.orgName");
errors.add("orgName", new ActionMessage("employer.requiredfield",
fieldName));
}
[...]
from struts Action source:
/**
* <p>Return the user's currently selected Locale.</p>
*
* @param request The request we are processing
*/
protected Locale getLocale(HttpServletRequest request) {
return RequestUtils.getUserLocale(request, null);
}
[...]
/**
* <p>Return the default message resources for the current module.</p>
*
* @param request The servlet request we are processing
* @since Struts 1.1
*/
protected MessageResources getResources(HttpServletRequest request) {
return ((MessageResources) request.getAttribute(Globals.MESSAGES_KEY));
}
[...]
again, thanks to all!!!
El mié, 24 de 05 de 2006 a las 15:33, Vinit Sharma escribió:
> Load resource bundle and get the message from bundle:
>
> ResourceBundle labels =
> ResourceBundle.getBundle(
> "properties/ApplicationResources",
> (Locale) request.getSession().getAttribute(
> Globals.LOCALE_KEY));
>
> String orgName = labels.getString("employer.orgName");
>
> errors.add("orgName", new ActionMessage("employer.requiredfield", orgName));
>
> HTH,
>
> On 5/24/06, navin mca <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> >
> >
> > Follow these steps.
> >
> > 1. Define ApllicationResources_locale specific property file.
> >
> > 2. add the message keys to thse different locale specific property file.
> >
> > 3. in Jsp file set the locale based on the reuest parameters.
> > with
> > <fmt:setlocale tag or set manually locale
> >
> > Hope this will help u.
> >
> >
> >
> > Jorge Martí(r)Cuervo <[EMAIL PROTECTED]> wrote:
> > Hi all,
> >
> > i want to use externalized messages in the validation errors of a
> > ActionForm subclass.
> >
> > I have this code:
> >
> > [...]
> > public ActionErrors validate(ActionMapping mapping, HttpServletRequest
> > request) {
> >
> > ActionErrors errors = new ActionErrors();
> >
> > /*
> > * required fields
> > */
> > if (orgName == null || orgName.equals("")) {
> > errors.add("orgName", new
> > ActionMessage("employer.orgName.requiredfield"));
> > }
> > [...]
> >
> > and works pretty good, but i want to use ActionMessages with a parameter
> > with the name of the required field. For instance:
> >
> > [...]
> > if (orgName == null || orgName.equals("")) {
> > errors.add("orgName", new
> >
> > ActionMessage("employer.requiredfield", "employer.orgName"));
> > }
> > [...]
> >
> > But in jsp view, it generates
> >
> > "employer.orgName is required"
> >
> >
> > I want to get the ResourceBundle to "translate" the employer.orgName to
> > the value assigned in .properties file.
> >
> > How can i do it?
> >
> > thanks
> >
> > --
> > ;-)
> > ____________________________________
> > Jorge Martin Cuervo
> > Analista Programador
> >
> > Outsourcing Emarketplace
> > deFacto Powered by Standards
> >
> > email
> > voz +34 985 129 820
> > voz +34 660 026 384
> > ____________________________________
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> >
> > Thanks and Regards,
> > Novin Jaiswal
> > +919890089443(M)
> > +912039511388(H)
> > +912026901306(O) direct
> > +912026982424 Extn:1306
> >
> > ---------------------------------
> > Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates.
> >
--
;-)
____________________________________
Jorge Martin Cuervo
Analista Programador
Outsourcing Emarketplace
deFacto Powered by Standards
email <[EMAIL PROTECTED]>
voz +34 985 129 820
voz +34 660 026 384
____________________________________