aspose file tools*
The moose likes Struts and the fly likes One form bean having form split into two different jsp pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "One form bean having form split into two different jsp pages" Watch "One form bean having form split into two different jsp pages" New topic
Author

One form bean having form split into two different jsp pages

namita sasa
Ranch Hand

Joined: Apr 20, 2009
Posts: 56
Hi, I am new to struts and really appreciate your help for this question.
Form bean contains: first name, last name, tuition fee
In jsp page 1, form1 contains fields: first name, last name
In jsp page 2, form2 contains field: tuition fee
In jsp page 3, form3 contains field:recurring fee
Action class1: populates form1 and submits it to DB
Action class2: populates form2 and submits it to DB
I have written separate action classes for inserting values from both forms to database but first name, last name, tuition fee, recurring fee all correspond to the same row in DB table even if they present in different forms.

When I am trying to submit form2 and form3, it is giving null pointer exception. (may be it is expecting all fields(first name, last name, tuition fee) in the same form instead of splitting it in two jsp pages??)
Is there any other way to handle this? My requirement is to split up input data( first name, last name, tuition fee etc.) in diffrent forms.(in different jsp's)
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

With no code or configuration information it's completely impossible to help.
namita sasa
Ranch Hand

Joined: Apr 20, 2009
Posts: 56
Hi, thanks for responding. Here are the details:

FeeClassActionForm:
String firstName;
String lastName;
String tuitionFee;
String recurringFee;



Action1 class:
FeeClassActionForm Form1 = (FeeClassActionForm) form;
FeeClass anc = new FeeClass();
anc.setLastName(Form1.getOrganization());//Value Objects
anc.setFirstName(Form1.getFirstName());

Action2 class:
FeeClassActionForm Form2 = (FeeClassActionForm) form;
FeeClass anc = new FeeClass();
anc.setTuitionFee(Form1.getTuitionFee());//Value Objects

Action3 class:
FeeClassActionForm Form3 = (FeeClassActionForm) form;
FeeClass anc = new FeeClass();
anc.setRecurringFee(Form1.getRecurringFee());//Value Objects


Based on condition selected in JSP form1, it either go to form2 or form3. But, when processing form 2 or form 3, I am getting null pointer exception.
Please help!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

...

I don't see the configuration. How are people supposed to know how your application is set up? How do we know you've configured the form beans properly?

*Where* is the NPE occurring? *You* know, but we don't--we can't just guess.

Please read esr's How To Ask Questions The Smart Way and see JavaRanch's own question-asking FAQ.
namita sasa
Ranch Hand

Joined: Apr 20, 2009
Posts: 56
I am using struts 1.2 and Tomcat 5.5.25.
The form bean just contain get-set methods for all four fields.
I don't have the code available with me currently since it's in my office.Sorry about that but I haven't added any validations in form bean since I want to run basic functionality first.
It's giving me error when it goes to processAction2.do or processAction3.do saying null pointer exception.I think it's not able to populate all fields from form bean since the form is split up??
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

There's no point in continuing until we can see the action/form configuration and you can tell us where the NPEs are happening.
namita sasa
Ranch Hand

Joined: Apr 20, 2009
Posts: 56
Here is the code:

public class AnnualActionForm extends ActionForm
{

private static Logger log = Logger.getLogger(AnnualActionForm.class);
private static final long serialVersionUID = 1L;

private String id;
private String organization;
private String firstName;
private String lastName;
private String giftInformation;
public AnnualActionForm()
{
this.setId(null);
this.setOrganization(null);
this.setFirstName(null);
this.setLastName(null);
this.setGiftInformation(null);
}
public void setId(String id)
{
this.id = (id != null) ? id.trim() : "0";
}
public void setOrganization(String organization)
{
this.organization = (organization != null) ? organization.trim() : "";
}
public void setFirstName(String firstName)
{
this.firstName = (firstName != null) ? firstName.trim() : "";
}
public void setLastName(String lastName)
{
this.lastName = (lastName != null) ? lastName.trim() : "";
}
public void setGiftInformation(String giftInformation)
{
this.giftInformation = (giftInformation != null) ? giftInformation.trim() : "";
}
public String getId()
{
return this.id;
}
public String getOrganization()
{
return this.organization;
}
public String getFirstName()
{
return this.firstName;
}
public String getLastName()
{
return this.lastName;
}
public String getGiftInformation()
{
return this.giftInformation;
}
public class AnnualLoadAction1 extends Action
{
private static Logger log = Logger.getLogger(AnnualLoadAction1.class);
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{
try
{
AnnualActionForm Form1 = (AnnualActionForm) form;
log.debug("inside action class");
Annual anc = new Annual();
anc.setOrganization(Form1.getOrganization());//value objects
anc.setFirstName(Form1.getFirstName());
anc.setLastName(Form1.getLastName());

request.setAttribute("form1", Form1);
request.setAttribute("anc",anc);
request.setAttribute("sponsorship", "Annual ");
log.debug("check which button pressed");
String buttonPressed=request.getParameter("giftInformation");
log.debug("button pressed="+buttonPressed);
if(buttonPressed!=null && buttonPressed.equalsIgnoreCase("One time gift"))
return mapping.findForward("onetimeGiftJSP");
else
return mapping.findForward("recurringGiftJSP");
}
catch (Exception e)
{
log.error(e);
return mapping.findForward("error");
}
}

public class AnnualLoadAction2 extends Action
{
private static Logger log = Logger.getLogger(AnnualLoadAction2.class);
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{
try
{
log.debug("inside action 2");
AnnualActionForm Form2 = (AnnualActionForm) form;
Annual anc=(Annual) request.getAttribute("anc");//get data entered in form 1 and add to that form 2 data to enter it in DB in one single row
anc.setOneTimeAmount(Double.parseDouble(Form2.getOneTimeAmount()));
request.setAttribute("amount",Double.parseDouble(Form2.getOneTimeAmount()));
request.setAttribute("form2", Form2);
return mapping.findForward("redirectJSP");
}
catch (Exception e)
{
log.error(e);
return mapping.findForward("error");
}
}
}

public class AnnualLoadAction3 extends Action
{
private static Logger log = Logger.getLogger(AnnualLoadAction3.class);

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{
try
{
AnnualActionForm Form3 = (AnnualActionForm) form;
Annual anc=(Annual) request.getAttribute("anc");
ecurringAmount=Double.parseDouble(Form3.getRecurringAmount());

anc.setRecurringAmount(recurringAmount);//value object
request.setAttribute("form3", Form3);
request.setAttribute("amount",totalAmount);
return mapping.findForward("redirectJSP");
}
catch (Exception e)
{
log.error(e);
return mapping.findForward("error");
}
}


I am not able to find where exactly NPE is occuring. The stack trace says:

2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG ConvertUtils - Convert string 'NE' to class 'java.lang.String'
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG StringConverter - Converting 'String' value 'NE' to type 'String'
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG ConvertUtils - Convert string 'gk' to class 'java.lang.String'
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG StringConverter - Converting 'String' value 'gk' to type 'String'
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG ConvertUtils - Convert string '576' to class 'java.lang.String'
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG StringConverter - Converting 'String' value '576' to type 'String'
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG ConvertUtils - Convert string 'gj' to class 'java.lang.String'
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG StringConverter - Converting 'String' value 'gj' to type 'String'
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG ConvertUtils - Convert string 'yhk' to class 'java.lang.String'
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG StringConverter - Converting 'String' value 'yhk' to type 'String'
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG ActionCommandBase - Executing org.apache.struts.chain.commands.servlet.ValidateActionForm
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG ActionCommandBase - Executing org.apache.struts.chain.commands.servlet.SelectInput
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG ActionCommandBase - Executing org.apache.struts.chain.commands.ExecuteCommand
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG ActionCommandBase - Executing org.apache.struts.chain.commands.servlet.SelectForward
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG ActionCommandBase - Executing org.apache.struts.chain.commands.SelectInclude
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG ActionCommandBase - Executing org.apache.struts.chain.commands.servlet.PerformInclude
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG ActionCommandBase - Executing org.apache.struts.chain.commands.servlet.CreateAction
2009-04-21 13:46:41,394 [http-8080-1 ] DEBUG ActionCommandBase - Executing org.apache.struts.chain.commands.servlet.ExecuteAction
2009-04-21 13:46:41,394 [http-8080-1 ] ERROR AnnualLoadAction1 - java.lang.NullPointerException
2009-04-21 13:46:41,441 [http-8080-1 ] DEBUG ActionCommandBase - Executing org.apache.struts.chain.commands.ExecuteForwardCommand
2009-04-21 13:46:41,441 [http-8080-1 ] DEBUG ActionCommandBase - Executing org.apache.struts.chain.commands.servlet.PerformForward
2009-04-21 13:46:41,441 [http-8080-1 ] DEBUG [/paymentsgateway2] - servletPath=/registration/annual2.jsp, pathInfo=null, queryString=status=failure, name=null
2009-04-21 13:46:41,441 [http-8080-1 ] DEBUG PerformForward - Forwarding to /registration/annual2.jsp?status=failure
2009-04-21 13:46:41,441 [http-8080-1 ] DEBUG [/paymentsgateway2] - Path Based Forward
2009-04-21 13:46:41,441 [http-8080-1 ] DEBUG JspServlet - JspEngine --> /registration/annual.jsp
2009-04-21 13:46:41,441 [http-8080-1 ] DEBUG JspServlet - ServletPath: /registration/annual.jsp
2009-04-21 13:46:41,441 [http-8080-1 ] DEBUG JspServlet - PathInfo: null
2009-04-21 13:46:41,441 [http-8080-1 ] DEBUG JspServlet - RealPath: C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\paymentsgateway2\registration\annual2.jsp
2009-04-21 13:46:41,441 [http-8080-1 ] DEBUG JspServlet - RequestURI: /paymentsgateway2/registration/annual.jsp
2009-04-21 13:46:41,441 [http-8080-1 ] DEBUG JspServlet - QueryString: status=failure
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags. Turning up the logging level may help with the stack trace; I don't know of any excpetion swallowing--are you sure you're looking in the right log file? Try other techniques like using log statements--it's going to be really hard to help if you can't tell us where the NPE occurs.

*PLEASE* show the configuration. I don't understand why you won't.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: One form bean having form split into two different jsp pages