0

i am trying to edit a populated form but it only sends the old values to the managedBean after clicking on the commandButton.

Quick overview of the concept:

i have for each column a outputText and inputText field whenever i click on edit i send the id of the row to a managed bean called EditBean and i store the id of the row, if the id in the bean is the same as the one in the row the inputText will be rendered otherwise the outputText will be rendered,now when i change the values in the inputText fields the row is updated with old values!

JSF page:

<h:form id="form">

    <h:dataTable value ="#{profil.getProfils()}" var ="profil" class="table table-dark">

   <h:column>                   
      <f:facet name = "header">Login</f:facet>                  
      <h:inputText value = "#{profil.login}" id="login" size = "10" rendered = "#{edit.id eq 
       profil.login}" class="form-control"/>
      <h:outputText value = "#{profil.login}" rendered = "#{edit.id ne profil.login}" />
   </h:column>
    <h:column>
           <f:facet name ="header">Edit</f:facet>
            <h:commandButton id="edit" value="Edit" action="#{edit.setId(profil.login)}"
            rendered ="#{edit.id ne profil.login}" class="btn btn-primary">
             <f:ajax execute="@form" render="@form" />   
            </h:commandButton>
            <h:commandButton id="save" value ="Save" 
              action="#{profil.updateProfil()}"
              rendered = "#{edit.id eq profil.login}" class="btn btn-primary" > 
            </h:commandButton>

      </h:column>
  </h:dataTable>

 </h:form>

ProfilBean:

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

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

 public String updateProfil() {

    ProfilDao dao = new ProfilDao();
    dao.updateProfile(this);
    EditBean eb = new EditBean();
    eb.setId(null);
    return "saved";

}
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Amine Maalfi
  • 145
  • 9

0 Answers0