• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

querystring subtitution in struts

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

My problem is ...there are two jsp main.jsp and detail..jsp. In main.jsp i enter the only project desc and submit to database and map the struts to call the detail.jsp which has to pick the project id( which is sequence generator) and display its description so i can add the other details o project.

Now the problem is as i submit the action the request goes out of scope and i am unable to get the project Id so i cant find the project desc to display in my detail page.

one way is querystring, which is not preferred in our proj. Is there any substituion for querystring in struts.

Its kind of urgernt

Thanks
Infyniti.
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
before forwarding to the details page, inside your main.jsp processing action, set the form property 'projectId' of the details.jsp form (which should be the same form-bean as the main.jsp) to the generated id. use html:hidden to hold on to that value. i am hoping that you understand the basic of passing parameters via struts form.
 
Anant Rao
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in Main.jsp addaction class i am setting the form parameters

projectDetailForm.setProjectId(projectNumber);

ProjectNumber is the number i want assing to the project Id.

in display of detail action class i am getting the value

ProjectDetailActionForm form = (ProjectDetailActionForm ) aForm;
int projectNumber= form.getProjectId();


But still not giving me the value..when I debug its setting the value but while getting its showing 0.

Can u please let me know where i am doing it wrong.

thanks in advance
infyniti.
 
Anant Rao
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If anybody have idea where I am going wrong pleae let me know.

Its kind of urgernt.

Thanks in advance
infyniti
[ October 16, 2005: Message edited by: infyniti molugu ]
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In the Main Action Class, after inserting the description into the database, set the Project ID in the Request. And In the Other Action Class, the forwarded action class, take the ID from the request and get the details and show them.

Thanks & Regards
Hema
 
Anant Rao
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply,

But how do u set in a request and get in another class. can u please paste me those lines of code

thanks
Infyniti
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first of all, both of your actions should be mapped to the same form bean for this approach to work.

in the main Action class, prior to forwarding, you need to do:

ActionForm form = (ActionForm) aForm;
form.set("projectId",projectNumber);

//do forward to details.jsp forward mapping

your form bean must have a 'projectId' field and in your details.jsp, your form must have an html:hidden property="projectId".
 
Anant Rao
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes both my action beans are mapped to same form bean. My form bean projectId and detai.jsp has a hiddenfile projectId.


In my main action class i wrote

form.setProjectId("projectId",projectNumber);

now i waat this value in my display action of detail page so that passing the projectId i will fetch the project description.
But in my display detail action I am not getting that projectId.

How should i get that value that is set in form.

thanks for ur patience
Infyniti




your form bean must have a 'projectId' field and in your details.jsp, your form must have an html:hidden property="projectId
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the line form.set("projectId",projectNumber); (note that is just a simple 'get' method of the ActionForm class, NOT the getter of the projectId) sets the project id value. using the struts html:hidden tag in the details page should automatically puts the value into an <input type="hidden" name="projectId" value="1"> where '1' is the ID of the project. if you view source of the main.jsp generated HTML codes, can you see the project ID being passed in as a hidden field?

if you CAN see the value in the source (which means you've done everything correctly up until this point), then in the display action, simply do the same to get the form out and call
form.get("projectId"); to retrieve the project.

if you CANNOT...make sure the value is being generated. do a System.out of that value just before you call the form.set(). passing a non-calculatable ID as a double or int may be problematic. i suggest you convert it to a String before setting it into the form (in the main action). when you pass it back, simply convert that back to whatever the DB needs.
 
reply
    Bookmark Topic Watch Topic
  • New Topic