• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Question with FormBean and action class

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
san geetha
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I havent specified any context for the form bean. what do i do?
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Scope is already set to session and not to request...
someone solve this
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't listen to Steve. Just read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic