• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts 2 validation not woking properly

 
Jibin Najeeb
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
</s:form>

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;
}
@Override
public String execute() throws Exception {
System.out.println("from execute"+companyName);
return SUCCESS;
}
@Override
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="com.mt.erp.CreateCompany">
<result name="success" type="redirect-action">redirection</result>
<result name="error" type="redirect-action">error</result>
<result name="input">Test.jsp</result>
</action>
<action name="redirection" class="com.mt.erp.Redirection">
<result name="success">success.jsp</result>
<result name="input">Test.jsp</result>
</action>

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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic