0

I have a projet object and I need to save it to a SelectItem clients object. How do I code this?

public Projet projet;
public List<Client> clients;

we have a Xhtml code

<h:selectOneMenu value="#{details.projet.client}">

        <f:selectItem itemLabel="----Choisir Votre Client ---------" itemValue="-1"/>
        <f:selectItems value="#{details.clients}" var="c" itemValue="#{c}" itemLabel="#{c.nom_prenom}"/>
        </h:selectOneMenu>

        <p:commandButton value="Choisir" class="btn btn-primary" />

I need to save the selected item of clients object to a projet object. How do I code this in ManagedBean details?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • @Balus C , i not need to display into selectonemenu but i need when onclick button command the item selected of selectonemenu ( type Client) , the value inserted in class projet into DB – Hamdi Zairi Sep 06 '16 at 23:26
  • It's covered in the top answer of the duplicate. Did you read it from top to bottom? – BalusC Sep 07 '16 at 07:14
  • My problem is not display in the selectonemenu(the display is done) ,but my problem is when I click on the "select" button, I prefer to assign the selected value to the table selectonemenu 'project'. – Hamdi Zairi Sep 07 '16 at 17:20
  • So you're saying that you don't have a JSF related problem? I.e. you already have the `client` variable set with right value thanks to JSF and you just wanted to save the `client` variable in the database? – BalusC Sep 07 '16 at 18:33
  • yes , i talk about that – Hamdi Zairi Sep 07 '16 at 20:45
  • I do not know what is the necessary code to the method of choisirClient () in the bean – Hamdi Zairi Sep 07 '16 at 20:53
  • JSF is a MVC framework for HTML form based applications, not a database persistence framework. For that you normally use JPA or perhaps vanilla JDBC. Just start off with the `client` variable. JSF has at that point already done its job of providing you the submitted HTML form value in a Java variable and is irrelevant as to persisting that variable in the database. – BalusC Sep 07 '16 at 21:08

0 Answers0