2012-01-29 50 views
1

暈 我的名字是Sergie,我在使用jsf spring和jpa構建學校自動化系統的學校項目上工作。我正在學習jsf。 我需要你的幫助,三個標題JSF - 在運行時填充數值

城市|學校|添加/刪除

<c:column> 
    <f:facet name="header"> 
    <c:outputText value="City" /> 
</f:facet> 

    <c:outputText id="ukrCity" value="" " /> 
</c:column> 

<c:column> 
<f:facet name="header"> 
<c:outputText value="School" /> 
</f:facet> 
<c:inputText id="school" value="" 
     maxlength="12" " /> 
      </c:column> 

<c:column> 
<f:facet name="header"> 
<c:outputText value="Add/Remove" /> 
</f:facet> 
<c:selectBooleanCheckbox 
    id="addremove" 
     value="" 
     rendered="" /> 
</c:column> 




City  |   School  | Add/Remove 


Київ    "textbox"   "checkbox" 

Харків    "textbox"   "checkbox" 

城市從市級

public class UkrCity {      

private List<A> ukrCities; 

public List<A> getUkrCities() { 
     return ukrCities; 
    } 

public void setUkrCities(final List<A> ukrCities) { 
     this.ukrCities= ukrCities; 
    } 

private void allCities() { 
     //add all cities in a list 
     ukrCities.add("Київ"); 
     ukrCities.add("Харків"); 
    } 
} 

人口如何展示下城區XHTML頁面和空白文本框和複選框上ukrcities下學校和添加/刪除TAV。

謝謝 抱歉,我的英語不好。

+0

OK sergie我會爲您提供所有的東西是很容易 – 2012-01-30 12:12:56

回答

1

我重構了你的代碼。這裏是UkrCity班。

package com.example; 

import java.io.Serializable; 

public class UkrCity implements Serializable { 
    /** 
* 
*/ 
private static final long serialVersionUID = 1L; 
private String name; 

public UkrCity(String name) { 
     this.setName(name); 
} 

public String getName() { 
    return name; 
} 

public void setName(String name) { 
    this.name = name; 
} 
} 

下面是支持bean

package com.example; 

import java.io.Serializable; 
import java.util.ArrayList; 
import java.util.Arrays; 

import javax.faces.bean.ManagedBean; 
import javax.faces.bean.SessionScoped; 

@ManagedBean 
@SessionScoped 
public class TableBean implements Serializable{ 

/** 
* 
*/ 
private static final long serialVersionUID = 1L; 
private ArrayList<UkrCity> cities = new ArrayList<UkrCity>(Arrays.asList(new UkrCity("Київ"),new UkrCity("Харків"))); 
public ArrayList<UkrCity> getCities() { 
    return cities; 
} 
} 

這是你的index.xhtml

<?xml version="1.0" encoding="UTF-8"?> 
<!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:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"> 
<h:head> 
    <title>UkrCities Table</title> 
</h:head> 
<h:body> 
    <h:form> 
    <h:dataTable value="#{tableBean.cities}" var="city"> 

     <h:column> 
      <f:facet name="header">City</f:facet> 
      <h:outputText value="#{city.name}" /> 
     </h:column> 

     <h:column> 
      <f:facet name="header">School</f:facet> 
      <h:inputText value="" /> 
     </h:column> 

     <h:column> 
      <f:facet name="header">Add/Remove</f:facet> 
      <h:selcectBooleanCheckbox value="" onclick="submit()" /> 
     </h:column> 
    </h:dataTable> 
    </h:form> 
</h:body> 
</html>