You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "J. Garcia" <jo...@gmail.com> on 2012/10/19 14:10:27 UTC

getText in error messages: resource bundle or bean value?

Hi,
I'm having a problem with getText().
I have the following xml validator:

    <field name="user.confirmPassword">
        <field-validator type="requiredstring">
            <message key="errors.required"/>
        </field-validator>
        <field-validator type="fieldexpression">
            <param name="expression">
                (user.confirmPassword.equals(user.password))
            </param>
            <message key="errors.confirmPassSame"/>
        </field-validator>
    </field>

And the error message is defined in a bundle like this:
errors.confirmPassSame=The ${getText(user.confirmPassword)} field has to
have the same value as the ${getText(user.password)} field.
...
user.confirmPassword=Confirm Password
user.password=Password

I would expect a message like:
The Confirm Password field has to have the same value as the Password field.

However, when the error message is shown, instead of the text from the
resource bundle, what is shown are the actual values of the bean, like this:
The abcd field has to have the same value as the 1234 field.

Is this a bug in getText()?

Cheers,
J. Garcia

Re: getText in error messages: resource bundle or bean value?

Posted by "J. Garcia" <jo...@gmail.com>.
Mi mistake. Sorry.

The resource error message I was using is in fact:

errors.confirmPassSame=The ${user.confirmPassword} field has to have the
same value as the ${user.password} field.

whereas it should be:

errors.confirmPassSame=The ${getText("user.confirmPassword")} field has to
have the same value as the ${getText("user.password")} field.

Solved!


On Fri, Oct 19, 2012 at 2:10 PM, J. Garcia <jo...@gmail.com> wrote:

> Hi,
> I'm having a problem with getText().
> I have the following xml validator:
>
>     <field name="user.confirmPassword">
>         <field-validator type="requiredstring">
>             <message key="errors.required"/>
>         </field-validator>
>         <field-validator type="fieldexpression">
>             <param name="expression">
>                 (user.confirmPassword.equals(user.password))
>             </param>
>             <message key="errors.confirmPassSame"/>
>         </field-validator>
>     </field>
>
> And the error message is defined in a bundle like this:
> errors.confirmPassSame=The ${getText(user.confirmPassword)} field has to
> have the same value as the ${getText(user.password)} field.
> ...
> user.confirmPassword=Confirm Password
> user.password=Password
>
> I would expect a message like:
> The Confirm Password field has to have the same value as the Password
> field.
>
> However, when the error message is shown, instead of the text from the
> resource bundle, what is shown are the actual values of the bean, like this:
> The abcd field has to have the same value as the 1234 field.
>
> Is this a bug in getText()?
>
> Cheers,
> J. Garcia
>

Re: getText in error messages: resource bundle or bean value?

Posted by "J. Garcia" <jo...@gmail.com>.
You are right!

On Fri, Oct 19, 2012 at 2:54 PM, Hoying, Ken <Ke...@premierinc.com>wrote:

> I believe that your problem is that the field names are the same as your
> label names and with the validator both are in the stack.
> ${getText(user.password)} is first evaluating user.password and finding the
> field value "1234".  getText is then trying to locate an entry for "1234"
> and cannot find one so it is just return "1234".
>
> It might work if you try ${getText('user.password')}.  Otherwise, you may
> need to rename it.
>
> -----Original Message-----
> From: J. Garcia [mailto:jogaco.en@gmail.com]
> Sent: Friday, October 19, 2012 8:10 AM
> To: Struts Users Mailing List
> Subject: getText in error messages: resource bundle or bean value?
>
> Hi,
> I'm having a problem with getText().
> I have the following xml validator:
>
>     <field name="user.confirmPassword">
>         <field-validator type="requiredstring">
>             <message key="errors.required"/>
>         </field-validator>
>         <field-validator type="fieldexpression">
>             <param name="expression">
>                 (user.confirmPassword.equals(user.password))
>             </param>
>             <message key="errors.confirmPassSame"/>
>         </field-validator>
>     </field>
>
> And the error message is defined in a bundle like this:
> errors.confirmPassSame=The ${getText(user.confirmPassword)} field has to
> have the same value as the ${getText(user.password)} field.
> ...
> user.confirmPassword=Confirm Password
> user.password=Password
>
> I would expect a message like:
> The Confirm Password field has to have the same value as the Password
> field.
>
> However, when the error message is shown, instead of the text from the
> resource bundle, what is shown are the actual values of the bean, like
> this:
> The abcd field has to have the same value as the 1234 field.
>
> Is this a bug in getText()?
>
> Cheers,
> J. Garcia
>
> -----------------------------------------
> ***Note:The information contained in this message may be privileged and
> confidential and protected from disclosure. If the reader of this message
> is not the intended recipient, or an employee or agent responsible for
> delivering this message to the intended recipient, you are hereby notified
> that any dissemination, distribution or copying of this communication is
> strictly prohibited.  If you have received this communication in error,
> please notify the Sender immediately by replying to the message and
> deleting it from your computer.  Thank you.  Premier Inc.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

RE: getText in error messages: resource bundle or bean value?

Posted by "Hoying, Ken" <Ke...@PremierInc.com>.
I believe that your problem is that the field names are the same as your label names and with the validator both are in the stack. ${getText(user.password)} is first evaluating user.password and finding the field value "1234".  getText is then trying to locate an entry for "1234" and cannot find one so it is just return "1234".

It might work if you try ${getText('user.password')}.  Otherwise, you may need to rename it.

-----Original Message-----
From: J. Garcia [mailto:jogaco.en@gmail.com] 
Sent: Friday, October 19, 2012 8:10 AM
To: Struts Users Mailing List
Subject: getText in error messages: resource bundle or bean value?

Hi,
I'm having a problem with getText().
I have the following xml validator:

    <field name="user.confirmPassword">
        <field-validator type="requiredstring">
            <message key="errors.required"/>
        </field-validator>
        <field-validator type="fieldexpression">
            <param name="expression">
                (user.confirmPassword.equals(user.password))
            </param>
            <message key="errors.confirmPassSame"/>
        </field-validator>
    </field>

And the error message is defined in a bundle like this:
errors.confirmPassSame=The ${getText(user.confirmPassword)} field has to
have the same value as the ${getText(user.password)} field.
...
user.confirmPassword=Confirm Password
user.password=Password

I would expect a message like:
The Confirm Password field has to have the same value as the Password field.

However, when the error message is shown, instead of the text from the
resource bundle, what is shown are the actual values of the bean, like this:
The abcd field has to have the same value as the 1234 field.

Is this a bug in getText()?

Cheers,
J. Garcia

-----------------------------------------
***Note:The information contained in this message may be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.  If you have received this communication in error, please notify the Sender immediately by replying to the message and deleting it from your computer.  Thank you.  Premier Inc.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org