2012-07-05 72 views
0

我有下面的代碼,我想獲得選定的行。綁定數據表JSF 2.0

@ManagedBean 
@SessionScoped 
public class ElementTableData { 

    private List<Element> elementList; 
    private DataModel<Element> model; 

    private HtmlDataTable htmlDataTable; 
    private Element element; 
    private List<Element> selectedElementList; 
     .... 
     public HtmlDataTable getHtmlDataTable(){ 
     return htmlDataTable; 
    } 

    public void setHtmlDataTable(HtmlDataTable aHtmlDataTable){ 
     htmlDataTable = aHtmlDataTable; 
    } 
     .... 
    } 

當我試圖使結合

<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:p="http://primefaces.org/ui"> 
<h:head> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
    <link rel="stylesheet" type="text/css" href="css/styles.css" /> 
    <script type="text/javascript" src="js/global.js"></script> 
</h:head> 
<h:body> 
    <f:loadBundle 
     basename="messages" 
     var="labels" /> 
    <h:form> 
     <h:dataTable binding="elementTableData.htmlDataTable" styleClass="dataTable" rowClasses="rowOdd,rowEven" 
      value="#{elementTableData.elementList}" var="element"> 
      <!-- Table Title --> 
      <f:facet name="caption">#{labels.TableTitle}</f:facet> 

我收到以下異常:

javax.faces.FacesException: javax.el.PropertyNotWritableException: /index.xhtml at line 20 and column 52 binding="elementTableData.htmlDataTable": Illegal Syntax for Set Operation 

我有getter和setter的htmlDataTable,我不明白爲什麼我我正在獲得例外。

非常感謝!

+0

DataTable中綁定是錯誤的。它應該是@romaintaz狀態。另外,請查看BalusC(JSF專家)的代碼[使用數據表](http://balusc.blogspot.com/2006/06/using-datatables.html#GetSelectedDatatableRow)。 – 2012-07-06 02:13:24

回答

1

設置你作爲一個EL表達式綁定:

<h:dataTable binding="#{elementTableData.htmlDataTable}" ...> 
+0

我將綁定設置爲EL表達式,就像您從代碼中看到的一樣,我仍然收到異常:( – wallE 2012-07-05 20:52:12

+0

Srry Sryy!我的大錯誤!感謝您的幫助 – wallE 2012-07-06 07:25:44