2013-03-14 1 views
0

저는 XML을 사용하여 Struts2 유효성 검사를 사용하여 고객이 입력 한 다양한 필드를 검사하려고합니다. 내 struts.xmlstruts-default으로 확장되며 매우 간단한 동작 클래스 TestActionActionSupport으로 확장되었지만 작동하지 않습니다.Struts2 XML을 사용하는 유효성 검사가 작동하지 않습니까?

내가 부족한 것을 누군가도 볼 수 있다면 매우 감사하게 생각합니다. 여기

내가 가진 무엇 :

CustomerAction-validation.xml

<?xml version="1.0" encoding="UTF-8"?> 

    <!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.2//EN" "http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd"> 
<validators> 
    <field name="customerName"> 
     <field-validator type="requiredstring"> 
      <message>Required</message> 
     </field-validator> 
    </field> 
</validators> 

struts.xml 여기

<action name="addCustomer" class="com.yell.hibu.action.CustomerAction" 
      method="execute"> 
      <interceptor-ref name="validation"/> 
      <param name="excludeMethods"> 
        input,back,cancel,browse 
       </param> 
      <interceptor-ref name="fileUpload"> 
       <param name="maximumSize">2097152</param> 
       <param name="allowedTypes"> 
        image/png,image/gif,image/jpeg,image/pjpeg 
       </param> 
      </interceptor-ref> 
      <interceptor-ref name="defaultStack"></interceptor-ref> 
      <result name="success">/success.jsp</result> 
      <result name="input">/registration.jsp</result> 
     </action> 

난 단지 1 개 필드

에 대한 Registration.jsp이
<s:form action="addCustomer" id="register-form" method="post" validate="true" theme="xhtml" enctype="multipart/form-data"> 
<s:actionerror/> 
<s:fielderror/> 
<s:textfield name="customer.customerName" label="Customer Name:" cssClass="tooltip" title="Max 10 characters allowed." maxlength="10"/> 

+0

도움이 될 정보가 충분하지 않습니다. 유효성 검사 파일은 어디에 배포됩니까? 무슨 일이 생기지 않습니까? 작업에 적절한 getter/setter가 있습니까? –

+0

'TestAction' 클래스의 코드는 무엇입니까? –

+0

이 링크를 사용해보세요. 문제가 해결되기를 바랍니다. http://www.roseindia.net/struts/struts/struts2.2.1/ValidationInterceptor.html –

답변

1

귀하의

<interceptor-ref name="validation"/> 

다음

<param name="excludeMethods"> 
     input,back,cancel,browse 
</param> 

읽을되지 않습니다, 자기 폐쇄입니다. examples from the documentation 같이

Validation Interceptor

Params Interceptor를 실행해야합니다. 그것은 모든 값이 이미 동작에 설정되어있는 것으로 가정으로

다시 설명서에 따라

인터셉터 종종 스택에인가되는 마지막 (또는 마지막 수 초) 인터셉터 하나이다 .

그런 다음, 다음과 같이 수행하려고 :

<action name="addCustomer" class="com.yell.hibu.action.CustomerAction" 
     method="execute"> 

    <interceptor-ref name="defaultStack"></interceptor-ref> 

    <interceptor-ref name="validation"> 
     <param name="excludeMethods"> 
      input,back,cancel,browse 
     </param> 
    </interceptor-ref> 

    <interceptor-ref name="fileUpload"> 
     <param name="maximumSize">2097152</param> 
      <param name="allowedTypes"> 
       image/png,image/gif,image/jpeg,image/pjpeg 
      </param> 
    </interceptor-ref> 

    <result name="success">/success.jsp</result> 
    <result name="input">/registration.jsp</result> 
</action> 

를가, 일이 너무 귀하의 JSP와 액션을 게시하지 않습니다.

도움이 되길 바랍니다.

관련 문제