Results 1 to 5 of 5

Thread: How to mark a form field as required???

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Location
    Paderborn, Germany
    Posts
    24

    Default How to mark a form field as required???

    Hi everyone,
    is there a way to mark a field in a HTML form as required?
    I know that there is a rejectIfEmpty method in the ValidationUtils class, but I'am searching for a way to include this validation rule directly into the JSP page.

    rejectIfEmpty is the only validation rule I need besides format checking. That's why i don't want to create an extra validation class just to check wether a form field is empty or not.

    Is there a JSP tag where you can mark a field as required? I think this is a common task in web applications, so such an tag would come in handy :-I

    Chris

  2. #2
    Join Date
    Sep 2004
    Posts
    5

    Default

    HTML does no provied such functionality, although you can use JavaScript instead. Yes, tag is a good idea, let me know when you write some or you can try using "Struts layout" tag library (after some modifications).

  3. #3
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    We use Field.jsp, Date.jsp, Checkbox.jsp, etc that we've created for controls, and publish data from the referenceData() method in the controller that can be picked up by these JSP pages to indicate they're required (*).

    Seems to work well and is all driven off the various Spring bean definitions, i.e. off some extra beans/properties we've defined.

    So when you flag that a field is required it appears required (*) as well as actually being validated as required.

    If you've got a single page you can use the built-in 'required' property in one of the Spring controllers or sort of build your own if you're using AbstractWizardFormController.

  4. #4
    Join Date
    Aug 2004
    Location
    Denver
    Posts
    249

    Default If you're using Commons Validator...

    If you're using Commons Validator, I've built a LabelTag as part of AppFuse that will mark a field as required if it's specified as required in validation.xml.

    View Demo

    View JSP Source

    HTH,

    Matt

  5. #5
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    we use a combination of the "required" functionality built into Spring, property editors, and Spring Validator implementations to handle required fields, data type validation, and data validation respectively.

Similar Threads

  1. Replies: 3
    Last Post: Jun 8th, 2010, 03:27 AM
  2. Replies: 4
    Last Post: Jun 13th, 2006, 05:21 PM
  3. Not updating a form field on setFormObject()?
    By SCWells72 in forum Swing
    Replies: 13
    Last Post: Aug 28th, 2005, 12:43 PM
  4. Replies: 1
    Last Post: Mar 23rd, 2005, 07:22 PM
  5. Replies: 7
    Last Post: Feb 21st, 2005, 11:33 PM

Posting Permissions

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