2013-07-04 100 views
-1

IM開發使用JSF IM中檢索的數據表,即數據,使用primefacesprimefaces數據表不能正常工作

這裏的數據表標籤在XHTML頁面顯示DATAS面臨的一個問題的webapps和primefaces,是我的XHTML代碼

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:f="http://java.sun.com/jsf/core" 
     xmlns:ui="http://java.sun.com/jsf/facelets" 
     xmlns:p="http://primefaces.org/ui"> 

<h:head></h:head> 
<body> 
<h:form id="form"> 
<h:panelGrid columns="2" cellpadding="10"> 
<h:outputText value="Batch Name" /> 
      <p:selectOneMenu id="city" value="#{allot.batchName}"> 
       <f:selectItem itemLabel="Select Batch" itemValue="" /> 
       <f:selectItems value="#{allot.batchList}" /> 
       <p:ajax listener="#{allot.handleBatch}" /> 
      </p:selectOneMenu> 
      <p:dataTable var="batch" value="#{allot.batchInfoList}" > 
       <p:column headerText="Tan"> 
        <h:outputText value="#{batch.tan}" /> 
       </p:column> 
      </p:dataTable> 
    </h:panelGrid> 
</h:form> 
</body> 
</html> 

這裏被用於檢索數據

package com.cation.action; 

import java.util.ArrayList; 
import java.util.List; 

import com.cation.bean.BatchInfo; 
import com.cation.controller.CationController; 

public class Allocation { 

    private String batchName; 

    private List<BatchInfo> batchInfoList; 

    private List<String> batchList = new ArrayList<String>(); 

    private CationController cationController = new CationController(); 

    public String getBatchName() { 
     return batchName; 
    } 

    public void setBatchName(String batchName) { 
     this.batchName = batchName; 
    } 

    public List<BatchInfo> getBatchInfoList() { 
     return batchInfoList; 
    } 

    public void setBatchInfoList(List<BatchInfo> batchInfoList) { 
     this.batchInfoList = batchInfoList; 
    } 

    public List<String> getBatchList() { 
     return batchList; 
    } 

    public void setBatchList(List<String> batchList) { 
     this.batchList = batchList; 
    } 

    public Allocation() { 
     try { 
      batchList = cationController.getAllBatch(); 
     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 

    public String handleBatch() { 
     try { 
      batchInfoList = new ArrayList<BatchInfo>(); 
      batchInfoList = cationController.getBatchByName(batchName); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return "allotInput"; 
    } 
} 

我的條件是我的行動豆從selectone男人選擇一個值時u標籤我得到選定的值,並通過使用該值來檢索一些對象列表並使用數據表在xhtml頁面中顯示。但問題是我得到的對象列表中的行動,但沒有數據顯示在XHTML頁面。

任何人都可以幫我解決這個問題PLZ。

+0

你怎麼填'batchInfoList'? – Akheloes

回答

0

在這種情況下,通常使用「提交」按鈕。

  1. 你從你的菜單
  2. 選擇一個項目你點擊提交按鈕
  3. 表被填充數據。

什麼你還需要的是一個id您的dataTable:

<p:dataTable id="table" ... 

而在你的按鈕,你需要更新表:

<p:commandButton value="Update my table" actionListener="#{allot.handleBatch}" update="table" ...