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.n...@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-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org