You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Affan Osman <af...@gmail.com> on 2019/04/02 02:43:19 UTC

Re: getText with multiple parameters not populating correctly

I am using version 2.5.17. I am not using any custom text provider.

I tried the same example as in the unit test but still only first parameter gets populated. The second and third show as [1] and [2].

Thanks.
On Mar 31, 2019, 5:21 AM -0400, Lukasz Lenart <lu...@apache.org>, wrote:
> sob., 30 mar 2019 o 20:03 Affan Osman <af...@gmail.com> napisał(a):
> >
> > I am passing in three parameters to getText but only the first one gets
> > populated.
> >
> > getText("error.invalidcode", new String[] {"name", "num", "1az"});
> >
> > And in my ApplicationResources.properties
> >
> > error.invalidcode={0} and {1} property has error with code {2}.
> >
> > I am getting the following result: name and {1} property has error with
> > code {2}.
> >
> > Where I was expecting:
> >
> > name and num property has error with code 1az.
> >
> > What am I missing?
>
> Struts version? Can you post your struts.xml? Maybe you are using a
> custom TextProvider.
>
> As you see there is a unit test that covers such functionality [1]
> [1] https://github.com/apache/struts/blob/master/core/src/test/java/com/opensymphony/xwork2/DefaultTextProviderTest.java#L89
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

Re: getText with multiple parameters not populating correctly

Posted by Affan Osman <af...@gmail.com>.
Double single quotes did the trick. Thanks!
On Apr 2, 2019, 10:59 AM -0400, Lukasz Lenart <lu...@apache.org>, wrote:
> wt., 2 kwi 2019 o 16:54 Dave Newton <da...@gmail.com> napisał(a):
> >
> > Single-quotes must be escaped using double single-quotes; single quotes are
> > used to allow non-resource strings. IIRC this is just how `MessageFormat`
> > works.
>
> Yeah... getText() is using MessageFormat so you must properly escape
> your messages
>
> https://docs.oracle.com/javase/7/docs/api/java/text/MessageFormat.html
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

Re: getText with multiple parameters not populating correctly

Posted by Lukasz Lenart <lu...@apache.org>.
wt., 2 kwi 2019 o 16:54 Dave Newton <da...@gmail.com> napisał(a):
>
> Single-quotes must be escaped using double single-quotes; single quotes are
> used to allow non-resource strings. IIRC this is just how `MessageFormat`
> works.

Yeah... getText() is using MessageFormat so you must properly escape
your messages

https://docs.oracle.com/javase/7/docs/api/java/text/MessageFormat.html


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

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


Re: getText with multiple parameters not populating correctly

Posted by Dave Newton <da...@gmail.com>.
Single-quotes must be escaped using double single-quotes; single quotes are
used to allow non-resource strings. IIRC this is just how `MessageFormat`
works.

On Tue, Apr 2, 2019 at 10:40 AM Affan Osman <af...@gmail.com> wrote:

> I think found the issue. It fails because of '.
>
> test.key={0}is{1}and{2}.
> test.key2={0}'sis{1}and{2}.
>
> String key1= getText("test.key", newString[] {"aa11", "bb22", "cc33"});
> String key2= getText("test.key2", newString[] {"aa11", "bb22", "cc33"});
>
> Key 1: aa11 is bb22 and cc33.
> Key 2: aa11s is {1} and {2}.
>
> Is there anyway I can escape the character ' ?
>
> I don't think there is an issue with struts.xml, but here it is.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE struts PUBLIC
>     "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
>     "struts.apache.org/dtds/struts-2.5.dtd">
>
> <struts>
>                 <constant name="struts.custom.i18n.resources"
> value="ApplicationResources" />
>                 <constant name="struts.devMode" value="true" />
>                 <constant name="struts.enable.DynamicMethodInvocation"
> value="true" />
>                 <constant name="struts.action.extension" value="do"/>
>                 <package name="default" namespace="/"
> extends="struts-default">
>                                 <default-action-ref name="foldersearch" />
>
>                                 <global-results>
>                                                 <result
> name="sessiontimeout">/sessiontimeout.jsp</result>
>                                                 <result
> name="error">/error.jsp</result>
>                                 </global-results>
>
>                                 <action name="searchresults"
> class="com.test.SearchAction" method="execute">
>                                                 <result
> name="success">/searchresults.jsp</result>
>                                 </action>
>
>                 </package>
>
> </struts>
>
>
> Thanks!
> On Apr 2, 2019, 5:11 AM -0400, Lukasz Lenart , wrote:
> > wt., 2 kwi 2019 o 04:46 Affan Osman <af...@gmail.com> napisał(a):
> > >
> > > I am using version 2.5.17. I am not using any custom text provider.
> > >
> > > I tried the same example as in the unit test but still only first
> parameter gets populated. The second and third show as [1] and [2].
> >
> > Could you share your struts.xml? This is rather something with your
> > config, I have tested the same in my app and everything looks good:
> >
> > System.out.println(getText("test.key", new String[] { "A", "B", "C" }));
> >
> > test.key={0} is {1} and {2}
> >
> > "A is B and C"
> >
> >
> > Regards
> > --
> > Łukasz
> > + 48 606 323 122 http://www.lenart.org.pl/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
>


-- 
em: davelnewton@gmail.com
mo: 908-380-8699
tw: @dave_newton <https://twitter.com/dave_newton>
li: dave-newton <https://www.linkedin.com/in/dave-newton/>
gh: davelnewton <https://github.com/davelnewton>
so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
bl[0]: Bucky Bits <http://buckybits.blogspot.com/>
bl[1]: Maker's End Blog <https://blog.makersend.com>
sk: davelnewton_skype

Re: getText with multiple parameters not populating correctly

Posted by Affan Osman <af...@gmail.com>.
I think found the issue. It fails because of '.

test.key={0}is{1}and{2}.
test.key2={0}'sis{1}and{2}.

String key1= getText("test.key", newString[] {"aa11", "bb22", "cc33"});
String key2= getText("test.key2", newString[] {"aa11", "bb22", "cc33"});

Key 1: aa11 is bb22 and cc33.
Key 2: aa11s is {1} and {2}.

Is there anyway I can escape the character ' ?

I don't think there is an issue with struts.xml, but here it is.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
    "struts.apache.org/dtds/struts-2.5.dtd">

<struts>
                <constant name="struts.custom.i18n.resources" value="ApplicationResources" />
                <constant name="struts.devMode" value="true" />
                <constant name="struts.enable.DynamicMethodInvocation" value="true" />
                <constant name="struts.action.extension" value="do"/>
                <package name="default" namespace="/" extends="struts-default">
                                <default-action-ref name="foldersearch" />

                                <global-results>
                                                <result name="sessiontimeout">/sessiontimeout.jsp</result>
                                                <result name="error">/error.jsp</result>
                                </global-results>

                                <action name="searchresults" class="com.test.SearchAction" method="execute">
                                                <result name="success">/searchresults.jsp</result>
                                </action>

                </package>

</struts>


Thanks!
On Apr 2, 2019, 5:11 AM -0400, Lukasz Lenart , wrote:
> wt., 2 kwi 2019 o 04:46 Affan Osman <af...@gmail.com> napisał(a):
> >
> > I am using version 2.5.17. I am not using any custom text provider.
> >
> > I tried the same example as in the unit test but still only first parameter gets populated. The second and third show as [1] and [2].
>
> Could you share your struts.xml? This is rather something with your
> config, I have tested the same in my app and everything looks good:
>
> System.out.println(getText("test.key", new String[] { "A", "B", "C" }));
>
> test.key={0} is {1} and {2}
>
> "A is B and C"
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

Re: getText with multiple parameters not populating correctly

Posted by Lukasz Lenart <lu...@apache.org>.
wt., 2 kwi 2019 o 04:46 Affan Osman <af...@gmail.com> napisał(a):
>
> I am using version 2.5.17. I am not using any custom text provider.
>
> I tried the same example as in the unit test but still only first parameter gets populated. The second and third show as [1] and [2].

Could you share your struts.xml? This is rather something with your
config, I have tested the same in my app and everything looks good:

System.out.println(getText("test.key", new String[] { "A", "B", "C" }));

test.key={0} is {1} and {2}

"A is B and C"


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

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