简体   繁体   中英

How can I retrieve the item that the user selected from the drop down? in jsf

My question is how can i retrieve selected item in backing bean ?

In my view page i have one select box component :

<h:selectOneMenu id="materialCat" value="#
{materialMasterBean.materialDTOs.materialCategoryId}" required="true" requiredMessage="Material Category is Mandatory"> <f:selectItem itemLabel="select" itemValue="-1" /> <f:selectItems value="#{materialMasterBean.materialCatList}" />
</h:selectOneMenu>

This is my backing bean

` public ArrayList getMaterialCatList() { if(materialCatList == null ) {

        materialCatList= new ArrayList<SelectItem>();
        ArrayList<MaterialDTO> temp;
        try {
                temp= getAdminDelegate().getMaterialLsit();
                for (int i = 0; i < temp.size(); i++)
                    {
                    MaterialDTO materialDTO = temp.get(i);
                        item = new SelectItem(materialDTO.getMaterialCategoryId(),materialDTO.getMaterialCategory());
                        materialCatList.add(item);
                    }
            } catch (Exception e) {
        // TODO Auto-generated catch block
                        e.printStackTrace();
                }

        return materialCatList;
    }
    else
    {
        return materialCatList;
    }

}

` also in backing Bean i have:

private MaterialDTO materialDTOs; please help me

you can access it in your bean if you binded it with the value="#{bean.filed} attribute

EDIT: here is an example on how to do a selectonebox, i think you missunderstood some things. Do you want to select a MaterialDTO Object in the list? or an Id? You dont need an ArrayList with SelectItem ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM