Faheem Farhan

Greenhorn
+ Follow
since Aug 04, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Faheem Farhan

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.
14 years ago
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);

}

}

------------------------------------------------------------------------------------------------------------------------------------------------
14 years ago