0

I have a problem binding a certain profile from a datatable to managedbean for editing purpose,i'll show only one column in my code to make it readable!

adminIndex.xhtml

<!DOCTYPE html>

   <h:form>
<h:dataTable value = "#{profil.getProfils()}" var = "profil">

 <h:column>                 
   <f:facet name = "header">Login</f:facet>                 
    <h:inputText value = "#{profil.login}" size = "10" rendered = 
        "#{edit.id eq profil.login}" />
        <h:outputText value = "#{profil.login}" rendered = "#{edit.id 
        ne profil.login}" />
    </h:column>
    <h:column>
       <f:facet name ="header">Edit</f:facet>
       <h:commandButton value ="Edit" 
              action = "#{edit.setId(profil.id)}" 
              rendered = "#{edit.id ne profil.login}"> 
           </h:commandButton>
      </h:column>
</h:dataTable>
<h:commandButton id="save" value ="Save" 
              action = "#{profil.saveProfil()}" > 
</h:commandButton>
</h:form>
    </h:body>
</html>

Profil.java:

@Entity
@Table(name="profil")
@ManagedBean(name="profil")
@SessionScoped
public class Profil implements Serializable {

private static final long serialVersionUID = 1L;
@Id
private String login;

public void saveProfil() {
    EditBean eb = new EditBean();
    eb.setId(null);
    ProfilDao dao = new ProfilDao();
    dao.saveProfile(this);
 }

  public List<Profil> getProfils(){
    ProfilDao dao = new ProfilDao();
    return dao.profils();
}
}

EditBean.java:

@ManagedBean(name="edit")
public class EditBean {
private static String id;

    public void setId(String id) {
    this.id = id;
}
}

toString method shows that the object is null, i need the object to be binded to the managedBean

Amine Maalfi
  • 145
  • 9

1 Answers1

0

thank you all i resolved it,the command button related to savewas outside the datatable!

Amine Maalfi
  • 145
  • 9