我正在尝试编辑填充的表单,但是它仅在单击commandButton后才将旧值发送到ManagedBean。
该概念的快速概述:
每当我单击edit时,每列都有一个outputText和inputText字段,如果该行中的id与该行中的id相同,则将该行的id发送给一个名为EditBean的托管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>
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";
}