-1

I have a and I want to get the selected values back in bean. But the value I receive when I select an item from the menu it's a string, representing the type field from the CategorizationBean. I just want when I select an item from the table, to get the whole CategorizationBean structure in the bean.

any idea ?

Jebshit
  • 11
  • 3

1 Answers1

1

I think that you have missed by using a list of beans, I use this example and it works:

<p:selectCheckboxMenu id="slctRdBtn"
                                value="#{yourBean.compLovDtgrid}"
                                converter="compLovDtgridConverter">
                                <f:selectItems
                                    value="#{yourBean.listCompLovDtgrid}"
                                    var="rdbtn" itemLabel="#{rdbtn.vjlrLibelleRep}"
                                    itemValue="#{rdbtn}" />
                            </p:selectCheckboxMenu>

and for the converter:

@FacesConverter(forClass=CompLovDtgrid.class , value="compLovDtgridConverter")
public class CompLovDtgridConverter implements Converter{
@Override
public String getAsString(FacesContext context, UIComponent component, Object value)
{
    return (value instanceof CompLovDtgrid) ? ((CompLovDtgrid) value).getVjlrCodeRep() : null;
}
@Override
public Object getAsObject(FacesContext context, UIComponent component,String value)
{
    if(value == null)
        return null;

YourBean data = context.getApplication().evaluateExpressionGet(context, "#{yourBean}", YourBean.class);

for(CompLovDtgrid compLovDtgrid : data.getListCompLovDtgrid())
{
    if(compLovDtgrid.getVjlrCodeRep().equals(value))
        return compLovDtgrid;
}

throw new ConverterException(new FacesMessage(String.format("Cannot convert %s to CompLovDtgrid", value)));}}

and for the list, I use:

public List<CompLovDtgrid> getListCompLovDtgrid() 
    {
        return listCompLovDtgrid;
    }

public void setListCompLovDtgrid(List<CompLovDtgrid> listCompLovDtgrid) {
    this.listCompLovDtgrid = listCompLovDtgrid;
}
Abed Kanbar
  • 120
  • 4