You want to inernationalize your labels/messages/text - but not the names of
your properties on your form bean - if you had a property "house" - you
wouldn't have a different property on your form bean depending on the Locale
(getHouse() / setHouse() for English and getMaison() setMaison() for
French) - you label the field with an inernationalized message - but the
field name and associated property in your form bean is always the same -
"house" in this example. You need to add messages for that field/property
under the property name "house" - not under the value of the field label
(i.e. "house" in English or "maison" in French) because that gives it an
association with the field (which you also use the property name) on your
form. So what you had on your jsp is correct

    <bean:message key="label.house"/>
   <html:text property="house"/>
    <html:messages id="msg" property="house">...</html:messages>

Where you are going wrong is in the validate method of your ActionForm. The
following is correct...

    String label = resources.getMessage("label.password");
    ActionMessage message = new
    ActionMessage("validation.error.requiredfield", label);

The above gets the internationalized message and replaces an argument with
an internationalized parameter. So presumably you have something like

   validation.error.requiredfield={0} is required
   label.password=password

and the above code has created an ActionMessage with the key to the message
(i.e. "validation.error.requiredfield") and the internationalized text for
the label (i.e. "password"). Now where I believe you are going wrong is the
next step. You have......

    errors.add(label, message);

But what you want to do is have...

    errors.add("password", message);

What your're doing is associating the message with a property/field on your
form - its just a key, not something you display to the user - all that is
in the associated ActionMessage - its very purpose is so that the
<html:messages> or <html:errors> tags can pick out the messages for a
specific form field. Once they find those message(s) - they get the key to
your internationalized message from the associated ActionMessage and look it
up in the resource bundle.

Niall

----- Original Message ----- 
From: "Chris Cheshire" <[EMAIL PROTECTED]>
Sent: Friday, February 17, 2006 4:23 PM


Internationalisation.

Resource bundle contains (among other things):
label.password=password

The label of the field is looked up from the resource bundle:
<td><b><bean:message key="label.password" /></b></td>

The validation error in the form is keyed on that same value, looked
up from the resource bundle:
String label = resources.getMessage("label.password");
ActionMessage message = new
ActionMessage("validation.error.requiredfield", label);
errors.add(label, message);

So far, nowhere has the value 'password' been coded directly in.

So how do I extract the error in the jsp *by using a resource key
lookup*, not using the value 'password' directly?

This:

<html:messages id="message" message="false" property="password">

breaks internationalisation.

What happens when a resource bundle in another language is used. It is
no longer keyed on 'password', because the other places have used a
resource lookup to get the new value.

How do I do it so that the value of property in html:messages is
extracted from a resource bundle lookup like the bean:message is, like
 the creation of the ActionError is?


On 2/17/06, Niall Pemberton <[EMAIL PROTECTED]> wrote:
> So what are you after? Why do you need to use a value from the resources
as
> the message property?
>
> Niall
>
> ----- Original Message -----
> From: "Chris Cheshire" <[EMAIL PROTECTED]>
> Sent: Friday, February 17, 2006 7:09 AM
>
>
> Yes what I have in my code is exactly what is in the example. It is
> not however what I am after.
>
> What is the point of using things from the resource bundle if it only
> works through 3/4 of the application?
>
> I have the error message next to the input field, by hardcoding the
> result of what would be a lookup to the resource bundle, as in that
> example. I don't want that.
>
> I want to be able to look up the value just like the bean:message tag
does.
>
> On 2/16/06, Niall Pemberton <[EMAIL PROTECTED]> wrote:
> > Did you try my suggestion - I believe that will do exactly what you
want -
> > you seem to be getting confused between the key used to store the
> > ActionErrors in the request (global error key) and the property under
> which
> > a message is stored in the ActionErrors.
> >
> > The validwhen example in the struts-examples does exactly what you say
> (show
> > error messages next to their respective form fields) - so you could take
a
> > look at that (struts-examples.war in the binary distro):
> >
> >     http://tinyurl.com/c2emd
> >
> > I think if you make the change I suggested it will do what you want -
> maybe
> > its worth a try?
> >
> > Niall
> >
> > From: "Chris Cheshire" <[EMAIL PROTECTED]>
> > Sent: Friday, February 17, 2006 3:36 AM
> >
> >
> > That's not the issue, it is actually doing that, via a resource bundle
> > lookup (I only have one configured). I want to be able to retrieve the
> > error on the jsp side by getting the key via the resource bundle
> > similar to the way it is being added, instead of just using the value
> > that is referenced in the resource bundle.
> >
> > The field label is being printed via a message bundle lookup (using
> > bean:message tag), and the error for that field is stored using that
> > same key.
> >
> > I want to retrieve the error not by the discrete value "password", but
> > by a key lookup to the message bundle that produces the value
> > "password".
> >
> > Chris
> > On 2/16/06, Niall Pemberton <[EMAIL PROTECTED]> wrote:
> > > Modify your code to do this:
> > >
> > >             errors.add("password", message);
> > >
> > >
> >
>
http://www.niallp.pwp.blueyonder.co.uk/HelpTagsErrorsAndMessages.html#section5
> > >
> > > Niall
> > >
> > > ----- Original Message -----
> > > From: "Chris Cheshire" <[EMAIL PROTECTED]>
> > > Sent: Friday, February 17, 2006 1:50 AM
> > >
> > >
> > > I have an ActionForm with its own validate method that adds errors
> > > keyed upon entries in a resource bundle, so that the errors can be
> > > linked back to the field they are pertinent to, not just as a global
> > > error.
> > >
> > >             String label = resources.getMessage("label.password");
> > >             ActionMessage message = new
> > > ActionMessage("validation.error.requiredfield", label);
> > >             errors.add(label, message);
> > >
> > >
> > > I have the error displaying next to the input field in the jsp page
via
> :
> > >
> > >           <td><b><bean:message key="label.password" /></b></td>
> > >           <td><html:password property="password" size="20"
> > > maxlength="20" /></td>
> > >           <td>
> > >             <html:messages id="message" message="false"
> > property="password">
> > >               <bean:write name="message" /><br>
> > >             </html:messages>
> > >           </td>
> > >
> > > Unfortunately the value of "property" is hardcoded in the
> > > html:messages tag. What I have there is the value stored in the
> > > resource bundle under "label.password", as is used to display next to
> > > the input field in the bean:message tag.
> > >
> > > How can I extract the value from the resource bundle when using it as
> > > a value for the property field, instead of hard coding it in, which
> > > defeats the purpose of the resource bundle.
> > >
> > > Thanks
> > >
> > > Chris
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to