...I wrote a mini example to explaint what I mean...:
This is the client side layout:
Code:
<f:view>
<h:form>
<f:subview id="workplace_democomboobjectsg_37">
<t:rowbodypane id="g_1" >
<t:row id="g_2" >
<t:label id="g_3" text="Department" width="120" />
<t:combobox id="g_4" validvaluesbinding="#{wp.DemoComboObjects.cbDepartment.vvb}" value="#{wp.DemoComboObjects.cbDepartment.value}" width="200" />
</t:row>
<t:rowdistance id="g_5" height="10" />
<t:row id="g_6" >
<t:coldistance id="g_7" width="120" />
<t:button id="g_8" actionListener="#{wp.DemoComboObjects.onOutputSelection}" text="Output Information" />
</t:row>
</t:rowbodypane>
<t:rowstatusbar id="g_9" />
<t:pageaddons/>
</f:subview>
</h:form>
</f:view>
And this is the server side code:
Code:
package workplace;
import java.io.Serializable;
import javax.faces.event.ActionEvent;
import org.eclnt.editor.annotations.CCGenClass;
import org.eclnt.jsfserver.defaultscreens.Statusbar;
import org.eclnt.jsfserver.elements.util.ValidValuesBinding;
@CCGenClass (expressionBase="#{wp.DemoComboObjects}")
public class DemoComboObjects implements Serializable
{
// ------------------------------------------------------------------------
// inner classes
// ------------------------------------------------------------------------
public interface IWithText
{
public String getText();
}
public class Department
implements Serializable, IWithText
{
String i_text;
public String getText() { return i_text; }
public void setText(String text) { i_text = text; }
public Department(String text) { i_text = text; }
}
/**
* The id that is passed to the client side is the index of the
* object within the array.
*/
public class ComboCounterPart
{
IWithText[] i_objects;
int i_selObjectIndex = -1;
ValidValuesBinding i_vvb = new ValidValuesBinding();
public ComboCounterPart(IWithText[] objects)
{
i_objects = objects;
for (int i=0; i<objects.length; i++)
i_vvb.addValidValue(""+i,objects[i].getText());
}
public ValidValuesBinding getVvb() { return i_vvb; }
public String getValue()
{
if (i_selObjectIndex < 0)
return null;
else
return "" + i_selObjectIndex;
}
public void setValue(String value)
{
i_selObjectIndex = (new Integer(value)).intValue();
}
public IWithText getSelectedObject()
{
if (i_selObjectIndex < 0)
return null;
else
return i_objects[i_selObjectIndex];
}
}
// ------------------------------------------------------------------------
// members
// ------------------------------------------------------------------------
ComboCounterPart m_cbDepartment;
// ------------------------------------------------------------------------
// constructors
// ------------------------------------------------------------------------
public DemoComboObjects()
{
Department[] deps = new Department[]
{
new Department("Sales"),
new Department("Marketing"),
new Department("Production"),
new Department("Board")
};
m_cbDepartment = new ComboCounterPart(deps);
}
// ------------------------------------------------------------------------
// public usage
// ------------------------------------------------------------------------
public ComboCounterPart getCbDepartment() { return m_cbDepartment; }
public void onOutputSelection(ActionEvent event)
{
if (m_cbDepartment.getSelectedObject() != null)
Statusbar.outputMessage("The selected object is: " + m_cbDepartment.getSelectedObject().getText());
else
Statusbar.outputMessage("No selection yet.");
}
}
The class "ComboBoxCounterPart" is the transferr-er between Objects and Strings. Hope, this makes things clearer...
Björn