The OP isn't really using the built-in intrange validator, but doing it 
manually (for some reason).

The problem, however, lies in the OP's configuration fragment:

<action name="EmployeeCard" 
        class="com.tsystems.tintra4.actions.EmployeeCard">
  <interceptor-ref name="i18n" />
  <interceptor-ref name="roles">
    WTT_CARDS_EDITOR
  </interceptor-ref>
  <interceptor-ref name="workflow"/>
  <result type="tiles" name="SUCCESS">def_page_employee_card</result>
  <result type="tiles" name="input">def_page_employee_card</result>
</action>

As soon as you start defining an action's interceptors you are defining *all* 
the action's interceptors. 

In other words, this action will *only* be using the "i18n", "roles", and 
"workflow" interceptors. This bypasses the default stack, which includes the 
"validation" interceptor--the interceptor that calls an action's validate() 
method.

In order to call the validate() method we must include the "validation" 
interceptor or stack that includes it.

I'm also not sure if result names are case-sensitive, but if they are, the 
above result named "SUCCESS" will not be found by an action returning "success" 
or ActionSupport.SUCCESS. As to why the OP is bypassing the bundled int range 
validator, not sure, but unless there's a good reason for it, I wouldn't bother 
re-writing existing functionality.

Dave

--- On Wed, 9/10/08, Priyanka.dandekar wrote:
> If Integer Range Validator does not work for you then you
> shoud consider regular expression validation for same, its 
> can be done by restricting number of digits and allowing 
> only numeric characters.
> 
> Here is an example of similar problem 
> http://struts-2-developers.blogspot.com/2008/08/struts-2-integer-validation-example.html
> Struts 2 Integer Validation  
> 
> 
> fil78 wrote:
> > 
> > Hello everybody,
> > 
> >  
> > 
> > I need to validate only 1 field on the jsp. It value
> should be between 1
> > and 999999. Initially I started to implement through
> int validation but it
> > seemed to go wrong - it works with some limitation -
> maximum value should
> > not exceed 1000 or something like that. I am trying to
> implement
> > validation through overriding validate() method. I use
> tiles together with
> > Struts 2.0.11. I could not tune it to work correctly.
> Could someone help,
> > please?
> > 
> >  
> > 
> > Here are my snippets:
> > 
> >  
> > 
> >  
> > 
> > Struts.xml:
> > 
> >  
> > 
> >             <action
> name="EmployeeCard"
> > 
> >                  
> class="com.tsystems.tintra4.actions.EmployeeCard">
> > 
> >                   <interceptor-ref
> name="i18n" />
> > 
> >                   <interceptor-ref
> name="roles">
> > 
> >                        
> WTT_CARDS_EDITOR
> > 
> >                  
> </interceptor-ref>
> > 
> >                   <!--
> interceptor-ref name="workflow"/-->
> > 
> >                   <interceptor-ref
> name="workflow"/>
> > 
> >                   <result
> type="tiles"
> >
> name="SUCCESS">def_page_employee_card</result>
> > 
> >                   <result
> type="tiles" name="input">
> > 
> >                        
> def_page_employee_card
> > 
> >                   </result>
> > 
> >             </action>
> > 
> >  
> > 
> >  
> > 
> > Jsp:
> > 
> >  
> > 
> > <%@ page language="java"
> contentType="text/html; charset=UTF-8"
> > 
> >     pageEncoding="UTF-8"%>
> > 
> > <%@ taglib prefix="s"
> uri="/struts-tags" %>
> > 
> >  
> > 
> > <!--Reference to the Employee profile-->
> > 
> >  
> > 
> > <div>
> > 
> > <s:url id="url_fio"
> action="GetEmployee"
> includeParams="none">
> > 
> >       <s:param
> name="employeeId"><s:property
> value="%{EmpNo}"/></s:param>
> > 
> > </s:url>
> > 
> > <s:a href="%{url_fio}">
> > 
> >       <s:property
> value="%{fio}"/>
> > 
> > </s:a>
> > 
> > </div>
> > 
> > <br/>
> > 
> >  
> > 
> > <!--Adding new card-->
> > 
> >  
> > 
> > <s:if test="addCard == true">
> > 
> > <s:text
> name="card_adding_proccess"></s:text>
> > 
> > <s:fielderror/>
> > 
> > <s:form method="GET"
> validate="true">
> > 
> >       <s:textfield name="cardNo"
> >
> label="%{getText('card_add_edit_field')}"></s:textfield>
> > 
> >       <s:textfield name="EmpNo"
> value="%{EmpNo}"></s:textfield>
> > 
> >       <s:hidden name="editCard"
> value="%{true}"></s:hidden>
> > 
> >       <s:hidden name="addCardFinal"
> value="%{true}"></s:hidden>
> > 
> >       <s:submit
> value="%{getText('button_submit')}"/>
> > 
> > </s:form>
> > 
> > </s:if>
> > 
> >  
> > 
> > <!--Editing new card-->
> > 
> >  
> > 
> > <s:if test="editCard == true">
> > 
> > <s:text
> name="card_editing_proccess"></s:text>
> > 
> > <s:fielderror/>
> > 
> > <s:form method="GET"
> validate="true">
> > 
> >       <s:textfield name="cardNo"
> >
> label="%{getText('card_add_edit_field')}"></s:textfield>
> > 
> >       <s:hidden name="EmpNo"
> value="%{EmpNo}"></s:hidden>
> > 
> >       <s:hidden name="editCard"
> value="%{true}"></s:hidden>
> > 
> >       <s:hidden name="editCardFinal"
> value="%{true}"></s:hidden>
> > 
> >       <s:submit
> value="%{getText('button_submit')}"/>
> > 
> > </s:form>
> > 
> > </s:if>
> > 
> >  
> > 
> > JAVA Action:
> > 
> >  
> > 
> > public void validate() {
> > 
> >             request =
> ServletActionContext.getRequest();
> > 
> >             String tmp = "";
> > 
> >             try {
> > 
> >                   tmp =
> request.getParameter("cardNo");
> > 
> >                   Integer i =
> this.getCardNo();
> > 
> >                   if (tmp != null
> && tmp.length() > 0) {
> > 
> >                         int
> tmpInt = Integer.parseInt(tmp);
> > 
> >                        
> this.setCardNo(tmpInt);
> > 
> >                        
> System.out.println("Card no (validation) = " +
> > cardNo);
> > 
> >                         if
> (cardNo < 1 || cardNo > 999999) {
> > 
> >  
> > 
> >
>                             
> addFieldError("cardNo", "Must be int");
> > 
> >
>                              
> > 
> >
>                              
> > 
> >
>                             
> System.out.println("INPUT...");
> > 
> >                         }
> > 
> >                   }
> > 
> >             } catch (Exception e) {
> > 
> >  
> > 
> >                  
> e.printStackTrace();
> > 
> >             }
> > 
> >  
> > 
> >       }
> > 
> >  
> > 
> > Thanx a lot.
> > 
> >  
> > 
> > Best regards, Filippov Andrey
> > 
> > 
> > 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Custom-validation-with-Struts2-tp16115973p19425117.html
> Sent from the Struts - User mailing list archive at
> Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to