• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Action class not being called after validation

 
Manjunath Muniyappa
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am new to Struts2. I am tring to run a simple application which has one JSP and one java class. My jsp has few fields where user enters data. Once they click on submit, I need to validate them and return back if there is any missing data. I am using struts2 validation i.e classname-validation.xml. What is happening is that, even though I enter all the data in the JSP and click on submit, my application still shows that data fileds are required!!!Also after clicking on submit button, my action class is not getting called. I am posting my code here below. Please help me!!!

Action class

package com.wa;
import com.opensymphony.xwork2.ActionSupport;

public class RefundsLessThanThreeThousand extends ActionSupport {

private static final long serialVersionUID = 1L;
private String AccountNumber;
private String ValueofSignOff;
private String CustomerName;
private String Address;
private String PeriodofSignOff;
private String DetailedReason;

public String getsAccountNumber() {
System.out.println("____________________________ AccountNumber "+AccountNumber);
return AccountNumber;
}
public void setsAccountNumber(String AccountNumber) {
this.AccountNumber = AccountNumber;
System.out.println("____________________________ AccountNumber "+AccountNumber);
}
public String getsValueofSignOff() {
return ValueofSignOff;

}
public void setsValueofSignOff(String ValueofSignOff) {
this.ValueofSignOff = ValueofSignOff;
System.out.println("____________________________ ValueofSignOff "+ValueofSignOff);
}
public String getsCustomerName() {
return CustomerName;
}
public void setsCustomerName(String CustomerName) {
this.CustomerName = CustomerName;
System.out.println("____________________________ CustomerName "+CustomerName);
}
public String getsAddress() {
return Address;
}
public void setsAddress(String Address) {
this.Address = Address;
System.out.println("____________________________ Address "+Address);
}
public String getsPeriodofSignOff() {
return PeriodofSignOff;
}
public void setsPeriodofSignOff(String PeriodofSignOff) {
this.PeriodofSignOff = PeriodofSignOff;
System.out.println("____________________________ PeriodofSignOff "+PeriodofSignOff);
}
public String getsDetailedReason() {
return DetailedReason;
}
public void setsDetailedReason(String DetailedReason) {
this.DetailedReason = DetailedReason;
System.out.println("____________________________ DetailedReason "+DetailedReason);
}


public String createcase(){
System.out.println("____________________________ entered the jaa class");
return "sucess";
}

public String execute(){
System.out.println("____________________________ entered the jaa class exe");
return "sucess";
}

}


JSP

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat" %>
<html>
<head>
<title>RefundsLessThanThreeThousand</title>

</head>
<body>

<s:form action="RefundsLessThanThreeThousand.action" method="post" name="RefundsLessThanThreeThousand" >
<s:textfield name="AccountNumber" key="label.AccountNumber" size="30" />
<s:textfield name="ValueofSignOff" key="label.ValueofSignOff" size="30"/>
<s:textfield name="CustomerName" key="label.CustomerName" size="50" />
<s:textarea name="Address" key="label.Address" rows="8" cols="30"/>
<s:textfield name="PeriodofSignOff" key="label.PeriodofSignOff" size="30"/>
<s:textarea name="DetailedReason" key="label.DetailedReason" rows="8" cols="30"/>
<s:submit method="execute" key="label.Submit" align="center" />
<s:reset key="label.clear" align="center" ></s:reset>
</s:form>
</body>
</html>

struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<constant name="struts.enable.DynamicMethodInvocation"
value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources"
value="ApplicationResources" />

<package name="default" extends="struts-default" namespace="/">
<action name="LoginAction"
class="com.wa.LoginAction">
<result name="success">/pages/Welcome/Welcome.jsp</result>
<result name="error">/pages/login/Login.jsp</result>
</action>
<action name="RefundsLessThanThreeThousand"
class="com.wa.RefundsLessThanThreeThousand">
<result name="sucess">/pages/login/Login.jsp</result>
<result name="input">/pages/RefundsLessThanThreeThousand/RefundsLessThanThreeThousand.jsp</result>
<result ></result>
</action>
</package>

</struts>

RefundsLessThanThreeThousand-validation.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">

<validators>
<field name="AccountNumber">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message key="errors.required" />
</field-validator>
</field>
<field name="ValueofSignOff">
<field-validator type="required">
<message key="errors.required" />
</field-validator>
<field-validator type="int">
<param name="min">350</param>
<param name="max">3000</param>
<message key="errors.range"/>
</field-validator>
</field>
<field name="CustomerName">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message key="errors.required" />
</field-validator>
</field>
<field name="Address">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message key="errors.required" />
</field-validator>
</field>
<field name="PeriodofSignOff">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message key="errors.required" />
</field-validator>
</field>
<field name="DetailedReason">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message key="errors.required" />
</field-validator>
</field>

</validators>
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.

Also, when posting code samples, it's best to limit them to the minimum necessary to replicate the problem; things like System.out.println just obfuscate the actual issues.

And welcome to JavaRanch!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic