Announcement Announcement Module
Collapse
No announcement yet.
How to mark a form field as required??? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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).

    Comment


    • #3
      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.

      Comment


      • #4
        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

        Comment


        • #5
          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.

          Comment

          Working...
          X