【发布时间】:2014-12-05 21:27:26
【问题描述】:
我正在使用 ajax jquery 验证。
https://code.google.com/p/struts2-jquery/wiki/Validation
在我的 struts.xml 中,我有
<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>
在 JSP 页面中我有:
<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>
我有带有注释验证的模型类 Channel:
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 be between ${minInclusive} and ${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 be between ${minInclusive} and ${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 be between ${minExclusive} and ${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;
}
}
我的动作类实现了模型驱动接口。我的问题是:
即使我提交了正确数据的表单,我的表单也会显示错误 消息。
连同错误消息,返回的输入结果是 显示在结果 div 中。这意味着我在 jsp 页面上有两个表单 点击提交按钮后。
如果我删除 jsonValidationWorkflowStack struts.xml 中的拦截器 我的表单被提交了两次。
这是提交后的截图:
请帮我解决这个问题。
【问题讨论】:
标签: ajax jsp struts2 struts2-jquery struts-validation