i m using multiple submit buttons on my
jsp it includes buttons for ADD, EDIT and DELETE
now i want to ask how to let them executed in a single ACTION class???
i read somewhere that we can have the methods of the names that can be bound with the Buttons on JSP but doing that in
struts 1.2.9 is not working...
i just want to know the exact way of doing this...
i m attaching my code of the jsp n Action here please do let me know whether it is right way to do it or not???
NOTE : PLEASE CONSIDER 'lessthan' and 'greaterthan' signs as required coz its not allowing me to add that signs...
and Execute is actually execute
public class UserAction extends Action {
/**
*
*/
public UserAction() {
super();
}
/* (non-Javadoc)
* @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public UserBean createBean(HttpServletRequest request)
{
String password=null;
String contactNo=request.getParameter("countryCode")+'-'+request.getParameter("areaCode")+'-'+request.getParameter("phoneNo");
password=PasswordUtil.generatePassword();
UserBean ub = new UserBean();
ub.setUserName(request.getParameter("userName"));
ub.setUserPassword(password);
ub.setRoleId((int) 2);
//ub.setRoleId(Integer.parseInt(request.getParameter("roleId")));
ub.setUserEmailID(request.getParameter("userEmailID"));
ub.setUserAlias(request.getParameter("userAlias"));
ub.setFirstName(request.getParameter("firstName"));
ub.setLastName(request.getParameter("lastName"));
ub.setContactNo(contactNo);
ub.setLocation(request.getParameter("location"));
ub.setExtensionNo(request.getParameter("extensionNo"));
ub.setMobileNo(request.getParameter("mobileNo"));
return ub;
}
public ArrayList createBean(ArrayList userList)
{
return userList;
}
public ActionForward Execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
ArrayList userList=new ArrayList();
userList=UserBusiness.findAll();
request.setAttribute("users",userList);
return mapping.findForward("success");
}
public ActionForward save(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
boolean res=false;
boolean res1=false;
UserBean ub=createBean(request);
res1=UserBusiness.validateUser(request,ub);
if(res1){
res=UserBusiness.addRecord(ub);
}
if(res)
{
return mapping.findForward("success");
}
else
{
return mapping.findForward("faliour");
}
}
/**
* Method edit
* @param ActionMapping mapping
* @param ActionForm form
* @param HttpServletRequest request
* @param HttpServletResponse response
* @return ActionForward
* @throws Exception
*/
public ActionForward edit(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
boolean res=false;
boolean res1=false;
UserBean ub=createBean(request);
res1=UserBusiness.validateUser(request,ub);
if(res1)
{
res=UserBusiness.updateRecord(ub);
}
if(res)
{
return mapping.findForward("success");
}
else
{
return mapping.findForward("faliour");
}
}
/**
* Method edit
* @param ActionMapping mapping
* @param ActionForm form
* @param HttpServletRequest request
* @param HttpServletResponse response
* @return ActionForward
* @throws Exception
*/
public ActionForward delete(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
boolean res=false;
UserBean ub=createBean(request);
res=UserBusiness.updateRecord(ub);
if(res)
{
return mapping.findForward("success");
}
else
{
return mapping.findForward("faliour");
}
}
}
[ May 09, 2006: Message edited by: lubna ]