File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts 2 validation not woking properly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 validation not woking properly" Watch "Struts 2 validation not woking properly" New topic

Struts 2 validation not woking properly

Jibin Najeeb

Joined: Nov 27, 2012
Posts: 6
The file contains so many fields. Im only showing some of them
<s:form action="buildCompany" method="post" enctype="multipart/form-data" theme="simple">
<s:textfield name="companyName" />// I only applied validation for this field only.
<s:file cssClass="input-file" label="" name="myFile" size="19" cssStyle="opacity: 0;" />
<button class="btn btn-inverse"><i class="white-icons download_to_computer"></i>Save</button>//<s:submit>also tried

My Action Class is this

public class CreateCompany extends ActionSupport {
String companyName;
public String getCompanyName() {
return companyName;
public void setCompanyName(String companyName) {
this.companyName = companyName;
public String execute() throws Exception {
System.out.println("from execute"+companyName);
return SUCCESS;
public void validate() {
if ((companyName == null) || companyName.length() == 0) {
this.addFieldError("companyName", "BLank");

my struts.xml

<package name="my-default" extends="struts-default">
<action name="buildCompany" class="">
<result name="success" type="redirect-action">redirection</result>
<result name="error" type="redirect-action">error</result>
<result name="input">Test.jsp</result>
<action name="redirection" class="">
<result name="success">success.jsp</result>
<result name="input">Test.jsp</result>

The problem is the validation some times shows error even when it is not empty. Some times work properly. The causing is randomly. Why is this
Is there any issue between enctype and struts 2 validation
I agree. Here's the link:
subject: Struts 2 validation not woking properly
It's not a secret anymore!