wood burning stoves 2.0*
The moose likes Struts and the fly likes How to fetch value from ActionForm given a parameter... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to fetch value from ActionForm given a parameter..." Watch "How to fetch value from ActionForm given a parameter..." New topic
Author

How to fetch value from ActionForm given a parameter...

frank wa
Greenhorn

Joined: May 21, 2008
Posts: 2
Hey All,

I looked through the faqs but i'm not sure if my question is answered in the faqs. I don't believe it is.

Basically... I have a form extending ActionForm and sent back to a jsp page. seems simple already ;-P

in my controller i do a (for example) form.setDetails( object1 );
object1 is a Map<String, String>

in the action form i also have a

getDetail( String key ) {
return thisDetailMap.get(key);
}

I would like to know how i can pass the parameter in and get the value back... all in the jsp page....

So in the page i'd have something like: {$form.detail('HELLO')} and it would return the value for the key "HELLO"

In my page i'm displaying keys using a forEach loop... but for each key i find, i want to fetch speific details for it... ie: title information or whatnot...

I know i'm close, i just can't seem to get it...

Thanks guys!
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
See the Heading "Mapped Properties" in this link.


Merrill
Consultant, Sima Solutions
frank wa
Greenhorn

Joined: May 21, 2008
Posts: 2
Hello :-)

Thanks for the quick reply.

I had tried this and it doesn't seem to work. This is what my code looks like:

ApplicationForm extends ActionForm
private Map<String, String> appDetailedInfo;
public Object getDetails( String key ) {
return appDetailedInfo.get(key);
}

JSP:
<bean:write name="ApplicationForm" scope="request" property="details(1024_REGION)"/>

I even tried:

<jsp:useBean id="bean" scope="request" class="com.app.ApplicationForm">
<bean:write name="bean" property="details(1024_REGION)"/>
</jsp:useBean>

I keep getting this error:

javax.servlet.jsp.JspException: No getter method for property: "details(1024_REGION)" of bean: "bean"
at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:915)
at org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:234)

Any idea why? :-/
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Your code looks OK. I don't know what to tell you but that I know this works. I even wrote a small application to test it, and got the results I expected. I'll post my code, and maybe you can figure out what you're doing differently.

Action Form:


struts-config.xml:



jsp:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to fetch value from ActionForm given a parameter...