facebook

Problem in Struts Validator

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #262235 Reply

    I got the problems in validator.

    Here the script in struts-config.xml:
    <form-bean name=”beverageCreationForm” type=”com.deth.struts.form.BeverageCreationForm” >
    <form-property name=”method” type=”java.lang.String”/>
    </form-bean>

    <action
    attribute=”beverageCreationForm”
    input=”/tiles/beverageCreation-tiles.jsp”
    name=”beverageCreationForm”
    path=”/beverageCreation”
    roles=”Admin,Manager”
    scope=”request”
    validate=”true”
    parameter=”method”
    type=”com.deth.struts.action.BeverageCreationDispatchAction”>
    <forward name=”saved” path=”/beverageCreationSuccess.do” redirect=”true” contextRelative=”true”/>
    <forward name=”previewed” path=”/tiles/beverage-creation-preview-tiles.jsp”/>
    </action>

    And in validator.xml:
    <form name=”beverageCreationForm”>
    <field
    property=”name”
    depends=”required”>
    <arg key=”prompt.name”/>
    </field>
    <field
    property=”price”
    depends=”required,mask,minlength,maxlength”>
    <arg0 key=”prompt.price”/>
    <arg1 key=”${var:minlength}” name=”minlength” resource=”false”/>
    <arg1 key=”${var:maxlength}” name=”maxlength” resource=”false”/>
    <var>
    <var-name>mask</var-name>
    <var-value>^[0-9]*$</var-value>
    </var>
    <var>
    <var-name>minlength</var-name>
    <var-value>1</var-value>
    </var>
    <var>
    <var-name>maxlength</var-name>
    <var-value>7</var-value>
    </var>
    </field>
    </form>

    The code in jsp as following below:

    <html:form action=”/beverageCreation” focus=”name” enctype=”multipart/form-data” method=”post” onsubmit=”validateBeverageCreationForm(this);”>
    <input type=”hidden” name=”method”>
    <script>
    function setUrl(target) {
    document.forms[0].method.value=target;
    }
    </script>
    <table width=”100%” align=”center”>
    <tr>
    <td>Kind of Beverage:</td>
    <td>
    <html:select property=”parentBeverageId”>
    <html:option value=”1″>WINE</html:option>
    <html:option value=”2″>BEER</html:option>
    </html:select>
    </td>
    </tr>
    <tr>
    <td>* Name:</td>
    <td>
    <html:text property=”name” size=”50″ maxlength=”50″/>
    </td>
    </tr>
    <tr>
    <td>Picture:</td>
    <td>
    <html:file size=”50″ maxlength=”50″ property=”theFile”/>
    </td>
    </tr>
    <tr>
    <td>* Price:</td>
    <td>
    <html:text property=”price” size=”32″ maxlength=”50″/>
    </td>
    </tr>
    <tr>
    <td>Unit:</td>
    <td>
    <html:select property=”unitId”>
    <html:option value=”4″>Bottle</html:option>
    <html:option value=”5″>Can</html:option>
    </html:select>
    </td>
    </tr>
    <tr>
    <td></td>
    <td>
    <html:submit value=”Preview” onclick=”setUrl(‘preview’);”/>
    <html:submit value=”Save” onclick=”setUrl(‘save’);”/><html:reset/>
    </td>
    </tr>
    <tr>
    <td>Note: * indicates required field.</td>
    </tr>
    </table>
    <html:javascript staticJavascript=”true” dynamicJavascript=”true” formName=”beverageCreationForm”/>
    </html:form>

    When on submit the form, JavaScript works fine. But it makes forward to the target page, instead of the input. Here is the errors:
    javax.servlet.ServletException: For input string: “”
    org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    deth.i18n.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:111)
    org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)

    root cause

    java.lang.NumberFormatException: For input string: “”
    java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)

    I compared the last my project, there was no this problem. Please help. Thanks.
    Best regards, Khoa.

    #262387 Reply

    Riyad Kalla
    Member

    Moving to OT > Soft Dev

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Problem in Struts Validator

You must be logged in to post in the forum log in