• 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

How to persist form data across different pages

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have a registration form (register.jsp) when submitted goes to
RegisterPersonController(extends SimpleFormController) --> RegisterPersonService --> RegisterPersonDAO
and saves the details to DB.

The successView is defined as registered.jsp

In registered.jsp I am displaying the congratulations message plus two links

1) View details in PDF
2) View details in Excel

I am capturing the form details from register.jsp into RegisterPersonController in the command object (person) and passing it to registered.jsp through modelAndView object, where i am able to display the details directly on the page .

But how do I pass this model or (command object) from registered.jsp to AbstractPdfView

For your ready reference I am pasting my code here and not attaching ( sorry for long post)

------------------------------------------------------------------------------------------------------------------------------------------------
register.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri = "http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="/spring" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method="post" action="./registerPerson.htm">
<spring:bind path="person">
<c:forEach items="${status.errorMessages}" var = "errorMessage">
<c:out value="${errorMessage}" /> <br/>
</c:forEach>
</spring:bind>

<br/>

<spring:bind path="person.firstName">
FirstName : <input type="text" name = "<c:out value="${status.expression}" />"
value = "<c:out value = "${status.value}" />" />
<c:out value="${status.errorMessage}"></c:out>
</spring:bind>

<br/>

<spring:bind path="person.lastName">
LastName : <input type="text" name = "<c:out value="${status.expression}" />"
value = "<c:out value = "${status.value}" />" />
<c:out value="${status.errorMessage}"></c:out>
</spring:bind>

<br/>

<spring:bind path="person.password">
Password : <input type="password" name = "<c:out value="${status.expression}" />"
value = "<c:out value = "${status.value}" />" />
</spring:bind>

<br/>

<spring:bind path="person.email">
Email : <input type="text" name = "<c:out value="${status.expression}" />"
value = "<c:out value = "${status.value}" />" />
</spring:bind>

<br/>

<input type="submit" value="Register" />

</form>
</body>
</html>
------------------------------------------------------------------------------------------------------------------------------------------------
RegisterPersonController

package com.ff.controller;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.ff.beans.Person;
import com.ff.service.RegisterPersonService;

public class RegisterPersonController extends SimpleFormController{
private RegisterPersonService rps;

public RegisterPersonService getRps() {
return rps;
}

public void setRps(RegisterPersonService rps) {
this.rps = rps;
}

public RegisterPersonController(){
setCommandClass(com.ff.beans.Person.class);
setCommandName("person");
}

protected ModelAndView onSubmit(Object command , BindException errors) throws Exception{
Person p = (Person)command;
rps.addPerson(p);
return new ModelAndView("registered","personDetails",p);

}
}


------------------------------------------------------------------------------------------------------------------------------------------------
registered.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri = "http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>!!! Congratulations ...... You have registered successfully !!!</h1>

<a href="./displayDetailsInPDF.htm"> View details in PDF</a>
<a href="./displayDetailsInExcel.htm"> View details in Excel</a>

</body>
</html>
------------------------------------------------------------------------------------------------------------------------------------------------
DisplayDetailsInPdfController

package com.ff.controller;

import java.util.TreeMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;

import com.ff.beans.Person;

public class DisplayDetailsInPDF extends AbstractCommandController {

public DisplayDetailsInPDF(){
setCommandClass(com.ff.beans.Person.class);
}
protected ModelAndView handle(HttpServletRequest arg0,
HttpServletResponse arg1, Object command, BindException arg3)
throws Exception {

Person p = (Person)command;
System.out.println("The value of p:" + p);
System.out.println("firstname : "+p.getFirstName());
TreeMap map = new TreeMap();
map.put("personDetails", p);
return new ModelAndView(new DisplayDetailsInPDFView(),map);
}
}

------------------------------------------------------------------------------------------------------------------------------------------------
DisplayDetailsInPDFView

public class DisplayDetailsInPDFView extends AbstractPdfView {

protected void buildPdfDocument(Map model, Document doc, PdfWriter writer,
HttpServletRequest request, HttpServletResponse response) throws Exception {

Person p = (Person)model.get("personDetatils");
Chunk heading = new Chunk("Person Details");
heading.setBackground(Color.RED);
heading.setUnderline(3f, -3f);
doc.add(heading);
Paragraph para = new Paragraph();
if(p!=null){

para.add(p.getFirstName());
para.add("\n");
para.add(p.getLastName());
para.add("\n");
para.add(p.getPassword());
para.add("\n");
para.add(p.getEmail());


}else{
para.add("Person details not available");
}
doc.add(para);

}

}

------------------------------------------------------------------------------------------------------------------------------------------------
 
Faheem Farhan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No replies .......may be the length of the question is the cause.
ok

How to read the form content (data) in the next to next page(Page3) ?

Page1 (Form) ---> Page2 ---> Page3.
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried AbstractWizardFormController?
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can -
  • Put the data in the session
  • Pass the data to the new controller through a request parameter.
  • Use AbstractWizardFormController
  • Use SpringWebFlow.

  •  
    Hong Anderson
    Ranch Hand
    Posts: 1936
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    As Nathan suggested there are many ways.
    But from your requirement, Spring Web Flow is overkill, you can just use AbstractWizardFormController.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic