Dropdown validator does not fire if the selected value is a blank string

I have created a <ui:dropdown> like this:

<ui:dropDown binding="#{myPage.default}" id="default"

items="#{myPage.selectionList}"

validator="#{myPage.validateDropdownSelection}"

valueChangeListener="#{myPage.processValueChange}"/>

My intention was to create a mechanism where I create a list of valid selections from the database and append a "[ Select Value]" type tag with a blank string value as the first element in the Option[]. Something like this:

new Option[]{

new Option("","[ Select Value ]" ),

new Option("valueA","Value A" ),

new Option("valueB","Value B" )

};

My custom validator checks to make sure that that a valid selection has been made, e.g. not the initial blank string-valued tag. This validator works normally for all cases except for when I choose the initial blank string value. In that case the validator never fires, so my validator is effectively useless in safeguarding against this blank string as a selection.

So, to sum up my problem, the validator from a <ui:dropdown> does not appear to fire in the case where the new selection is a blank string.

Thanks.

[1656 byte] By [pennstump] at [2007-11-26 11:33:00]
# 1
I'm not sure how your custom validator works. But I have dropdown box with options same as you have. My required flag is checked. When I press submit. I get the missing field error.Sri Thuraisamy
WatchBlade at 2007-7-7 3:48:46 > top of Java-index,Development Tools,Java Tools...
# 2

I'll include my validator; it's very simple. According to the debugger, I never even get into this method when the top selection is made.

public void validateDropdownSelection( FacesContext context, UIComponent component, Object value )

{

// Method Variables

String selection = "";

// Validate Passed Value Type

if ( value instanceof String )

{

selection = (String) value;

}

else

{

selection = value.toString ();

}

// Validate Dropdown Selection

if ( selection.length() < 1 )// If Blank String

{

// Failure - Blank Dropdown Selection; Throw Exception

throw new ValidatorException( new FacesMessage( "Please select a value" ) );

}

}

pennstump at 2007-7-7 3:48:46 > top of Java-index,Development Tools,Java Tools...