jsp - AJAX validation fails for all form data -


i using ajax jquery validation.

https://code.google.com/p/struts2-jquery/wiki/validation

in struts.xml, have

<action name="createchannel" class="channel.channelaction" method="createchannel"> <interceptor-ref name="jsonvalidationworkflowstack"/> <result  name="success">createsuccess.jsp</result> <result  name="input">createchannel.jsp</result> </action> 

in jsp page have:

<s:form method="get" action="createchannel" > <s:textfield name="channelname" label="channel name" /> <s:textfield name="channelband" label="channel band"/> <s:textfield name="vcfrequency" label="video carrier frequency"/> <s:textfield name="acfrequency" label="audio carrier frequency"/> <s:select name="chargetype" label="charge type" list="{'prepaid','postpaid'}"/> <s:select name="transmissiontype" label="transmission type" list="{'hd','standard'}"/> <s:textfield name="channelcharge" label="channel charge"/> <sj:submit value="submit" button="true" validate="true" targets="result"  /> </s:form> <div id="result">result:</div> 

i have model class channel annotation validations as:

public class channel {     private int channelid;     private string channelname;     private string channelband;     private double vcfrequency;     private double acfrequency;     private string chargetype; //prepaid or postpaid     private string transmissiontype; //hd or standard     private double channelcharge;      private set<channelpackage> channelpackage;      public channel(){         channelpackage=new hashset<>();     }      public int getchannelid() {         return channelid;     }      public void setchannelid(int channelid) {         this.channelid = channelid;     }      @requiredstringvalidator(trim=true,type=validatortype.field,message="please enter valid channel name")     public string getchannelname() {         return channelname;     }      public void setchannelname(string channelname) {         this.channelname = channelname;     }     @requiredstringvalidator(trim=true,type=validatortype.field,message="please enter valid channel band")     public string getchannelband() {         return channelband;     }      public void setchannelband(string channelband) {         this.channelband = channelband;     }     @doublerangefieldvalidator(type = validatortype.simple,fieldname = "vcfrequency",mininclusive = "40",maxinclusive = "225",message = "the scale must between ${mininclusive} , ${maxinclusive} (exclusive)")     public double getvcfrequency() {         return vcfrequency;     }      public void setvcfrequency(double vcfrequency) {         this.vcfrequency = vcfrequency;     }     @doublerangefieldvalidator(type = validatortype.simple,fieldname = "acfrequency",mininclusive = "45",maxinclusive = "230",message = "the scale must between ${mininclusive} , ${maxinclusive} (exclusive)")     public double getacfrequency() {         return acfrequency;     }      public void setacfrequency(double acfrequency) {         this.acfrequency = acfrequency;     }      public string getchargetype() {         return chargetype;     }      public void setchargetype(string chargetype) {         this.chargetype = chargetype;     }       public string gettransmissiontype() {         return transmissiontype;     }      public void settransmissiontype(string transmissiontype) {         this.transmissiontype = transmissiontype;     }     @doublerangefieldvalidator(type = validatortype.simple,fieldname = "channelcharge",minexclusive = "20.5",maxexclusive = "78.5",message = "the scale must between ${minexclusive} , ${maxexclusive} (exclusive)")     public double getchannelcharge() {         return channelcharge;     }      public void setchannelcharge(double channelcharge) {         this.channelcharge = channelcharge;     }       public set<channelpackage> getchannelpackage() {         return channelpackage;     }      public void setchannelpackage(set<channelpackage> channelpackage) {         this.channelpackage = channelpackage;     }      public string tostring(){         return channelid+": "+channelname;     }  } 

my action class implements model driven interface. problem is:

  • even if submit form correct data, form shows error messages.

  • along error messages, input result returned shown in result div. means have 2 forms on jsp page after clicking submit button.

  • if remove jsonvalidationworkflowstack interceptors struts.xml form getting submitted twice.

here screenshot after submission:

please me right.

enter image description here

so many questions in single one... btw, here go:

1. if submit form correct data, form shows error messages.

this due interceptor stack using:

<interceptor-ref name="jsonvalidationworkflowstack"/> 

that defined as

<interceptor-stack name="jsonvalidationworkflowstack">     <interceptor-ref name="basicstack"/>     <interceptor-ref name="validation">         <param name="excludemethods">input,back,cancel</param>     </interceptor-ref>     <interceptor-ref name="jsonvalidation"/>     <interceptor-ref name="workflow"/> </interceptor-stack> 

and basicstack

<interceptor-stack name="basicstack">     <interceptor-ref name="exception"/>     <interceptor-ref name="servletconfig"/>     <interceptor-ref name="prepare"/>     <interceptor-ref name="checkbox"/>     <interceptor-ref name="params"/>     <interceptor-ref name="conversionerror"/> </interceptor-stack> 

as can see, no modeldriven interceptor involved here. if want keep using modeldriven, need to:

  • add modeldriven interceptor, ,
  • ensure runs before validation interceptor, otherwise parameters sending not (yet) set on model when validation performed. read answer understand mean.

this should enough:

<action name="createchannel" class="channel.channelaction" method="createchannel">     <interceptor-ref name="modeldriven"/>     <interceptor-ref name="jsonvalidationworkflowstack"/>     <result  name="success">createsuccess.jsp</result>     <result  name="input">createchannel.jsp</result> </action> 

2. along error messages, input result returned shown in result div. means have 2 forms on jsp page after clicking submit button.

this obvious, design that, how supposed change automagically in case of input ? need rethink design. example, can target form in, like:

<div id="result">     <s:form method="get" action="createchannel" >         <s:textfield name="channelname" label="channel name" />         <s:textfield name="channelband" label="channel band"/>         <s:textfield name="vcfrequency" label="video carrier frequency"/>         <s:textfield name="acfrequency" label="audio carrier frequency"/>         <s:select name="chargetype" label="charge type" list="{'prepaid','postpaid'}"/>         <s:select name="transmissiontype" label="transmission type" list="{'hd','standard'}"/>         <s:textfield name="channelcharge" label="channel charge"/>         <sj:submit value="submit" button="true" validate="true" targets="result"  />     </s:form> </div> 

then both in case of input , success, return message, form , fields repopulated. better create jsp snippet used in original page <s:include/>, follow dry.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -