working with two buttons in jsp
hi
My working with jsp's in struts.
I have a jsp with two buttons "Save" and "Delete".
My requirement is, on clicking either the "save button" or "Delete button" in jsp, it should call the corresponding code in the Action class.
wht is the logic required to call the corresponding code in the Action class ?
Thanks
# 3
[nobr]hi
Thanks nani and jHyena for ur reply , but its not working, can u tell me where i went wrong, how to set them in jsp and action class.
This is my Action class
public class EditUserDetailsAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws DaoException {
System.out.println("in execute() befor try/catch--");
//**************************the problem is here calling in if()/else, how should i call i?**************
if() {
try{
EditUserDetailsForm editUserDetailsForm = (EditUserDetailsForm) form;
System.out.println(" execute()--");
DaoImplementer daoImpl = new DaoImplementer();
Integer editUid= (Integer) editUserDetailsForm.getUser_Id();
String editName= (String) editUserDetailsForm.getName();
String editTitle= (String) editUserDetailsForm.getTitle();
String editEmail= (String) editUserDetailsForm.getEmail();
Integer editTelephone = (Integer) editUserDetailsForm.getTelephone();
String editUserName = (String) editUserDetailsForm.getUserName();
String editPassword= (String) editUserDetailsForm.getPassword();
daoImpl.registerUser(editUid, editName, editTitle, editEmail, editTelephone, editUserName, editPassword);
System.out.println("sent to model components");
System.out.println("-forwarding to edituserdetail.jsp-");
return mapping.findForward("editUserDetails");
}
catch (Exception e) {
System.out.println("@@@ Exception in EditUserDetailsAction class--@@@@");
throw new DaoException("Error adding userDetails: ",e);
}
}
return mapping.findForward("addUserDetails");
}
}
Here is the jsp
<html:html locale="true">
<head>
<html:base />
<title>editUserDetails.jsp</title>
<script type="text/javascript">
function save_display(){
var x = confirm("Save: Are you sure ?")
if( x == true ){
confirm("Save: OK")
}
else{
text("Save: Cancelled")
}
}
function delete_display(){
var y = confirm("Delete: Are you sure ?")
if( y == true ){
confirm("Delete: OK")
}
else{
alert("Delete: Cancelled")
}
}
function funSave(){
document.form[0].ID.value = id;
form[0].ID.value.action="<%=request.getContextPath()%>/division/editDesignation.app?save=save";
form[0].ID.value.method="post";
form[0].ID.value.submit();
}
function funDelete(){
function funSave(){
document.form[0].ID.value=id;
form[0].ID.value.action="<%=request.getContextPath()%>.app?save=save";
form[0].ID.value.method="post";
form[0].ID.value.submit();
}}
</script>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<html:javascript formName="editUserDetailsForm"/>
<html:form action="/editUserDetails" onsubmit="return validateEditUserDetailsForm(this);">
user_Id : <html:text property="user_Id"/><html:errors property="user_Id"/><br/>
name : <html:text property="name"/><html:errors property="name"/><br/>
title : <html:text property="title"/><html:errors property="title"/><br/>
telephone : <html:text property="telephone"/><html:errors property="telephone"/><br/>
email : <html:text property="email"/><html:errors property="email"/><br/>
userName : <html:text property="userName"/><html:errors property="userName"/><br/>
password : <html:password property="password"/><html:errors property="password"/><br/>
<html:submit property="save" value="Save" onclick ="funSave()"/>
<html:cancel property="delete" value="delete" onclick="funDelete()"/>
</html:form>
</body>
pls let me know how to set the hidden variables within the above jsp .
and in Action class how to call it.
I would be very thankful to u guys.
Thanks
[/nobr]