This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Struts and the fly likes How to Reverse Lookup resource key from resource Message in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to Reverse Lookup resource key from resource Message in Struts" Watch "How to Reverse Lookup resource key from resource Message in Struts" New topic
Author

How to Reverse Lookup resource key from resource Message in Struts

Khurram Butt
Greenhorn

Joined: Jun 19, 2010
Posts: 2

Hi Guyz

i need a way to find the key from the message passed .........
why i need it
i have a application that uses LookupDispatchAction and have corresponding ActionForm classes that validates
the bean properties ..... it actually do conditional validation based on which button pressed on the page by using mapping.getParameter()

and then extracting its value from request to decide which button is pressed like

if(request.getParameter(mapping.getParameter()).equals("SAVE")) // then do validation associated with save operation

if(request.getParameter(mapping.getParameter()).equals("DEL")) // then do validation associated with del operation

now my application is going to support multi languages here the problem arise the message that will come from button will come in different languages and it will cause to stop the validation
i have considerable amount of ActionForms and i dont want to edit every form

so i was looking to do any reverse lookup of keys from messages so that i can extract english messages and update accordingly

any new ideas to this problem are also welcome

thanks
Richard Golebiowski
Ranch Hand

Joined: May 05, 2010
Posts: 213

I always check for the button pressed like this:



This uses the id of the button, not the value. I think this is what you want.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61449
    
  67

Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Khurram Butt
Greenhorn

Joined: Jun 19, 2010
Posts: 2
Hi
thanks Richard for replying
yes good technique but this way will require me to change code at both ends jsps and ActionForms because in jsps i can't see any property/attribute of id .

thanks
Richard Golebiowski
Ranch Hand

Joined: May 05, 2010
Posts: 213

All tags have an id attribute. In Struts 1 it is styleId. In Struts 2 it is id.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Reverse Lookup resource key from resource Message in Struts