1

I have a Map (Integer, List) which I want to fill from a JSF page. I'm only using JSF, no Primefaces or such.

On my JSF page there is a selectOneMenu that displays each keys of my Map, and a selectManyBox to choose the values for each key.

I want to be able to save each state before submitting the whole Map.

See my bean:

@ManagedBean(name="myBean")
@SessionScoped
public class MyBean implements Serializable {
    (...)
    public void refresh(ValueChangeEvent e)
{
    if (idRole==-1){ //to check if its just the first selection                     
        setKey((int)e.getNewValue());
    }
    else{
        myObject.getMap().put(key,listOfValuesSelected); //put current manycheckbox values in last selected key
        setKey((int)e.getNewValue()); //get new key
        listOfValuesSelected=MyObject.getMap().get(Key); //refresh the
                               //selectManyCheckbox for the newly selected key          
    }

}

My JSF Page

<h:selectOneMenu id="idRole" value="#{myBean.key}" onchange="submit()" valueChangeListener="#{myBean.refresh}" render="checkbox"> >
    <f:selectItem itemLabel="" itemValue="" />
    <f:selectItems value="#{myBean.listKeys}" />
</h:selectOneMenu>

<fieldset id="checkbox">
    <h:selectManyCheckbox value="#{myBean.listOfValuesSelected}">
        <f:selectItems value="#{myBean.listeOfValues}" var="n"
            itemLabel="#{n.title}" itemValue="#{n.key}"/>
    </h:selectManyCheckbox>
</fieldset>

My real code is kind of a mess, I rearranged it a bit to fit the needs of my question but I can give you the real code if needed.

My problem is that the selectmanycheckbox doesn't "react" at all. I see that the listOfValuesSelected is modified when I am in debug mode.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

0

Do you use AJAX somewhere? And what kind of form do you use?

With "doesn't react", do you mean it's not re-rendered, or that nothing happens when you select one or more items in it?

If you use AJAX then with the given code the select many checkbox will indeed not re-render (refresh). The reason is that SelectOneMenu doesn't have an attribute "render" that causes something to be re-rendered. Third party components often have such a thing, but the standard components only do that via an f:ajax tag. Also, you can't use a non-component ID as a re-render target. Fieldset is not a component.

See http://docs.oracle.com/javaee/6/tutorial/doc/gkabr.html on how to use f:ajax

Mike Braun
  • 3,729
  • 17
  • 15
  • Oh, thank you very much. Since I'm kind of starting with JSF. I am for that one tryin a easier way to respond to my needs. So i will just add a button that will submit the changes, and ajax listener just to refresh the view. Currently working on that, will keep you posted. Thank you for your help – user3798342 Jul 03 '14 at 12:45