Question

Hi I have the follonwing selectOneMenu

<h:selectOneMenu value="#{modelsController.selected.idBrands}">
    <f:selectItems value="{brandsController.itemsAvailableSelectOne}" />
</h:selectOneMenu> <br/>

which is populated with all available brands in the bean.

And I would like to create a button that retrives the brand selected in the mentioned selectOneMenu and display the records in the bean filtered by the selection (what I mean, is that if the user selected, aBrand in the selectOneMenu all models from abrand will be shown in a datatable.

This is a simple CRUD jsf 2.0 with EcpliseLink.

Could somebody point me in the right direction? Thank you very much

Was it helpful?

Solution

Add a <h:form> and a <h:commandButton>:

<h:form>
    <h:selectOneMenu value="#{modelsController.selected.idBrands}">  
        <f:selectItems value="{brandsController.itemsAvailableSelectOne}" />  
    </h:selectOneMenu>
    <br />
    <h:commandButton value="submit" action="#{modelsController.submit}" />
</h:form>

And define an action method which fills the datatable list based on the selected item.

public String submit() {
    items = itemDAO.load(selected.getIdBrands());
}

And display it in the <h:dataTable> the usual way.

<h:dataTable value="#{modelsController.items}" ... >
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top