aspose file tools*
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
Author

Struts 2 validation not woking properly

Jibin Najeeb
Greenhorn

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
</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
 
wood burning stoves
 
subject: Struts 2 validation not woking properly