?
Solved

How to generate a jsp page with form in struts where the values of the input fields are pre-generated?

Posted on 2006-04-12
8
Medium Priority
?
319 Views
Last Modified: 2010-04-01
Hi all,

In our web application (struts), we have an action that executes a query in the database. The results of this query are the values of the fields on the next page (the page that is being forwarded to).
So we want this jsp page to be generated with the values allready filled in.

What is the best way of accomplishing this?
0
Comment
Question by:tcollogne
  • 4
  • 2
  • 2
8 Comments
 
LVL 3

Expert Comment

by:el_dios
ID: 16443143
Hi tcollogne,
> So we want this jsp page to be generated with the values allready filled in.

> What is the best way of accomplishing this?
I dont think there is any Struts support for this. I think you could use a 2D array and iterate through it.

Cheers!
0
 

Author Comment

by:tcollogne
ID: 16443281
Is it not possible to create an instance of the form bean in the "goto" action. Which would then be automatically used for filling in the fields?
Or something like that?
0
 
LVL 5

Accepted Solution

by:
gksinghiet earned 500 total points
ID: 16443364
>>Is it not possible to create an instance of the form bean in the "goto" action...
Yes it is possible. You need to create the goto action mapping to use the newly created form and populate that form with the queried values. Now in your JSP page use that form using <html:form> tag. You get the queried values there.
Let me know if you want more explanation.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:tcollogne
ID: 16443401
This is the strutcure of my app. Between brackets is the name of the Form bean

GoToMakeReservationAction( GoToMakeReservationForm)   --> makeReservation.jsp   --> MakeReservationAction (MakeReservationForm)   --> result.jsp

If I understand it correctly I should put this code in the GoToMakeReservationAction

MakeReservationForm f = new MakeReservationForm();
f.setName("me");
request.setAttribute("makeReservationForm",f);

So I create an instance of the MakeReservationForm (not GoToMakeReservationForm) in the GoToMakeReservationAction and put the values.

Then on my makeReservation.jsp page I have the code

               <html:form action="/makeReservation">
                  <html:text property="name"/>
                  <html:submit/><html:cancel/>
            </html:form>


Is this correct?
0
 
LVL 5

Expert Comment

by:gksinghiet
ID: 16443527
This is one way of doing the same but the ideal way for a struts application is:
In GoToMakeReservationAction::

MakeReservationForm f = (MakeReservationForm) form;
f.setName(<Your queried value>);
....
return (mapping.findForward("success"));

In struts-config.xml::
 
   <!--Your form bean-->
  <form-beans>
    <!-- name form bean -->
    <form-bean name="reservationForm" type="<MakeReservationForm>"/>
  </form-beans>

   <!--Your action mapping-->
    <action path="/setName"
            type="<GoToMakeReservationAction>"
            name="reservationForm"
            scope="request"
            input="/index.jsp">
      <forward name="success" path="/makeReservation.jsp "/>
    </action>
0
 

Author Comment

by:tcollogne
ID: 16443548
So what you say is using the same form bean for both actions?

0
 
LVL 3

Expert Comment

by:el_dios
ID: 16443550
Do you have only one such query or many such situations, then it would be better for a generic solution.
In the form have the names which you want to display as the headings in an array or arraylist.
Have the values to be displayed in a 2D array. Forrow the steps gksinghiet has provided. I think that would be enough.
0
 

Author Comment

by:tcollogne
ID: 16443591
No only one situation.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am posting this in case anyone runs into similar issues that I did, this may save you a lot of grief: Condition: 1. Your NetBIOS domain name contains an ampersand " & " character.  (e.g. AT&T) 2. You've tried to run any Microsoft installation…
If you need to complete a Physical to Virtual (P2V), Virtual to Virtual (V2V) conversion to a VMware product (VMware Workstation, Player or VMware vSphere (ESXi) ) for FREE, then there is some good news...
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month9 days, 8 hours left to enroll

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question