my dog learned polymorphism*
The moose likes Struts and the fly likes Passing a bean:message as string to a custom tag?(Struts2) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Passing a bean:message as string to a custom tag?(Struts2)" Watch "Passing a bean:message as string to a custom tag?(Struts2)" New topic
Author

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

David Glossop
Greenhorn

Joined: Sep 10, 2009
Posts: 6
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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.

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
David Glossop
Greenhorn

Joined: Sep 10, 2009
Posts: 6
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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

Joined: Sep 10, 2009
Posts: 6
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

Joined: Sep 10, 2009
Posts: 6
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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
 
wood burning stoves
 
subject: Passing a bean:message as string to a custom tag?(Struts2)
 
Similar Threads
Bean:Message - Advantages ?
Using struts tag library inside one I am developing
tld question
nesting tags and evaluate expressions in Struts2.0 ,alternative to bean:define ?
bean:message tag inside logic:equal