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

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?
tcollogneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

el_diosCommented:
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
tcollogneAuthor Commented:
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
gksinghietCommented:
>>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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

tcollogneAuthor Commented:
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
gksinghietCommented:
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
tcollogneAuthor Commented:
So what you say is using the same form bean for both actions?

0
el_diosCommented:
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
tcollogneAuthor Commented:
No only one situation.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.