Rajat,
I don't get what mean. Where did you get the value for result from?
so in this case, I have two files, actionform and action classes, How
and where do I modify these files in order for the buttons to work?
Do I have to modify in other files as well?
Thanks for your help.
Dinh nguyen
====================================================
Here is the ActionForm file.
package studentweblog.ActionForm;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
/**
Register Form
*/
public final class RegisterForm extends ActionForm {
private String userName = null;
private String password = null;
private String confirmPassword = null;
private String firstName =null;
private String lastName = null;
private String address = null;
private String country = null;
private String state =null;
private String city = null;
private String zip = null;
private String telephone = null;
private String email =null;
private boolean accountType = false;
public String getUserName() {
return userName;
}
public String getPassword() {
return password;
}
public String getConfirmPassword() {
return confirmPassword;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getAddress() {
return address;
}
public String getCountry() {
return country;
}
public String getState() {
return state;
}
public String getCity() {
return city;
}
public String getZip() {
return zip;
}
public String getTelephone() {
return telephone;
}
public String getEmail() {
return email;
}
public boolean getAccountType() {
return accountType;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
userName = null;
password = null;
confirmPassword = null;
firstName =null;
lastName = null;
address = null;
country = null;
state =null;
city = null;
zip = null;
telephone = null;
email =null;
accountType = false;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setPassword(String password) {
this.password = password;
}
public void setConfirmPassword(String confirmPassword) {
this.confirmPassword = confirmPassword;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setAddress(String address) {
this.address = address;
}
public void setCountry(String country) {
this.country = country;
}
public void setState(String state) {
this.state = state;
}
public void setCity(String city) {
this.city = city;
}
public void setZip(String zip) {
this.zip = zip;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public void setEmail(String email) {
this.email = email;
}
public void setAccountType(boolean accountType) {
this.accountType = accountType;
}
//Here we start doing validation. The simple validation now we can
make by checking
//all required fields which must have values entered.
// We have to check 5 required fields based on our last
mockup:USERNAME,PASSWORD,
// CONFIRMPASSWORD, EMAIL
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if ((userName == null) || (userName.length() < 1))
errors.add("userName", new ActionError
("error.userName.required"));
if ((password == null)|| (password.length() < 1))
errors.add("password", new ActionError
("error.password.required"));
if ((confirmPassword == null)|| (confirmPassword.length() <
1))
errors.add("confirmPassword", new ActionError
("error.confirmPassword.required"));
if ( ! password.equals(confirmPassword))
errors.add("notMatch", new ActionError
("error.notMatchPassword.required"));
if ((email == null) || (email.length() < 1))
errors.add("email", new ActionError
("error.email.required"));
return errors;
}
}
====================================================
****************************************************
Here is the action class file
=================
/*
* Created on Oct 4, 2003
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and
Comments
*/
package studentweblog.Action;
/**
* @author
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and
Comments
*/
import javax.servlet.http.*;
import org.apache.struts.action.*;
import studentweblog.ActionForm.*;
public final class RegisterAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
RegisterForm f = (RegisterForm) form; // get the form bean
// and take the last name value
String userName = f.getUserName();
String password = f.getPassword();
String confirmPassword = f.getConfirmPassword();
String firstName = f.getFirstName();
String lastName = f.getLastName();
String address = f.getAddress();
String country = f.getCountry();
String state = f.getState();
String city = f.getCity();
String zip = f.getZip();
String telephone = f.getTelephone();
String email = f.getEmail();
boolean accountType = f.getAccountType();
// Translate the name to upper case
//and save it in the request object
request.setAttribute("userName", userName.toUpperCase());
request.setAttribute("password", password.toUpperCase());
request.setAttribute("confirmPassword",
confirmPassword.toUpperCase());
request.setAttribute("firstName", firstName.toUpperCase());
request.setAttribute("lastName", lastName.toUpperCase());
request.setAttribute("address", address.toUpperCase());
request.setAttribute("country", country.toUpperCase());
request.setAttribute("state", state.toUpperCase());
request.setAttribute("city", city.toUpperCase());
request.setAttribute("zip", zip.toUpperCase());
request.setAttribute("telephone", telephone.toUpperCase());
request.setAttribute("email", email.toUpperCase());
//request.setAttribute("accountType", accountType.toUpperCase
());
// Forward control to the specified success target
return (mapping.findForward("success"));
}
}
=========================================================
--- In [EMAIL PROTECTED], "Rajat Pandit" <[EMAIL PROTECTED]> wrote:
> Hi,
> Hmm,, well if you have seen the execute function of the action
class it
> returns ActionForward value.
>
> So in ur action class where you have been able to do a sucessfully
> commit to the db or performed some action then you need to return
the
> forward value.
>
> For example
>
> public ActionForward execute(ActionMapping mapping,
> ActionForm form,
> javax.servlet.http.HttpServletRequest
> request,
> javax.servlet.http.HttpServletResponse
> response)
> throws java.lang.Exception
> {
>
>
> String target = new String();
> If (result) {
> target = "success";
> } else {
> target = "failure";
> }
>
> return (mapping.findForward(target));
> }
>
>
> In ur structs-config.xml make the rquire <forward tags for the
target
> values "success" and "failure"
>
> Hope this helps!!
>
>
> -----Original Message-----
> From: Dinh Nguyen [mailto:[EMAIL PROTECTED]
> Sent: Saturday, October 25, 2003 12:11 PM
> To: [EMAIL PROTECTED]
> Subject: Re: How to do Confirmation page.
>
>
> Hi Rajat,
>
> Ok, let say, whatever page, the user wants to save the information,
> then the Save (Submit) button will be implemented. But how do you
do
> that? Can you give me example? how do I use the forward in my
> action class?
>
> Thanks,
> Dinh nguyen
>
> --- In [EMAIL PROTECTED], "Rajat Pandit" <[EMAIL PROTECTED]> wrote:
> > <html:cancel.. Should do the job. However you could use do
different
> > forwards in ur action class. Depending on the value of submit
> clicked
> > on.
> > Also to keep it simple, just javascript on the onClick even on
the
> > cancel button and use the actual submit button for sending the
> content
> > to the action class via the controller.
> >
> >
> > -----Original Message-----
> > From: Dinh Nguyen [mailto:[EMAIL PROTECTED]
> > Sent: Saturday, October 25, 2003 12:02 PM
> > To: [EMAIL PROTECTED]
> > Subject: How to do Confirmation page.
> >
> >
> > Hi,
> >
> > Do you know how to do the confirm page using struts? For example,
> > after a person fill-out a registration form, he/she clicks on
> Submit
> > button, she/he will be redirected to a page says that "are you
sure
> > you want to submit information?". If the use clicks yes, button,
> > then he/she will be redirected back to the home page, otherwise,
> > he/she will be redirected back to registration form/page if the
> > cancel button is clicked.
> >
> > Thanks,
> > dinh Nguyen
> >
> >
> > ------------------------------------------------------------------
--
> -
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> > ------------------------------------------------------------------
--
> -
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> --------------------------------------------------------------------
-
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> --------------------------------------------------------------------
-
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]