Jsf pages from entities class net Beans Foreign key

Asked

Viewed 68 times

0

inserir a descrição da imagem aquiWhen I send jsf pages from entities class by net Beans, it generates crud automatically from the database even in primefaces if I prefer, but when I put some table that has foreign key relation, at the time of making a registration it takes the field this way through a selectOneMenu( entities.Vendaproduto[ idVenda=2 ] ), where it takes the path + the field id, and assigns the id and makes the registration according to the id, I want to make it take the field name and enter the id, ie in selectOneMenu will be presented the name when selector will register the id of that name.

<p:selectOneMenu id="idUsu" value="#{vendaProdutoController.selected.idUsu}" >
                        <f:selectItems value="#{usuarioController.itemsAvailableSelectOne}"
                                       var="idUsuItem"
                                       itemValue="#{idUsuItem}"/>
                    </p:selectOneMenu>

I tried to do the following way, where he accesses the following route salesProductController.selected.idProduct.productProduct, which in my logic took the name of the product but in Lectone appears empty.

<p:selectOneMenu id="idUsu" value="#{vendaProdutoController.selected.idUsu}" >
                        <f:selectItems value="#{vendaProdutoController.selected.idProduto.nomeProduto}"
                                       var="idUsuItem"
                                       itemValue="#{idUsuItem}"/>
                    </p:selectOneMenu>

how do I get the name correctly in selectOneMenu?

1 answer

0


You need to use the attribute of f:Selecteditems "itemLabel", in it you can use an expression, using var to write whatever you want. Example:

Remember that in your selectOneMenu value has to be the type of your itemValue.

  • obg just put the following line : itemLabel="#{idUsuItem.nome}", sorry the return delay was in travel

Browser other questions tagged

You are not signed in. Login or sign up in order to post.