Rajaneesh
Rajaneesh

Reputation: 71

liferay jsp rendering to other jsp

I have a form which is in two jsps when the details in first jsp is filled after clicking next the form in next jsp must appear please suggest me how to solve this it must render using javascript

Upvotes: 2

Views: 864

Answers (1)

Prakash K
Prakash K

Reputation: 11698

I assume you need some information from the first form in first.jsp to render the second form in second.jsp

You can go with following approaches to have step-by-step forms:

I. Using two JSPs (page refresh):

  1. Create two JSPs (ofcourse!)
  2. Have a normal action-URL defined for the first.jsp. (check this out to see how its done)
  3. In the processAction method check all the validations and everything and set the render-parameter for showing the second.jsp
  4. Either store the first form result in database or in portlet-session or pass as request attributes to the second.jsp to be submitted as hidden params (your choice!)
  5. Now do you usual stuff in second.jsp

II. Using two JSPs (ajax)

  1. Again create two JSPs
  2. Define a resource-URL when the first form is submitted in first.jsp. (you can learn how to submit - here)
  3. Once the form is submitted in your serveResource method in your portlet do whatever logic you want to do and when you want to serve the content using ResourceResponse - serve the second.jsp
  4. Again you can use whatever method you want to use for storing or validating the first form's data. (some are suggested in Approach-I above)

III. Using one JSP (ajax)

  1. Separate the two forms in a single JSP through a <div> tag.
  2. Hide the second form through CSS or inline styles like style=display:none;
  3. Submit the first form using ajax as mentioned in the above approach.
  4. And if all the validations are proper and data from first form is stored, do
  5. Instead of returning the second.jsp return a JSON (if required to fill some values of second form)
  6. Through javascript unhide the second <div> and fill in the details.
  7. Submit this form using actionURL or resourceURL as per your choice if you want to refresh the page or not respectively.

Just in case your second form does not depend on first form:

  1. Create the one single form but separate the fields you want in first part and second part in two <div> and hide the second part <div> as mentioned above.
  2. Just fill in first form and onclick of the next button show the second form
  3. Fill the form and submit as usual.

Hope this helps.

Upvotes: 2

Related Questions