SelectMany checkbox value-binded with HashMap<String,ArrayList>

Hello,

Someone can help me please?

Im trying to create a page with a lot of HtmlSelectManyCheckbox, and i need to value-bind then to the same Object in my BackingBean.

First i attemped to bind all HtmlSelectManyCheckbox with a single ArrayList, but only the last SelectMany had their values inserted on the ArrayList...

So, now im trying to bind all the HtmlSelectManyCheckbox with a HashMap<String,ArrayList>, because i would have just one object and for each entry I would have the checkboxes that were cheked in a single HtmlSelectManyCheckbox.

Now my question: there is a way to make this work?

my code example

Backing bean

private HashMap<String, ArrayList> respostaMatrizCheck =new HashMap<String, ArrayList>();

public HashMap<String, ArrayList> getRespostaMatrizCheck(){

return respostaMatrizCheck;

}

publicvoid setRespostaMatrizCheck(HashMap<String, ArrayList> respostaMatrizCheck){

this.respostaMatrizCheck = respostaMatrizCheck;

and the bindings

<h:selectManyCheckbox value="#{backingBean.respostaMatrizCheck['1'] }">

...

<h:selectManyCheckbox value="#{backingBean.respostaMatrizCheck['2'] }">

And the error message given when i tryed this is the following:

javax.servlet.ServletException: ValueBinding for UISelectMany must be of type List or Array

Any help would be welcome.

Thanks,

Ferry

[1822 byte] By [Ferrymana] at [2007-11-26 16:19:07]
# 1

This is just a guess, but maybe it would work if you initialize the elements of respostaMatrizCheck that you're going to use, like this:

public class myBean {

private HashMap<String, ArrayList> respostaMatrizCheck;

myBean() {

respostaMatrizCheck = new HashMap<String, ArrayList>();

respostaMatrizCheck.put( "1", new String[0] );

... one for each selectMany

}

...

}

The setRespostaMatrizCheck is not going to be used.

BrantKnudsona at 2007-7-8 22:42:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks for the reply,I think this not gonna work for me, because the SelectManyCheckboxes are added in runtime and i dont know how many of then i'll have.[]Ferry
Ferrymana at 2007-7-8 22:42:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
When you add the selectmanycheckbox, also add the empty string array to the map.
BrantKnudsona at 2007-7-8 22:42:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Hmm didnt work here...

here what ive done:

HtmlSelectManyCheckbox matrizCheck = (HtmlSelectManyCheckbox) app.createComponent(HtmlSelectManyCheckbox.COMPONENT_TYPE);

// Seta o id como sendo QuestaoMatriz_[CodQuestao]_[codLinha]

matrizCheck.setId("QuestaoMatriz_" + questaoMatriz.getCodigo() + "_" + linha.getCodigo());

PesquisaBackingBean pbb = (PesquisaBackingBean) faces.getApplication().getVariableResolver().resolveVariable(faces, "pesquisaBackingBean");

HashMap<String, ArrayList><String>> respostaMatrizCheck = pbb.getRespostaMatrizCheck();

respostaMatrizCheck.put(questaoMatriz.getCodigo() + "_" + linha.getCodigo(), new ArrayList<String>());

but the error continues:

javax.servlet.ServletException: ValueBinding for UISelectMany must be of type List or Array

javax.faces.webapp.FacesServlet.service(FacesServlet.java:152)

org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)

thanks for the help,

Ferry

Ferrymana at 2007-7-8 22:42:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Someone help me plz!there is a way to bind many HtmlSelectManyCheckbox to the same object in a backing bean?Im getting out of ideas.any help would be welcome!thanks,Ferry
Ferrymana at 2007-7-8 22:42:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

The ['1'] and ['2'] doesn't work with maps, it only works with ordinary arrays (and instead use [0], [1], etc). With maps you can just use the key name as getter.

So instead do<h:selectManyCheckbox value="#{backingBean.respostaMatrizCheck.box1}">

...

<h:selectManyCheckbox value="#{backingBean.respostaMatrizCheck.box2}">

and use map keys starting with an alphabetic character instead of numbers.

Map respostaMatrizCheck = new HashMap();

respostaMatrizCheck.put("box1", List<SelectItem>);

respostaMatrizCheck.put("box2", List<SelectItem>);

BalusCa at 2007-7-8 22:42:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...