You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Deep Chand <dg...@gmail.com> on 2005/10/09 20:58:23 UTC

Please help.

Hi All,

I'm new to Struts, so please bear with me :). I've a form asking for
customer data with fields
like name, address etc.  What I'm trying to achieve is this kind of flow/design:

 Page1) Customer enters their info. Submit button will take them to Page2.
 Page2) They are asked to verify the same info again with read only
 fields. Two buttons will be there, Confirm/Submit and Change. Change
 will take them to Page1 and Confirm/Submit will take them to Page3.
 Page3) The info is displayed to them again after entering it into the DB.

What i see is the control never goes to  CustomerConfirmAction class.
What I'm doing wrong?  Any help is appreciated.

Thanks, Deep

I've the following configuration and code.

	<action-mappings>
		<action path  = "/customerCreate"
	  	        type  = "customer.CustomerAction"
		        scope = "request"
			input = "/jsp/customer/CustomerCreate.jsp"
			name  = "customerForm">
 		<forward name="customerConfirm" path="/jsp/customer/CustomerConfirm.jsp"/>			
		</action>	
	        <action path  = "/customerConfirm"
			type  = "customer.CustomerConfirmAction"
			scope = "request"
			name  = "customerForm"
			input = "/jsp/customer/CustomerConfirm.jsp">
		  <forward name="customerView"
path="/jsp/customer/CustomerView.jsp"/>				</action>
	</action-mappings>

CustomerCreate.jsp:
<html:form action="customerCreate" method="POST">

	<TABLE border="0" width="700">
		<TR>
			<TD>First Name</TD>
			<TD><html:text property="customer.firstName" /></TD>
		</TR>
                 ... ....
		<TR>
			<TD><html:submit property="submit" /></TD>
			<TD><html:cancel property="cancel" /></TD>
		</TR>

CustomerConfirm.jsp:
<html:form action="customerConfirm" method="POST">

	<TABLE border="0" width="700">
		<TR>
			<TD>First Name</TD>
			<TD><bean:write name="customer" property="firstName" /></TD>
		</TR>

CustomerAction.java:
		CustomerForm cf = (CustomerForm)form;
		Customer customer = cf.getCustomer();
		request.setAttribute("customer", customer);
		return mapping.findForward("customerConfirm");

CustomerConfirmAction.java:
		Customer customer = (Customer)request.getAttribute("customer");
		request.setAttribute("customer", customer);
		DAOFactory daf = DAOFactory.getFactory(DAOFactory.FACTORY_MYSQL);
		
		CustomerDAO custDAO = daf.getCustomerDAO();
		if (custDAO.insertCustomer(customer) > 0) {
			return mapping.findForward("customerView");
		}

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Please help.

Posted by Michael Jouravlev <jm...@gmail.com>.
1) "input" attribute name is misleading. It is not actually an input
page, it is a location where control will be forwarded in case of
error, that is, if ActionForm.validate() returns non-null non-empty
object.

2) Do not navigate directly to JSP page in browser, navigate to
action. Action is supposed to be a controller that tackles with input
data, JSP page is a view that displays output data.

3) Because of (2), forward to JSP page from your action mapping only
when you want to display the page.

4) If you navigate directly to a JSP page, your action class will
never be called, even if the page is defined as "input" for some
action. In your particular case, you forward to
"/jsp/customer/CustomerConfirm.jsp". The action class will never be
called.

Michael.

On 10/9/05, Deep Chand <dg...@gmail.com> wrote:
> Hi All,
>
> I'm new to Struts, so please bear with me :). I've a form asking for
> customer data with fields
> like name, address etc.  What I'm trying to achieve is this kind of flow/design:
>
>  Page1) Customer enters their info. Submit button will take them to Page2.
>  Page2) They are asked to verify the same info again with read only
>  fields. Two buttons will be there, Confirm/Submit and Change. Change
>  will take them to Page1 and Confirm/Submit will take them to Page3.
>  Page3) The info is displayed to them again after entering it into the DB.
>
> What i see is the control never goes to  CustomerConfirmAction class.
> What I'm doing wrong?  Any help is appreciated.
>
> Thanks, Deep
>
> I've the following configuration and code.
>
>         <action-mappings>
>                 <action path  = "/customerCreate"
>                         type  = "customer.CustomerAction"
>                         scope = "request"
>                         input = "/jsp/customer/CustomerCreate.jsp"
>                         name  = "customerForm">
>                 <forward name="customerConfirm" path="/jsp/customer/CustomerConfirm.jsp"/>
>                 </action>
>                 <action path  = "/customerConfirm"
>                         type  = "customer.CustomerConfirmAction"
>                         scope = "request"
>                         name  = "customerForm"
>                         input = "/jsp/customer/CustomerConfirm.jsp">
>                   <forward name="customerView"
> path="/jsp/customer/CustomerView.jsp"/>                         </action>
>         </action-mappings>
>
> CustomerCreate.jsp:
> <html:form action="customerCreate" method="POST">
>
>         <TABLE border="0" width="700">
>                 <TR>
>                         <TD>First Name</TD>
>                         <TD><html:text property="customer.firstName" /></TD>
>                 </TR>
>                  ... ....
>                 <TR>
>                         <TD><html:submit property="submit" /></TD>
>                         <TD><html:cancel property="cancel" /></TD>
>                 </TR>
>
> CustomerConfirm.jsp:
> <html:form action="customerConfirm" method="POST">
>
>         <TABLE border="0" width="700">
>                 <TR>
>                         <TD>First Name</TD>
>                         <TD><bean:write name="customer" property="firstName" /></TD>
>                 </TR>
>
> CustomerAction.java:
>                 CustomerForm cf = (CustomerForm)form;
>                 Customer customer = cf.getCustomer();
>                 request.setAttribute("customer", customer);
>                 return mapping.findForward("customerConfirm");
>
> CustomerConfirmAction.java:
>                 Customer customer = (Customer)request.getAttribute("customer");
>                 request.setAttribute("customer", customer);
>                 DAOFactory daf = DAOFactory.getFactory(DAOFactory.FACTORY_MYSQL);
>
>                 CustomerDAO custDAO = daf.getCustomerDAO();
>                 if (custDAO.insertCustomer(customer) > 0) {
>                         return mapping.findForward("customerView");
>                 }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Please help.

Posted by Deep Chand <dg...@gmail.com>.
If I do that then I don't see a jsp page asking me to Confirm the
data. It goes to the ConfirmAction class but as I said, what I want is

Enter info on Page1.
Ask for confirmation on Page2 and then insert the data in DB using
DataAccess object.
Display the data on Page3 that was entered by the user indicating
customer is created.

I thought this should be very simple ...a very very common use case.

Thanks
Deep



On 10/9/05, Jeremiah Johnson <jo...@egr.msu.edu> wrote:
> your path for the "customerConfirm" forward should be
> "/customerConfirm.do" probably but it might be "/do/customerConfirm"
> depending on what you have in your web.xml.
> /Jeremiah
>
>
> Deep Chand wrote:
> > Hi All,
> >
> > I'm new to Struts, so please bear with me :). I've a form asking for
> > customer data with fields
> > like name, address etc.  What I'm trying to achieve is this kind of flow/design:
> >
> >  Page1) Customer enters their info. Submit button will take them to Page2.
> >  Page2) They are asked to verify the same info again with read only
> >  fields. Two buttons will be there, Confirm/Submit and Change. Change
> >  will take them to Page1 and Confirm/Submit will take them to Page3.
> >  Page3) The info is displayed to them again after entering it into the DB.
> >
> > What i see is the control never goes to  CustomerConfirmAction class.
> > What I'm doing wrong?  Any help is appreciated.
> >
> > Thanks, Deep
> >
> > I've the following configuration and code.
> >
> >       <action-mappings>
> >               <action path  = "/customerCreate"
> >                       type  = "customer.CustomerAction"
> >                       scope = "request"
> >                       input = "/jsp/customer/CustomerCreate.jsp"
> >                       name  = "customerForm">
> >               <forward name="customerConfirm" path="/jsp/customer/CustomerConfirm.jsp"/>
> >               </action>
> >               <action path  = "/customerConfirm"
> >                       type  = "customer.CustomerConfirmAction"
> >                       scope = "request"
> >                       name  = "customerForm"
> >                       input = "/jsp/customer/CustomerConfirm.jsp">
> >                 <forward name="customerView"
> > path="/jsp/customer/CustomerView.jsp"/>                               </action>
> >       </action-mappings>
> >
> > CustomerCreate.jsp:
> > <html:form action="customerCreate" method="POST">
> >
> >       <TABLE border="0" width="700">
> >               <TR>
> >                       <TD>First Name</TD>
> >                       <TD><html:text property="customer.firstName" /></TD>
> >               </TR>
> >                  ... ....
> >               <TR>
> >                       <TD><html:submit property="submit" /></TD>
> >                       <TD><html:cancel property="cancel" /></TD>
> >               </TR>
> >
> > CustomerConfirm.jsp:
> > <html:form action="customerConfirm" method="POST">
> >
> >       <TABLE border="0" width="700">
> >               <TR>
> >                       <TD>First Name</TD>
> >                       <TD><bean:write name="customer" property="firstName" /></TD>
> >               </TR>
> >
> > CustomerAction.java:
> >               CustomerForm cf = (CustomerForm)form;
> >               Customer customer = cf.getCustomer();
> >               request.setAttribute("customer", customer);
> >               return mapping.findForward("customerConfirm");
> >
> > CustomerConfirmAction.java:
> >               Customer customer = (Customer)request.getAttribute("customer");
> >               request.setAttribute("customer", customer);
> >               DAOFactory daf = DAOFactory.getFactory(DAOFactory.FACTORY_MYSQL);
> >
> >               CustomerDAO custDAO = daf.getCustomerDAO();
> >               if (custDAO.insertCustomer(customer) > 0) {
> >                       return mapping.findForward("customerView");
> >               }
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Please help.

Posted by Jeremiah Johnson <jo...@egr.msu.edu>.
your path for the "customerConfirm" forward should be 
"/customerConfirm.do" probably but it might be "/do/customerConfirm" 
depending on what you have in your web.xml.
/Jeremiah


Deep Chand wrote:
> Hi All,
> 
> I'm new to Struts, so please bear with me :). I've a form asking for
> customer data with fields
> like name, address etc.  What I'm trying to achieve is this kind of flow/design:
> 
>  Page1) Customer enters their info. Submit button will take them to Page2.
>  Page2) They are asked to verify the same info again with read only
>  fields. Two buttons will be there, Confirm/Submit and Change. Change
>  will take them to Page1 and Confirm/Submit will take them to Page3.
>  Page3) The info is displayed to them again after entering it into the DB.
> 
> What i see is the control never goes to  CustomerConfirmAction class.
> What I'm doing wrong?  Any help is appreciated.
> 
> Thanks, Deep
> 
> I've the following configuration and code.
> 
> 	<action-mappings>
> 		<action path  = "/customerCreate"
> 	  	        type  = "customer.CustomerAction"
> 		        scope = "request"
> 			input = "/jsp/customer/CustomerCreate.jsp"
> 			name  = "customerForm">
>  		<forward name="customerConfirm" path="/jsp/customer/CustomerConfirm.jsp"/>			
> 		</action>	
> 	        <action path  = "/customerConfirm"
> 			type  = "customer.CustomerConfirmAction"
> 			scope = "request"
> 			name  = "customerForm"
> 			input = "/jsp/customer/CustomerConfirm.jsp">
> 		  <forward name="customerView"
> path="/jsp/customer/CustomerView.jsp"/>				</action>
> 	</action-mappings>
> 
> CustomerCreate.jsp:
> <html:form action="customerCreate" method="POST">
> 
> 	<TABLE border="0" width="700">
> 		<TR>
> 			<TD>First Name</TD>
> 			<TD><html:text property="customer.firstName" /></TD>
> 		</TR>
>                  ... ....
> 		<TR>
> 			<TD><html:submit property="submit" /></TD>
> 			<TD><html:cancel property="cancel" /></TD>
> 		</TR>
> 
> CustomerConfirm.jsp:
> <html:form action="customerConfirm" method="POST">
> 
> 	<TABLE border="0" width="700">
> 		<TR>
> 			<TD>First Name</TD>
> 			<TD><bean:write name="customer" property="firstName" /></TD>
> 		</TR>
> 
> CustomerAction.java:
> 		CustomerForm cf = (CustomerForm)form;
> 		Customer customer = cf.getCustomer();
> 		request.setAttribute("customer", customer);
> 		return mapping.findForward("customerConfirm");
> 
> CustomerConfirmAction.java:
> 		Customer customer = (Customer)request.getAttribute("customer");
> 		request.setAttribute("customer", customer);
> 		DAOFactory daf = DAOFactory.getFactory(DAOFactory.FACTORY_MYSQL);
> 		
> 		CustomerDAO custDAO = daf.getCustomerDAO();
> 		if (custDAO.insertCustomer(customer) > 0) {
> 			return mapping.findForward("customerView");
> 		}
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org