When I try to submit data on a jsp with post method to a method in an action class should be called. But it gives an error like this..
ERROR [DispatchAction] Action[/pages/jsp/smsserver/submitData] does not contain method named updateData
java.lang.NoSuchMethodException: com.orgtech.orgtice.smsservice.struts.action.SendReportAction.updateData(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
Here I add the necessary parts of jsp, struts config.xml, ActionForm class and Action class.
this is the showDetails.jsp..It shows the details to the user and also uer have the ability to edit it and submit again. So I want to get the changed details and updat ethem again to the database.
<head>
<html:base />
<title>showDetails.jsp</title>
<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">
</head>
<body>
<p> Message Details</p>
<table width="75%" border="0" id="showdatatable">
<logic:iterate name="showDetailsForm" property="allProducts" id="SingleItem">
<form method="post" action="submitData.do?next=updateData">
<tr>
<td>Id</td>
<td width="3%"><bean:write name="SingleItem" property="id"/></td>
</tr>
<tr>
<td>Modified Time</td>
<td><bean:write name="SingleItem" property="modifiedTime"/></td>
</tr>
<tr>
<td>Module</td>
<td>
<select name="smodule">
<%
if(request.getAttribute("moduleType").equals("GEN")){
%>
<option>TEST</option>
<option selected>GEN</option>
<%
}
%>
</select>
</td>
</tr>
<tr>
<td>Repeats</td>
<td>
<input type="text" name="srepeats" value="<bean:write name="SingleItem" property="repeats"/>" >
</td>
</tr>
<tr>
<td>Mobile No</td>
<td>
<input type="text" name="smobileNo" value="<bean:write name="SingleItem" property="mobileNo"/>">
</td>
</tr>
<tr>
<td>Message</td>
<td>
<textarea name="smessage"><bean:write name="SingleItem" property="message"/></textarea>
</td>
</tr>
<tr>
<td>Status</td>
<td> <select name="sstatus">
<%
if(request.getAttribute("statusType").toString().equals("Failed")){
%>
<option value="1">Success</option>
<option value="2" selected>Failed</option>
<option value="3">Pending</option>
<option value="4">Queued</option>
<%}
else
if(request.getAttribute("statusType").toString().equals("Success")){
%>
<option value="1" selected>Success</option>
<option value="2">Failed</option>
<option value="3">Pending</option>
<option value="4">Queued</option>
<%
}else
if(request.getAttribute("statusType").toString().equals("Pending")){
%>
<option value="1">Success</option>
<option value="2">Failed</option>
<option value="3" selected>Pending</option>
<option value="4">Queued</option>
<%
}else
if(request.getAttribute("statusType").toString().equals("Queued")){
%>
<option value="1">Success</option>
<option value="2">Failed</option>
<option value="3">Pending</option>
<option value="4" selected>Queued</option>
<%
}else{
%>
<OPTION><%=request.getAttribute("statusType").toString()%></OPTION>
<%
}
%>
</select>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="54"> </td>
<td><table width="92%" border="0">
<tr>
<td width="41%" height="27">
<input name="Reset" type="reset" value="Cancel">
</td>
<td width="59%">
<input type="submit" name="Submit2" value="Submit">
</td>
</tr>
</logic:iterate>
</table>
</td>
</tr>
</table>
<p> </p>
<p> </p>
</body>
-----------------------------------------------------------
In side config.xml how I mapped the post action with the method..
<action
name="showDetailsForm"
path="/pages/jsp/smsserver/submitData"
attribute="showDetailsForm"
scope="request"
type="com.orgtech.orgtice.smsservice.struts.action.SendReportAction"
parameter="next"
>
<forward
name="updateSuccess"
path="system.configuration.updateSuccess"
/>
</action>
---------------------------------------------------------
This is the ActionForm associate with the ActionClass and .jsp.It is needed when requesting the data to the jsp.And I used it inside the updateData method to update data in the database.But I didnt show that part here. I just need to call updateData method when I click submit button..
package com.orgtech.orgtice.smsservice.struts.form;
import java.util.List;
import java.util.Collection;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import com.irononetech.ironvoice.smsservice.view.SendSMSView;
/**
* MyEclipse Struts
* Creation date: 01-18-2007
*
* XDoclet definition:
* @struts.form name="showDetailsForm"
*/
public class ShowDetailsForm extends ActionForm {
// --------------------------------------------------------- Instance Variables
private Collection allProducts = null;
private SendSMSView sendSMSView = new SendSMSView();
// private String status;
// --------------------------------------------------------- Methods
/**
* @return Returns the status.
*/
public String getStatus() {
//return status;
return sendSMSView.getStatus().toString();
}
/**
* @param status The status to set.
*/
public void setStatus(Integer status) {
//this.status = status;
sendSMSView.setStatus(status);
}
public void setStatusType(int statusType){
if(statusType == 1){
setStatus(new Integer(1));
}
else if(statusType == 2){
setStatus(new Integer(2));
}
else if(statusType == 3){
setStatus(new Integer(3));
}
else if(statusType == 4){
setStatus(new Integer(4));
}
}
public String getStatusType(){
String status = "";
if((getStatus()!=null)&&(getStatus().equals("Success"))){
status = "Success";
}
else if((getStatus()!=null)&&(getStatus().equals("Failed"))){
status = "Failed";
}
else if((getStatus()!=null)&&(getStatus().equals("Pending"))){
status = "Pending";
}
else if((getStatus()!=null)&&(getStatus().equals("Queued"))){
status = "Queued";
}
else {
status = "testing";
}
return status;
}
public String getModule(){
return sendSMSView.getModule();
}
public void setModule(String module){
sendSMSView.setModule(module);
}
public String getModuleType(){
String moduleType = "";
if((getModule()!=null)&&(getModule().equals("GEN"))){
moduleType = "GEN";
}
return moduleType;
}
public void setModuleType(String moduleType){
if(moduleType.equals("GEN")){
setModule(new String("GEN"));
}
}
/**
* @return Returns the allProducts.
*/
public Collection getAllProducts() {
return allProducts;
}
/**
* @param allProducts The allProducts to set.
*/
public void setAllProducts(Collection allProducts) {
this.allProducts = allProducts;
}
/**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
}
/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
sendSMSView = new SendSMSView();
// TODO Auto-generated method stub
}
/**
* @return Returns the sendSMSView.
*/
public SendSMSView getSendSMSView() {
return sendSMSView;
}
/**
* @param sendSMSView The sendSMSView to set.
*/
public void setSendSMSView(SendSMSView sendSMSView) {
this.sendSMSView = sendSMSView;
}
}
--------------------------------------------------
This is the SendReportAction class.......................
public class SendReportAction extends DispatchAction{
/**
* Method updateData
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward updateData(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse respons) {
ShowDetailsForm showDetailsForm = new ShowDetailsForm();
// TODO Auto-generated method stub
try{
String messageChange = request.getParameter("smessage");
String moduleChange = request.getParameter("smodule");
int repeatsChange = Integer.parseInt(request.getParameter("srepeats"));
int statusChange = Integer.parseInt(request.getParameter("sstatus"));
}catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward("updateSuccess");
}
}
----------------------------------------------------
I know how to get data and update the details to the database..I just want to know why I got an error like cannot find updateData method inside action class and to see whet the mistake I have done..Please help me with this matter..Thank you..