You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by wkbutler <ke...@gmail.com> on 2009/07/10 19:59:27 UTC

RE: For s:textfield tag how to get value for title attribute from resource bundle.

Is this still the only way to get i18n translatations into a struts tag from
the resource bundle?

I'm trying to get a label on some struts fields, i.e.

                <s:textfield 
                   
name="userResponses[%{#loop.index}].userResponseValues[0].value" 
                    label="%{getText('q.client.name.first')}" 
                    value="%{userResponseValues[0].value}" 
                    required="%{formQuestion.required}" 
                    maxlength="%{formQuestion.maxLength}" 
                    cssStyle="width:%{fieldSize}px" 
                    cssClass="text medium"/>

with a messageSource defined as

	<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
	    <property name="basenames"> 
	       <list>
	           <value>classpath:/form</value>
           </list>
        </property>
	    <property name="cacheSeconds" value="7200"/>
	</bean>

I've never seen the getText() work successfully, but the following do work:

<fmt:setBundle basename="form"/>
<fmt:message key="q.client.name.first" />

<i18n:bundle baseName="form" id="b1">
    <i18n:message key="q.client.name.first" bundle="${b1}" />
</i18n:bundle>

I also have the JSTL message source defined in web.xml still, but removing
that doesn't help the getText succeed.

Any ideas on getting getText() to work?  Or alternatives ways of getting an
i18n label on the s:textfield?  Thanks for any ideas -




LEONARD Julien (Consulting for ACCOR Hotels) wrote:
> 
> Try this :
> 
> <s:textfield theme="xhtml" label="" key="categoryName"
> cssClass="fieldGreen validate-alpha " value=""
> title="%{getText('category.categoryName')}" id="categoryName"/> 
> 
> http://struts.apache.org/2.0.11/docs/localization.html
> 
> Julien
> 
> -----Message d'origine-----
> De : VJ22 [mailto:Vijay.Nair@iflexsolutions.com] 
> Envoyé : vendredi 22 février 2008 16:26
> À : user@struts.apache.org
> Objet : For s:textfield tag how to get value for title attribute from
> resource bundle.
> 
> 
> For s:textfield tag how to get value for title attribute from resource
> bundle. 
> I tried using <fmt:message> but seems the struts2 is  not recognising this
> inside the title tag and considering it as plain text.
> Please let me know if there exists a way to do the same For eg i tried 
> <td width="80%"<s:textfield theme="xhtml" label="" key="categoryName"
> cssClass="fieldGreen validate-alpha " value="" title="<fmt:message
> key='category.categoryName'/>" id="categoryName"/>
> 
> Here category.categoryName is refering to resouce bundle property.
> 
> --
> View this message in context:
> http://www.nabble.com/For-s%3Atextfield-tag-how-to-get-value-for-title-attribute-from-resource-bundle.-tp15634305p15634305.html
> Sent from the Struts - User mailing list archive at Nabble.com.
> 
> ----------------------------------------------------------------------------------------
> 
> 

-- 
View this message in context: http://www.nabble.com/For-s%3Atextfield-tag-how-to-get-value-for-title-attribute-from-resource-bundle.-tp15634305p24432096.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: For s:textfield tag how to get value for title attribute from resource bundle.

Posted by wkbutler <ke...@gmail.com>.
Well I took Dave's advice from another thread
(http://www.nabble.com/-S2--Dynamic-Text-Tag-Attributes-td19436146.html#a19436146) 
and just implemented this in my action.  Oh well.  Thanks guys -
-- 
View this message in context: http://www.nabble.com/For-s%3Atextfield-tag-how-to-get-value-for-title-attribute-from-resource-bundle.-tp15634305p24484318.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: For s:textfield tag how to get value for title attribute from resource bundle.

Posted by wkbutler <ke...@gmail.com>.
Yep I did find that, thanks.  What I've realized is that I have the OGNL
double-evaluation problem.  I'm really trying to get this result for the
s:textfield label:

              label="%{getText('%{formQuestion.question.questionKey}')}" 

which of course is not legal, but I guess I'm somewhat surprised that 

              label="getText('%{formQuestion.question.questionKey}')" 

doesn't get what I need, even though I guess it's technically identical to
the previous AFAIK.  The struts docs here
(http://struts.apache.org/2.1.6/docs/tag-syntax.html)  are a little vague on
this layered use, but I am seeing if I can get some insight from the OGNL
docs (http://www.opensymphony.com/ognl/html/LanguageGuide/paren.html).  

I did try a helper tag like

   <s:set name="labelVal" 
value="getText('%{formQuestion.question.questionKey}')"/>

but no luck.

Thanks for wading through my babble. I had my kids in the office today.  lol

-- 
View this message in context: http://www.nabble.com/For-s%3Atextfield-tag-how-to-get-value-for-title-attribute-from-resource-bundle.-tp15634305p24473204.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: For s:textfield tag how to get value for title attribute from resource bundle.

Posted by Dave Newton <ne...@yahoo.com>.
wkbutler wrote:
> Bottom line was that the resource props need to be packaged in the
> same package as the action class, with the same name.

getText calls will follow the hierarchy noted in the docs:

http://struts.apache.org/2.1.6/docs/localization.html

Dave

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


RE: For s:textfield tag how to get value for title attribute from resource bundle.

Posted by wkbutler <ke...@gmail.com>.
OK - I got getText() working via checking out the code in
com.opensymphony.xwork.util.LocalizedTextUtil , and the StrutsInAction book
has a pretty good section this.  Bottom line was that the resource props
need to be packaged in the same package as the action class, with the same
name.  I preferred another solution however, which was to declare a marker
interface and use the same trick on that (declare props file with same name,
same packaging), and any class implementing that inherits access to that
bundle.

Anyway, my followup question -  I can't use the 'key' attribute on this tag:

                <s:textfield 
                   
name="userResponses[%{#loop.index}].userResponseValues[0].value" 
                    label="%{getText('formQuestion.question.questionKey')}" 
                    value="%{userResponseValues[0].value}" 
                    required="%{formQuestion.required}" 
                    maxlength="%{formQuestion.maxLength}" 
                    cssStyle="width:%{fieldSize}px" 
                    cssClass="text medium"/>


How would you submit a variable as the identifier for the i18n key in the
above?  This syntax produces the result for the key  "question.questionKey".  
It is supposed to be evaluating the value of variable 
      formQuestion.question.questionKey

via OGNL object access as finding the value  "q.client.firstName"  etc.

Any idea how to specify that the inner OGNL translation should happen first?  
I have tried 
    label="getText('%{formQuestion.question.questionKey}')" 

among many others.  Haven't found this on the forums, probably missed it
though.  Thanks -






wkbutler wrote:
> 
> Is this still the only way to get i18n translatations into a struts tag
> from the resource bundle?
> 
> I'm trying to get a label on some struts fields, i.e.
> 
>                 <s:textfield 
>                    
> name="userResponses[%{#loop.index}].userResponseValues[0].value" 
>                     label="%{getText('q.client.name.first')}" 
>                     value="%{userResponseValues[0].value}" 
>                     required="%{formQuestion.required}" 
>                     maxlength="%{formQuestion.maxLength}" 
>                     cssStyle="width:%{fieldSize}px" 
>                     cssClass="text medium"/>
> 
> with a messageSource defined as
> 
> 	<bean id="messageSource"
> class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
> 	    <property name="basenames"> 
> 	       <list>
> 	           <value>classpath:/form</value>
>            </list>
>         </property>
> 	    <property name="cacheSeconds" value="7200"/>
> 	</bean>
> 
> I've never seen the getText() work successfully, but the following do
> work:
> 
> <fmt:setBundle basename="form"/>
> <fmt:message key="q.client.name.first" />
> 
> <i18n:bundle baseName="form" id="b1">
>     <i18n:message key="q.client.name.first" bundle="${b1}" />
> </i18n:bundle>
> 
> I also have the JSTL message source defined in web.xml still, but removing
> that doesn't help the getText succeed.
> 
> Any ideas on getting getText() to work?  Or alternatives ways of getting
> an i18n label on the s:textfield?  Thanks for any ideas -
> 
> 
> 
> 
> LEONARD Julien (Consulting for ACCOR Hotels) wrote:
>> 
>> Try this :
>> 
>> <s:textfield theme="xhtml" label="" key="categoryName"
>> cssClass="fieldGreen validate-alpha " value=""
>> title="%{getText('category.categoryName')}" id="categoryName"/> 
>> 
>> http://struts.apache.org/2.0.11/docs/localization.html
>> 
>> Julien
>> 
>> -----Message d'origine-----
>> De : VJ22 [mailto:Vijay.Nair@iflexsolutions.com] 
>> Envoyé : vendredi 22 février 2008 16:26
>> À : user@struts.apache.org
>> Objet : For s:textfield tag how to get value for title attribute from
>> resource bundle.
>> 
>> 
>> For s:textfield tag how to get value for title attribute from resource
>> bundle. 
>> I tried using <fmt:message> but seems the struts2 is  not recognising
>> this inside the title tag and considering it as plain text.
>> Please let me know if there exists a way to do the same For eg i tried 
>> <td width="80%"<s:textfield theme="xhtml" label="" key="categoryName"
>> cssClass="fieldGreen validate-alpha " value="" title="<fmt:message
>> key='category.categoryName'/>" id="categoryName"/>
>> 
>> Here category.categoryName is refering to resouce bundle property.
>> 
>> --
>> View this message in context:
>> http://www.nabble.com/For-s%3Atextfield-tag-how-to-get-value-for-title-attribute-from-resource-bundle.-tp15634305p15634305.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>> 
>> ----------------------------------------------------------------------------------------
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/For-s%3Atextfield-tag-how-to-get-value-for-title-attribute-from-resource-bundle.-tp15634305p24466512.html
Sent from the Struts - User mailing list archive at Nabble.com.


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