Results 1 to 3 of 3

Thread: No client-side validation for String fields with max > 30 chars

  1. #1
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    667

    Question No client-side validation for String fields with max > 30 chars

    An entity with this field (or any length of 30 or less):

    Code:
    @NotNull
    @Size(max = 30)
    private String name;
    Will have this text field in its create/update view:

    Code:
    <form:input cssStyle="width:250px" id="_name_id" maxlength="30" path="name" size="0"/>
    <br/>
    <form:errors cssClass="errors" id="_name_error_id" path="name"/>
    <spring:message arguments="Name" code="field.invalid" var="field_invalid"/>
    <spring:message code="field.required" var="field_required"/>
    <spring:message argumentSeparator="," arguments="Name,(${field_required})" code="field.simple.validation" var="field_validation"/>
    <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : '_name_id', widgetType : 'dijit.form.ValidationTextBox', widgetAttrs : {promptMessage: '${field_validation}', invalidMessage: '${field_invalid}', required : true}})); </script>
    Whereas if the field's max is over 30, you get a text area instead:

    Code:
    <form:textarea cssStyle="width:250px" id="_name_id" path="name"/>
    <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : '_name_id', widgetType: 'dijit.form.SimpleTextarea', widgetAttrs: {}})); </script>
    <br/>
    <form:errors cssClass="errors" id="_name_error_id" path="name"/>
    The difference to the user is that in the second case, there's no client-side validation, i.e. the field doesn't get the nice decorators when it loses focus and is still empty.

    Can anything be done about this lack of validation, preferably by enhancing Roo or even via a manual change to the view?
    Last edited by Andrew Swan; Jan 28th, 2010 at 10:54 PM. Reason: Forgot the first set of CODE tags, oops
    Andrew Swan
    "Now is the EJB of our discontent made glorious Spring"

  2. #2
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    We are aware of this issue and it is documented in ROO-440. The problem is that Dojo's Textarea does not recognize the required flag and it is also not possible to decorate it with a validator. So there is currently not too much we can do. We hope to change this soon.
    Stefan Schmidt
    Software Engineer, Spring Roo
    SpringSource - a division of VMware
    twitter @schmidtstefan

  3. #3
    Join Date
    Dec 2007
    Posts
    21

    Default

    Try Forms4j (www.forms4j.com) -- it will handle your error messages, maxlength and mandatory conditions for both client and server side.

    Code:
    <forms4j:input id="foo" maxlength="30" mandatory="true" />

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •