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"> <param name="allowedRoles">WTT_CARDS_EDITOR</param> </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