views:

31

answers:

1

I have a problem to bind list of h:selectBooleanCheckbox to my bean. Anybody helps ?

This is not working:

<ui:repeat value="#{cartBean.productsList}" var="cartProduct" varStatus="i">
   <h:selectBooleanCheckbox binding="#{cartBean.checkboxes[i.index]}" />
</ui:repeat>

public class CartBean extends BaseBean {
  public List<Product> getProductsList() {...}

  private HtmlSelectBooleanCheckbox[] checkboxes;
  public HtmlSelectBooleanCheckbox[] getCheckboxes() {
    return checkboxes;
  }
  public void setCheckboxes(HtmlSelectBooleanCheckbox[] checkboxes) {
    this.checkboxes = checkboxes;
  }
}

I get error:

javax.faces.FacesException: javax.el.PropertyNotFoundException: /WEB-INF/flows/main/cart.xhtml @26,97 binding="#{cartBean.checkboxes[i.index]}": Target Unreachable, 'checkboxes' returned null

I solved my problem. I used code like below and get what i want (thanks to BalusC blog - http://balusc.blogspot.com/2006/06/using-datatables.html#SelectMultipleRows):

<ui:repeat value="#{cartBean.productsList}" var="cartProduct" varStatus="i">
  <h:selectBooleanCheckbox value="#{cartBean.selectedIds[cartProduct.id]}" />
</ui:repeat>

public class CartBean extends BaseBean {
  private Map<Integer, Boolean> selectedIds = new HashMap<Integer, Boolean>();
  public Map<Integer, Boolean> getSelectedIds() {
    return selectedIds;
  }
}
A: 

I don't know if you can bind elements stored in an array. But in your code, the problem is that your HtmlSelectBooleanCheckbox[] is null. So maybe change your Java code to:

public HtmlSelectBooleanCheckbox[] getCheckboxes() {
    if (checkboxes == null) {
        checkboxes = new HtmlSelectBooleanCheckbox[getProductsList().size()];
    }
    return checkboxes;
}

but I am really not sure if it will work... Maybe the solution is to not bind your HtmlSelectBooleanCheckbox elements in the Java code. Why do you need to bind them?

romaintaz
Thanks for Your replay, but now i get error: javax.faces.FacesException: javax.el.PropertyNotFoundException: /WEB-INF/flows/main/cart.xhtml @26,97 binding="#{cartBean.checkboxes[i.index]}": Target Unreachable, 'BracketSuffix' returned null
marioosh.net