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?
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.

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.

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?
>>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.

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();

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"/>

Is this correct?
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-->
    <!-- name form bean -->
    <form-bean name="reservationForm" type="<MakeReservationForm>"/>

   <!--Your action mapping-->
    <action path="/setName"
      <forward name="success" path="/makeReservation.jsp "/>
tcollogneAuthor Commented:
So what you say is using the same form bean for both actions?

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.
tcollogneAuthor Commented:
No only one situation.
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

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.