Quick Question - Removing submit button for JS

At the minute I've got a drop down list, who's value is passed back to my bean using a submit button, though I want to pass it's value when a new item is selected, and have the bean fire off another method.

Eg.

My list has |Ford|BUTTON

|VW |

Clicking my h:commandButton fires off a method to populate a list which is displayed below the selectOneMenu with values like Mondeo, focus etc or if the user picks VW only VW cars are shown. Though I want to have the list updated from selection in the drop down rather than having to use the submit button also.

JSP code

<h:selectOneMenu id="num_id" value="#{Object.car}">

<f:selectItems value="#{Object.carValuesMap}"/>

</h:selectOneMenu>

<h:commandButton value="Submit" [b]action="#{ActionBean.changeCarSelected}" [/b]id="submit" />

<t:datatable ... value="{Object.valuesList}" var="type">

This means hitting submit repopulates "valuesList" and then when the page is redisplayed, the list contains the new values. This is working fine but how can I set my JSF <h:selectOneMenu> to fire off the action action="#{ActionBean.changeCarSelected}" without the user having to use the commandButton?

Thanks for any help.

Michael

[1489 byte] By [mmcaa] at [2007-10-2 16:27:10]
# 1
use a ValueChangeListener in your selectOnemenu, like this: <h:selectOneMenu ...valueChangeListener="#{.bean.goViewDetail}">...
pringia at 2007-7-13 17:27:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I have tested ValueChangeListener but I think I'm missing something. My JSP is now:

<h:selectOneMenu id="num_id" value="#{Object.car}" valueChangeListener="#{ActionBean.changeCarSelected}">

<f:selectItems value="#{Object.carValuesMap}"/>

</h:selectOneMenu>

And from what I have seen it has to call a method return type void and taking a valueChangeEvent as a parameter. So my backing bean has this method.

public void changeCarType(ValueChangeEvent e) {

String car = e.getNewValue().toString();

Object.setCar(car);

List values = sessionBean.getTypesOfCar(car);

Object.setValuesList(values);

}

The problem is car isn't getting set and then saved in my transfer object (called Object here).

Thanks for any help on what I'm missing with valueChangeListener.

Michael.

mmcaa at 2007-7-13 17:27:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
This changeCarSelected is different from this changeCarType
pringia at 2007-7-13 17:27:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Sorry this was a copy and paste error rather than an error in my code. Mehtod name and call match, as no error is thrown. No method is called until I click the submit button dispite having the valuechangelistener in the drop down?Any help much appreciated.Michael.
mmcaa at 2007-7-13 17:27:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
what you need is this : <h:selectOneMenu value="#{bean.somvalue}"valueChangeListener="#{bean.changeListener}"onchange="submit()" immediate="true">You have to put this in your selectOneMenu onchange="submit()" immediate="true"
pringia at 2007-7-13 17:27:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
This is what I'm looking for, I knew I would have been missing something silly, I guessed it would call submit itself.Thanks man.Michael.
mmcaa at 2007-7-13 17:27:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...