In a Struts 1.x application, I have a form with a simple single-selection html:select element. I want to force the user to touch the box and make a choice, rather than allowing the first option to be the de facto default value. An obvious first step is to add a stand-in html:option value as the first item in the list. This option would have a label such as “Please choose…” and a marker value of some kind to indicate that this is not a genuine option.
My question: What is the best approach to detect and reject this “no selection” value during form submission?
Ideally, I would like to use a standard Struts validator and the standard error flow, so that this would act in a similar fashion to an html:text with a “required” validator. Is this possible? If not, how can I achieve a similar effect?
You could simply have the
Please choose...option havevalue=""then make the field required in your validation.