我的应用程序使用richfaces 数据表显示客户列表,如图所示:
当用户单击编辑选项时,必须出现一个可编辑的行来编辑图像中的行数据:
我的 jsf 页面index.xhtml
<h:form>
<rich:panel style="width:100%;" header="List of Customer" >
<rich:dataTable style="width: 100%;" value="#{customerDataBaseQuery.customerDataModel}" var="c" rowClass="odd even" columnClasses=" c1,c2,c3,c4,c5,c6,c7"
onrowmouseover="this.style.fontWeight='bold'" onrowmouseout="this.style.fontWeight='normal'">
<rich:column>
<f:facet name="header">First Name:</f:facet>
<h:inputText value="#{customerDataBaseQuery.customer.firstName}" rendered="#{c.cusEditFlag}" />
<h:outputText value="#{c.firstName}" rendered="#{not c.cusEditFlag}" />
</rich:column>
<rich:column>
<f:facet name="header">Last Name:</f:facet>
<h:inputText value="#{customerDataBaseQuery.customer.firstName}" rendered="#{c.cusEditFlag}" />
<h:outputText value="#{c.lastName}" rendered="#{not c.cusEditFlag}" />
</rich:column>
<rich:column>
<f:facet name="header">Address</f:facet>
<h:inputText value="#{customerDataBaseQuery.customer.address}" rendered="#{c.cusEditFlag}" />
<h:outputText value="#{c.address}" rendered="#{not c.cusEditFlag}" />
</rich:column>
<rich:column>
<f:facet name="header">Phone No:</f:facet>
<h:inputText value="#{customerDataBaseQuery.customer.phone}" rendered="#{c.cusEditFlag}" />
<h:outputText value="#{c.phone}" rendered="#{not c.cusEditFlag}" />
</rich:column>
<rich:column>
<f:facet name="header">View Record:</f:facet>
<h:commandLink id="view" value="View" action="#{customerDataBaseQuery.assignCustId(c.id,c.firstName,c.lastName)}" rendered="#{not c.cusEditFlag}" styleClass="lk"/>
</rich:column>
<rich:column>
<f:facet name="header">Edit Record:</f:facet>
<h:commandLink id="Edit" value="Edit" styleClass="lk" action="#{customerDataBaseQuery.cusEditAction(c)}" rendered="#{not c.cusEditFlag}" />
<h:commandLink id="Save" value="Save" styleClass="lk" action="#{customerDataBaseQuery.cusSaveAction(c)}" rendered="#{c.cusEditFlag}"/>
</rich:column>
<rich:column>
<f:facet name="header">Remove Record:</f:facet>
<h:commandLink id="Remove" value="Remove" styleClass="lk" action="#{customerDataBaseQuery.deleteCustomer(c.id)}" rendered="#{not c.cusEditFlag}"/>
</rich:column>
</rich:dataTable>
</rich:panel>
</h:form>
我的 Bean 类CustomerDatabaseQuery.java
@ManagedBean()
@SessionScoped
public class CustomerDataBaseQuery {
private DataModel customerDataModel;
private DataModel creditDataModel;
private Customer customer;
private Items items;
private CustomerHelper customerHelper;
private int custID;
private String fName;
private String lName;
public CustomerDataBaseQuery(){
customer=new Customer();
items=new Items();
customerHelper=new CustomerHelper();
}
public String assignCustId(int ID,String f,String l){
custID=ID;
fName=f;
lName=l;
return "View";
}
public void cusSaveAction(Customer c){
c.setCusEditFlag(false);
}
public String cusEditAction(Customer c){
c.setCusEditFlag(true);
return null;
}
public void itemSaveAction(Items i){
i.setItemEditFlag(false);
}
public void itemEditAction(Items i){
i.setItemEditFlag(true);
}
public String getFName() {
return fName;
}
public void setFName(String fName) {
this.fName = fName;
}
public String getLName() {
return lName;
}
public void setLName(String lName) {
this.lName = lName;
}
public void setCustId(int custID){
this.custID=custID;
}
public int getCustID(){
return custID;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public DataModel getCustomerDataModel(){
customerDataModel = new ListDataModel(customerHelper.getCustomerRecord());
return customerDataModel;
}
public /*String*/ void insertCustomer(){
/*String returnString =*/ customerHelper.saveCustomerRecord(customer);
//return returnString;
}
public void deleteCustomer(int ID){
customerHelper.deleteCustomerRecord(ID);
}
public Items getItems() {
return items;
}
public void setItems(Items items) {
this.items = items;
}
public DataModel getCreditDataModel(){
creditDataModel = new ListDataModel(customerHelper.getCreditRecord(custID));
return creditDataModel;
}
public /*String*/ void insertCreditRecord(){
items.setCustomerId(custID);
/*String returnString =*/ customerHelper.saveCreditRecord(items);
//return returnString;
}
public void deleteCredit(int ID){
customerHelper.deleteCreditRecord(ID);
}
}
首先<h:outputText>
将呈现为变量 cusEditFlag 的值为 false。单击编辑命令链接时,变量 cusEditFlag 的值设置为 true。设置其值 true 后<h:inputText>
必须呈现但它不会发生。我还在单击编辑命令链接时查看变量的值进行调试,变量的值更改为 true,但它也不起作用。我在这里学习了类似的文章,唯一的区别是他使用的是 jsf 数据表,而我使用的是richfaces 数据表。dsf 数据表和richfaces 数据表在执行此类任务时是否存在差异?或者我做错了任何人都可以弄清楚。