views:

83

answers:

1

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

+1  A: 

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}" ... >
BalusC
Thanks,are you using Hibernates itemDAO? Cause I can not reech .load from anywhere
Ignacio
No, it's just a simple self-explaining abstraction of a DAO class. Do whatever DAO thing you want as long as it returns the desired `List<Items>`.
BalusC
OK I thin'k i've got it public List<Models> findByBrands(Brands id_brand){ CriteriaQuery cq = (CriteriaQuery) em.createNamedQuery("SELECT m FROM Models WHERE m.id_brand :id_brand); cq.select(cq.from(Modelos.class)); return em.createQuery(cq).getResultList(); }In nede to get the argument in the sql query, is it possible?
Ignacio
Yes it is. If you can't figure it in the JPA docs/tutorials, ask a new question. This is off topic.
BalusC