aspose file tools*
The moose likes Struts and the fly likes Question with FormBean and action class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Question with FormBean and action class" Watch "Question with FormBean and action class" New topic
Author

Question with FormBean and action class

san geetha
Ranch Hand

Joined: Sep 07, 2004
Posts: 44
In the jsp, have a hidden tag as strOperation...i set the value "Search" for this.
In the formbean, have appropriate get/set methods.
There are 2 action classes.
In the 1st action, i use the getStrOperation method to read the value... then i again set a new value for this variable to "List".
Then pass call the 2nd action class. Itz working fine, but in the 2nd action class if i do a getStrOperation(), the value that was set in the JSP (Search)is only read rather than reading the value that was set in 1st action class(List)
I dont have a clue as to why itz happening, can anyone throw light on this...Itz slightly urgent, depending upon this i need to alter my code.

Thanks,
Sangeeta
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
Check the bean context: is it set for page, session or application. In case it is for page you're not gonna see the changes.

./pope


blog - InfoQ.com
san geetha
Ranch Hand

Joined: Sep 07, 2004
Posts: 44
I havent specified any context for the form bean. what do i do?
Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
i guess you are using struts. All you have to do is set the scope to be session. If you dont provide any value for this attribute, still it defaults to session. I am guessing you might be having the attribute set to request in your configuration file.

<action path="/********"
name= "*******Form"
type="****************"
scope = "request">

change the scope to session OR just get rid of this attribute, that should default to session.

But, its not advisable to have the scope as session , unless its required
[ October 28, 2004: Message edited by: mvk ]
san geetha
Ranch Hand

Joined: Sep 07, 2004
Posts: 44
Scope is already set to session and not to request...
someone solve this
tukai chakraborty
Greenhorn

Joined: Feb 02, 2004
Posts: 11
dont set the scope to session unless needed,keep it to request.

This is what you need to do.

Say you 1 jsp,a form and 2 actions

In the struts-config.xml this is the mapping you need to do.

<action name="FormName" type="Action 1" input="/jsp1.jsp" scope="request" path="/Action 1"> <forward name="another" path="/another.do" /> </action>

<action path="/another" type="AnotherAction" scope="request" input="/jsp1.jsp"> <forward name="success" path="/Success.jsp" /> </action>

Note that from Action 1 you would forward to Action 2 and also note that there should not be any form bean mapping with the Action 2.

Now in Action 1,after re-setting the form bean values you need to set the form bean object in the request scope before forwarding it to the Action 2.

i.e.in Action 1

Say you had already done

YourForm yourForm = (YourForm )form;

So before forwarding it to Action 2 you need to do

request.setAttribute("updatedform",yourForm);

return(mapping.findForward("another"));(from struts-config)

Now in Action 2,you have to do

YourForm yourForm = (YourForm)request.getAttribute("updatedform");

If you now want to read the form values ,you would get the updated ones which you had re-setted in Action 1.

This would solve your problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question with FormBean and action class