2010-09-30 61 views
0

我正在使用JSF1.2中的數據表來填充從Seam組件/使用列表接收的數據。當我使用列表時,數據正在被抓取。但是,當我希望使Datatable可編輯,以便在JSF頁面上更改的值可以發送回Seam組件/備份Bean時,該列表不會將值傳遞給Seam組件/備份Bean。如何從JSF發送列表到支持Bean

我已經嘗試過了,但是我無法將列表再次傳遞給Seam組件/ Backing Bean。

以下是代碼。

JSF代碼:

<h:dataTable value="#{mainbean.findCustomerlist}" var="findCustomerList"> 
    <h:column> 
    <f:facet name="header"> 
    <h:outputText value="Sr No" /> 
    </f:facet> 
    <h:outputText value="#{findCustomerList.id}" /> 
    </h:column> 
    <h:column> 
    <f:facet name="header"> 
    <h:outputText value="Company Name" /> 
    </f:facet> 
    <h:inputText value="#{findCustomerList.companyName}" /> 
    </h:column> 

    <h:column> 
    <f:facet name="header"> 
    <h:outputText value="Account Number" /> 
    </f:facet> 
    <h:inputText value="#{findCustomerList.accountNumber}" /> 
    </h:column> 
    <h:column> 
    <f:facet name="header"> 
    <h:outputText value="Contact Number" /> 
    </f:facet> 
    <h:inputText value="#{findCustomerList.contactNumber}" /> 
    </h:column> 
    <h:column> 
    <f:facet name="header"> 
    <h:outputText value="Contact Name" /> 
    </f:facet> 
    <h:inputText value="#{findCustomerList.contactName}" /> 
      </h:column> 
     <br></br> 

    </h:dataTable> 

<h:commandButton value="Update" type="submit" action="#{mainbean.modifyCustomer(findCustomerlist)}" /> 

縫組件/輔助Bean代碼:

private List<Customer> findCustomerlist=null; 


public List<Customer> getFindCustomerlist() { 
    return findCustomerlist; 
} 

public void setFindCustomerlist(List<Customer> findCustomerlist) { 
    this.findCustomerlist = findCustomerlist; 
} 


public void searchCustomer(ActionEvent actionEvent) 
    { 
    findCustomerlist=session.findCustomer(customerName); 
    } 

/* The searchCustomer function works fine and it returns the list to the JSF. But when I use the modifyCustomer function to retrieve the value from JSF then it is not working.*/ 

    public void modifyCustomer(List<Customer> findCustomerlist) 
    { 
     session.updateCustomer(findCustomerlist); 
     System.out.println("Inside modifyCustomer"); 
     System.out.println(findCustomerlist.get(0).getCompanyName()); 
    } 

回答

1

我不知道什麼接縫正在做這件事,但在正常JSF這是不必要的。通常,JSF已經在更新模型值階段更新了列表屬性。您只需將其作爲本地bean屬性進行訪問即可。即

<h:commandButton value="Update" type="submit" action="#{mainbean.modifyCustomer}" /> 

public void modifyCustomer() 
{ 
    session.updateCustomer(findCustomerlist); 
    System.out.println("Inside modifyCustomer"); 
    System.out.println(findCustomerlist.get(0).getCompanyName()); 
} 

應該已經足夠了。

您只需確保由支持bean保留相同的列表。當bean被請求作用域時,到目前爲止顯示的代碼將失敗。如果您使用的是JSF 2.0,則可以將該bean放入view範圍內。在JSF 1.x上,您需要將bean放入session範圍內(不推薦),或者在bean的構造函數中預加載列表,或者根據customerName加載@PostConstruct

相關問題