• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Struts 2 validation not woking properly

 
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
 
Politics is a circus designed to distract you from what is really going on. So is this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic