2014-12-05 6 views
1

ajax jquery 유효성 검사를 사용하고 있습니다. 내 struts.xml에서모든 양식 데이터에 대해 AJAX 유효성 검사가 실패합니다.

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

, 나는이 JSP 페이지에서

<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> 

는 내가 가지고 :

<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> 

내가 주석 검증 등을 가진 모델 클래스 채널을 :

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 페이지 에 두 개의 양식이 있음을 의미합니다.

  • struts.xml에서 인터셉터를 제거하면 양식이 두 번 제출됩니다.

    날이 권리를 얻을 도와주세요 : 여기

는 제출 후 스크린 샷입니다.

답변

2

하나 하나에 이렇게 많은 질문

enter image description here ... BTW, 여기에 우리가 간다 :

1. 내가 올바른 데이터 양식을 제출하더라도, 내 양식이 오류가 표시됩니다 메시지.

이 인터셉터 스택 당신에 의한 것은 사용 : 당신이 볼 수 있듯이

<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> 

및 basicStack으로 정의된다

<interceptor-ref name="jsonValidationWorkflowStack"/> 

<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> 

입니다 , 아니 ModelDriven Interceptor입니다 여기에 참여했다. 당신이 ModelDriven을 계속 사용하려는 경우, 당신이 필요합니다, 당신은되지 않습니다 보내는 다른 매개 변수를

  • ModelDriven Interceptor를 추가하고,
  • 이는 Validation Interceptor 전에 실행 확인 (아직) 모델에 설정할 때 확인이 수행됩니다. Read this answer 정확히 무슨 뜻인지 이해해야합니다.

이 충분해야한다 : 오류 메시지와 함께

<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.

는 반환 입력 결과는 결과 DIV에 표시됩니다. 즉, 제출 버튼을 클릭 한 후 jsp 페이지에 두 개의 양식이 있음을 의미합니다.이 분명하다

, 설계가처럼, 어떻게 INPUT의 경우 자동적으로 변경하도록되어? 디자인을 재고해야합니다. 예를 들어, 당신이있는 형태로, 같은 타겟팅 할 수 있습니다 : INPUTSUCCESS의 경우 다음

<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> 

모두, 당신은 메시지 형식과 다시 채워 필드를 반환합니다. DRY를 따르려면 <s:include/>으로 원본 페이지에도 사용되는 JSP 스 니펫을 만드는 것이 좋습니다.

+0

예. 고마워요. 로트 ... 일 했어요 !! 나는 모델 인 가로수 요격기를 포함시켰다. – Madeyedexter