selected value in Dropdown doesn't change after processValueChanged

When I select a value in a drop down box which is set to send automaticaly modifications I have the folowing message:

com.sun.rave.web.ui.component.DropDown::The current value of component form1:yearDropDown does not match any of the selections.

Did you forget to reset the value after changing the options?

Add to that the selected value is not selected in the drop down after the refreshing.

Could you please help me to solve this problem.

Here's my code:

<?xml version="1.0" encoding="UTF-8"?>

<jsp:root version="1.2" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:ui="http://www.sun.com/web/ui">

<jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>

<f:view>

<ui:page binding="#{test1.page1}" id="page1">

<ui:html binding="#{test1.html1}" id="html1">

<ui:head binding="#{test1.head1}" id="head1">

<ui:link binding="#{test1.link1}" id="link1" url="/resources/stylesheet.css"/>

</ui:head>

<ui:body binding="#{test1.body1}" id="body1" style="-rave-layout: grid">

<ui:form binding="#{test1.form1}" id="form1">

<h:panelGrid binding="#{test1.gridPanel2}" columns="4" id="gridPanel2" style="left: 20px; top: 30px; position: absolute">

<ui:dropDown binding="#{test1.yearDropDown}" id="yearDropDown" items="#{test1.yearDropDownDefaultOptions.options}"

onChange="common_timeoutSubmitForm(this.form, 'gridPanel2:yearDropDown');" valueChangeListener="#{test1.yearDropDown_processValueChange}"/>

<ui:textField binding="#{test1.dateTextField}" id="dateTextField" label="Year" readOnly="true"/>

</h:panelGrid>

</ui:form>

</ui:body>

</ui:html>

</ui:page>

</f:view>

</jsp:root>

publicclass test1extends AbstractPageBean{

publicvoid init(){

//(...)

initYearDropDown();

}

privatevoid initYearDropDown()

{

int firstYear = 2000;

int lastYear = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR);

Option[] yearsList =new Option[lastYear-firstYear+1+1];

yearsList[0] =new Option(Integer.valueOf(-1),"SELECT YEAR");

for (int i = 0 ; i < lastYear-firstYear+1; i++)

yearsList[i+1] =new Option(Integer.valueOf(i), String.valueOf(firstYear+i));

yearDropDownDefaultOptions.setOptions(yearsList);

}

privatevoid refreshDateTextFieldText()

{

year = ((Integer)yearDropDown.getSelected()).intValue();

dateTextField.setText(year);

}

publicvoid yearDropDown_processValueChange(ValueChangeEvent event)

{

refreshDateTextFieldText();

}

}

[4700 byte] By [requinca] at [2007-10-2 20:08:48]
# 1

I found the response on this post: http://forum.sun.com/jive/thread.jspa?forumID=123&threadID=60361

David.Botterill :

"The issue had to do with the object being wrapped by the "Option". If you choose to have your own "OptionsList" with generated "Option"s and the value you pass to "new Option(Object value, String label)" is not a String, you must implement "equals" on the Object.

Here's why...

In order for the dropdown list plumbing to determine the current selected, it must take what was rendered ("Option" value) and compare it with the "OptionsList" "Option" value. This means the Object you use for "value" in "new Option(Object value, String label)" if not a String, must override "equals" and compare the "toString" values. The value passed into the equals will be from the value chosen on the screen which will be in String form because it's rendered"

requinca at 2007-7-13 22:49:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...