首页 > 解决方案 > jsf 表单编辑值未反映在托管 bean 中

问题描述

我正在尝试编辑填充的表单,但它仅在单击命令按钮后将旧值发送到 managedBean。

概念概览:

每当我单击编辑时,我都有一个 outputText 和 inputText 字段,我将行的 id 发送到名为 EditBean 的托管 bean 并存储行的 id,如果 bean 中的 id 与将呈现 inputText 的行,否则将呈现 outputText,现在当我更改 inputText 字段中的值时,该行将使用旧值更新!

JSF 页面:

<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>

轮廓豆:

@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";

}

标签: hibernatejsf

解决方案


推荐阅读