aspose file tools*
The moose likes Struts and the fly likes multi-step user registration  ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "multi-step user registration  ?" Watch "multi-step user registration  ?" New topic
Author

multi-step user registration ?

harish pathak
Ranch Hand

Joined: Dec 17, 2005
Posts: 51
Hi All,

I want to create multi-step user registration (multi step form) in struts.

Please give me the idea...........how to do that?

Thanks
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
My suggestion would be to create a single ActionForm with properties for all the fields needed by all pages of the registration process. Assign this same ActionForm to each of the pages and specify "session" as the scope. The user can then move back and forth between the pages with all values being retained. Then when the final page is submitted, all the data needed will be in the ActionForm and can be persisted.


Merrill
Consultant, Sima Solutions
harish pathak
Ranch Hand

Joined: Dec 17, 2005
Posts: 51
Hi,

Thanks for your response.

Now I have a idea how to do that.

Thanks

Harish Pathak
harish pathak
Ranch Hand

Joined: Dec 17, 2005
Posts: 51
Thanks for your reply.

Well I have created a formbean (fields of all jsp) and configure my struts-config.xml file as:


code:
--------------------------------------------------------------------------------

<struts-config><form-beans><form-bean name="userRegistrationForm" type="multipleform.UserRegistrationForm"/></form-beans><action-mappings> <action path="/userRegistration" type="multipleform.UserRegistrationAction"name="userRegistrationForm"attribute="user"scope="session"input="/multipleform.jsp"><forward name="success" path="/multipleform1.jsp"/><forward name="failure" path="/userregfailure.jsp"/></action> <action path="/userRegistration1" type="multipleform.UserRegistrationAction"name="userRegistrationForm"attribute="user"scope="session"input="/multipleform1.jsp"><forward name="success" path="/userregsuccess.jsp"/><forward name="failure" path="/userregfailure.jsp"/></action></action-mappings></struts-config>

--------------------------------------------------------------------------------



multipleform.jsp is as:


code:
--------------------------------------------------------------------------------

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%><%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%><html><head><title>User Registration</title></head><body><h1>User Registration</h1><html:errors/><table><html:form action="/userRegistration.do" focus="firstName"><tr><td>First Name</td><td><html:text property="firstName"/></td></tr><td>Last Name</td><td><html:text property="lastName"/></td><tr><td>User Name</td><td><html:text property="userName"/></td></tr><tr><td>Email:</td><td><html:text property="email"/></td></tr><tr><td>Phone</td><td><html:text property="phone"/></td></tr><tr><td>Fax</td><td><html:text property="fax"/></td></tr><tr><td>Password</td><td><html assword property="password"/></td></tr><tr><td>Retype password</td><td><html assword property="passwordCheck"/><html:hidden property="page" value="2"/></td></tr><tr><td><html:submit/></td><td><html:cancel/></td></tr></html:form></table></body></html>

--------------------------------------------------------------------------------



multipleform1.jsp is as:


code:
--------------------------------------------------------------------------------

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%><%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%><html><head><title>User Registration</title></head><body><h1>User Registration</h1><html:errors/><table><html:form action="/userRegistration1.do"><tr><td>Ename:</td><td><html:text property="ename"/></td></tr><tr><td><html:submit/></td><td><html:cancel/></td></tr></html:form></table></body></html>

--------------------------------------------------------------------------------



UserRegistrationForm is as:

code:
--------------------------------------------------------------------------------

package multipleform; import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionMapping;import org.apache.struts.action.ActionErrors;import org.apache.struts.action.ActionError;import javax.servlet.http.HttpServletRequest; public class UserRegistrationForm extends ActionForm {private String firstName;private String lastName;private String userName;private String password;private String passwordCheck;private String email;private String phone;private String fax;private String ename;private boolean registered; public UserRegistrationForm() {} public String getFirstName() {return this.firstName;}public void setFirstName(String firstName) {this.firstName = firstName;} public String getEmail() {return this.email;}public void setEmail(String email) {this.email = email;} public String getLastName() {return this.lastName;}public void setLastName(String lastName) {this.lastName = lastName;} public String getUserName() {return this.userName;}public void setUserName(String userName) {this.userName = userName;} public String getPassword() {return this.password;}public void setPassword(String password) {this.password = password;} public String getPasswordCheck() {return this.passwordCheck;}public void setPasswordCheck(String passwordCheck) {this.passwordCheck = passwordCheck;} public String getPhone() {return this.phone;}public void setPhone(String phone) {this.phone = phone;} public String getFax() {return this.fax;}public void setFax(String fax) {this.fax = fax;} public boolean getRegistered() {return this.registered;}public void setRegistered(boolean registered) {this.registered = registered;} public String getEname() {return this.ename;}public void setEname(String ename) {this.ename = ename;} public void reset(ActionMapping mapping,HttpServletRequest request) {firstName=null;lastName=null;userName=null;password=null;passwordCheck=null;email=null;phone=null;fax=null;registered=false;} private String[] defaultValues ={ firstName, lastName, userName, password,passwordCheck,email,phone,fax }; public boolean isMissing(String value) {if ((value == null) || (value.trim().equals(""))){return(true);} else {for(int i=0; i<defaultValues.length; i++) {if (value.equals(defaultValues[i])) {return(true);}}return(false);}} }

--------------------------------------------------------------------------------



The following is the url...
http://localhost/multipleform.jsp

When I click on the Submit button of this form the following page opens

url is :
http://localhost/multipleform1.jsp

And it gives me the following error:

says......


code:
--------------------------------------------------------------------------------

javax.servlet.jsp.JspException: No getter method for property ename of bean org.apache.struts.taglib.html.BEAN

--------------------------------------------------------------------------------



I don't know where I am going wrong well as I have created a form bean in which there are set and get methods of all jsps.

Answer Please...

Please reply soon.

Thanks in advance..
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
try changing

<html:form action="/userRegistration.do" ...

to

<html:form action="/userRegistration"

When the error message lists org.apache.struts.taglib.html.BEAN as the bean, that means Struts is not finding the correct form bean. Since it's the action attribute in the <html:form> tag that associates the page with the correct form bean, it must match exactly the action path definied in the struts-config.xml file.
harish pathak
Ranch Hand

Joined: Dec 17, 2005
Posts: 51
Thanks for your reply,

But that's not the problem as I have changed the setting as you describe but its giving me the same problem.

Now my change struts-config.xml file is as:
----------------------------
<form-beans>
<form-bean name="userRegistrationForm" type="multipleform.UserRegistrationForm"/>
</form-beans>


<action-mappings>
<action path="/userRegistration"
type="multipleform.UserRegistrationAction"
name="userRegistrationForm"
attribute="user"
scope="session"
input="/multipleform.jsp">
<forward name="success" path="/multipleform1.jsp"/>
<forward name="failure" path="/userregfailure.jsp"/>
</action>

<action path="/userRegistration1"
type="multipleform.UserRegistrationAction"
name="userRegistrationForm"
attribute="user1"
scope="session"
input="/multipleform1.jsp">
<forward name="success" path="/userregsuccess.jsp"/>
<forward name="failure" path="/userregfailure.jsp"/>
</action>

</action-mappings>
----------------------------


Please reply..

Thanks
Kamesh Loganathan
Greenhorn

Joined: Jan 21, 2006
Posts: 20
Hi Pal,
I think u shouldnot use / before ur action mapping name.
remove the / in ur html:form and action mapping as i have shown
below and try.

When / is put, the absolute path is taken that is why
in ur url the context root has changed.
----------------------------------------------------------
<html:form action="userRegistration.do" ...


<form-beans>
<form-bean name="userRegistrationForm" type="multipleform.UserRegistrationForm"/>
</form-beans>


<action-mappings>
<action path="userRegistration"
type="multipleform.UserRegistrationAction"
name="userRegistrationForm"
attribute="user"
scope="session"
input="/multipleform.jsp">
<forward name="success" path="/multipleform1.jsp"/>
<forward name="failure" path="/userregfailure.jsp"/>
</action>

<action path="userRegistration1"
type="multipleform.UserRegistrationAction"
name="userRegistrationForm"
attribute="user1"
scope="session"
input="/multipleform1.jsp">
<forward name="success" path="/userregsuccess.jsp"/>
<forward name="failure" path="/userregfailure.jsp"/>
</action>

</action-mappings>

----------------------------------------------------------------
harish pathak
Ranch Hand

Joined: Dec 17, 2005
Posts: 51
Hi,

Thanks for your reply,

well I have changed the setting as you mentioned but now it gives me the following error.
-----------
javax.servlet.jsp.JspException: Cannot retrieve mapping for action /userRegistration
------------
If I changed the setting mentioned by you.

Thanks
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I believe I finally see the problem:

Remove attribute="user" from both your userRegistration and userRegistration1 action mappings in the struts-config.xml file. This has the effect of nullifying the connection between the action and the userRegistrationForm bean.

Your two <html:form> tags should have attribute="/userRegistration1" and attribute="/userRegistration"

P.S. For future reference, when you post code, please put it in a more readable format with indentation and white space. Had this code not been in such an unreadable format, someone might have caught this sooner.
[ January 25, 2006: Message edited by: Merrill Higginson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multi-step user registration ?