views:

487

answers:

1

Hi people, I am a newbie into programming and i am currently employed as a junior programmer. I am currently having some problems validating the select tags in one of my forms. What i actually trying to do is to ensure that one item is selected before the user submits the form .

In the form i have;

<s:select list="assessmentTypes" headerKey="0" headerValue=" -- Select One --"
          listKey="id" value="name" listValue="name" key="course.assessmenttype"
          name="assessmenttype.id"/>

I have some knowledge of validation but not to sure how to do it for the select list.

I tried using a normal validation with strings but i don't think it is required in this case. for example;

<field name="course.assessmenttype">
    <field-validator type="requiredstring">
        <message>Please Select a value</message>
    </field-validator>
</field>

all help would be appreciated, Thanks in advance.

+1  A: 

One option is to use an int validator with a min value set. Since you want any value greater than 0.

     <field name="course.assessmenttype">
          <field-validator type="int">
              <param name="min">1</param>
              <message>Please Select a value to continue</message>
          </field-validator>
      </field>
Vincent Ramdhanie
Hey,I tried the Suggestion, but still ending with failures. Object of class [com.sbcstnt.core.model.AssessmentType] with identifier [0]: not found anymore ideas, Thanks
pundit
Are you sure that the field is being validated? Check the name of the field against the field name in the validation xml file to make sure.
Vincent Ramdhanie