我有一个带有 3 个输入字段和两个命令按钮(提交和取消)的表单。用户提交表单后,信息应填充到下面的数据表中,包含 3 列。还有一个操作列,其中包含插入的每一行的 EDIT 和 DELETE 命令链接。单击编辑时,需要将该记录的信息填充到上面的表单中,然后如果表单已提交,请检查该记录是否已存在。如果记录不存在,则将其添加到列表中。
XHTML1 名字:
<h:outputLabel>LastName:</h:outputLabel>
<h:inputText id="lastName" value="#{form.lastName}"/>
<h:outputLabel>MiddleName:</h:outputLabel>
<h:inputText id="middleName" value="#{form.middleName}" />
<h:commandButton value="Cancel" action="#{formBacking.cancel}" immediate="true"></h:commandButton>
<h:commandButton value="Submit" action="#{formBacking.submit}"></h:commandButton>
</h:panelGrid>
</h:form>
XHTML2
用户详情
<h:column>
<f:facet name="header">FirstName</f:facet>
<h:outputText value="#{userDetails.fname}" />
</h:column>
<h:column>
<f:facet name="header">LastName</f:facet>
<h:outputText value="#{userDetails.lname}" />
</h:column>
<h:column>
<f:facet name="header">MiddleName</f:facet>
<h:outputText value="#{userDetails.mName}" />
</h:column>
<h:column>
<f:facet name="header">Action</f:facet>
<h:commandLink
action="#{formBacking.editUser(userDetails)}"
value="Edit" />
<h:commandLink
action="#{formBacking.deleteUser(userDetails)}"
value="Delete" />
</h:column>
</h:dataTable>
</h:form>
Form.java
@Managed Bean
@ViewScoped
private String firstName = "";
private String lastName = "";
private String middleName = "";
//Setters and getters
UserBacking.java
@ManagedBean
@ViewScoped
private List<Form> userList = new ArrayList<Form>();
\\setters and getters
public void submit(){}
public void cancel(){}
public void editUser(){}
public void deleteUser(){}
What would be the best way to handle the edit functionality?