File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing a bean:message as string to a custom tag?(Struts2)

 
David Glossop
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am pretty new to struts, so this may sound like a silly question, however in the app i am starting to write I have want to use struts and an ApplicationResource file for internationalisation. The problem I have is with passing a string parameter to a custom tag as s string. Although syntax is wrong (very) the below example should exemplify what I want to achieve.

<menu:menuItem label=" <bean:message key="labels.pfm.menus.admin.ManageVendors"/> " forward="manageVendors.do" />

Question: How do I pass in the string represented by 'labels.pfm.menus.admin.ManageVendors' in the ApplicationResource.properties as a string to the tag?




 
Sagar Rohankar
Ranch Hand
Posts: 2904
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think, you're not allowed to cascade(hope I use correct word) the struts tag into another tag.
Still 2 solutions:
Use single ''' quote instead of double
OR
use(try) EL:


Welcome to JR and please use Code Tags to quote your code.
 
David Glossop
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar, thanks for the quick reply, however I think I am missing something as I can't get either solution to work?

The first results in a blank string ("") being passed and the second passes the string '<bean:message key="labels.pfm.menus.admin.ManageVendors"/>' ?


 
Sagar Rohankar
Ranch Hand
Posts: 2904
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, you're saying its Struts 2, so have you checked the S2 docs for the tag similar for <bean:message key=""../>.
I think you can't pass the bean:message output to any tag "value", its associated with the out.print() and thus directed its out put o the HTML text content. So the only suggestion I advise is, modify your custom tag, like

Your label comes between the tag.

If you cant modify the custom tag code, then Use the JavaScript to assign value to the "label" ;)
 
David Glossop
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar, thanks again for the advice. i have resolved the problem by taking a moving the problem domain from the jsp to the tag.

In the tag I now use MessageResources to retrieve the key from the ApplicationResource.properties file.





 
David Glossop
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Glossop wrote:Sagar, thanks again for the advice. I have resolved the problem by taking a moving the problem domain from the jsp to the tag.

In the tag I now use MessageResources to retrieve the key from the ApplicationResource.properties file.





 
Sagar Rohankar
Ranch Hand
Posts: 2904
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Glossop wrote:Sagar, thanks again for the advice. i have resolved the problem by taking a moving the problem domain from the jsp to the tag.

Brilliant, it couldn't get any better
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic