這個例子在jsf
自己在寫動態生成DataTable的時候也查閱了很多相關文章
在解決固定表頭問題上我是用的兩張表(加行標是
實現給每個Header加上一個CommandLink的時候我遇到了很大的問題
最後終於發現問題的所在
我原來的代碼是鏈接數據庫的
希望大家對我的代碼提出寶貴意見
Dynamic
<%@ taglib uri=
<%@ taglib uri=
<Script language=
var tdW;
//Scroll
function f_scroll(Col_T
if(Col_T!=
document
}
if(Row_T!=
document
}
}
</Script>
<html>
<f:view>
<head>
<title>TABLE</title>
<link rel=
</head>
<body>
<h:form>
<font size=
style=
<h:outputText value=
<h:inputText value=
style=
<h:commandButton value=
style=
<table BORDER=
STYLE=
<tr>
<td STYLE=
<!
<!
</td>
<td>
<!
<Div ID=
STYLE=
border
<h:dataTable value=
binding=
cellspacing=
headerClass=
style=
width:
id=
</h:dataTable>
</Div>
<!
</td>
</tr>
<tr>
<td STYLE=
<!
<Div ID=
STYLE=
width:
<h:dataTable value=
binding=
cellspacing=
headerClass=
style=
id=
</h:dataTable>
</Div>
<!
</td>
<td STYLE=
<!
<Div ID=
STYLE=
<h:dataTable value=
binding=
cellspacing=
headerClass=
style=
</h:dataTable>
</Div>
<!
</td>
</tr>
</table>
</h:form>
</body>
</f:view>
</html>
MyBean
package mypackage;
import java
import java
import javax
import ponent
import ponent
import l
import l
import l
import ntext
import javax
import javax
import javax
public class MyBean {
private List<List<String>> myList;
private List<List<String>> myHeader;
private List<List<Integer>> myNum;
private HtmlDataTable dynamicDataTable;
private HtmlDataTable headerDataTable;
private HtmlDataTable numDataTable;
private static int tempWidth =
// Load Data from DataBase to Every DataTable
public void loadMyList() throws Exception {
myList = new ArrayList<List<String>>();
int row =
while(row >
int column =
String str =
List <String> tmpvector = new ArrayList <String> ();
while(column >
tmpvector
column
}
row
myList
}
}
public void loadMyHeader() throws Exception {
myHeader = new ArrayList<List<String>>();
String str =
int column =
List <String> tmpvector = new ArrayList <String> ();
while(column >
tmpvector
column
}
myHeader
}
public void loadMyNum() throws Exception {
myNum = new ArrayList<List<Integer>>();
int row =
while(row <
List <Integer> tmpvector = new ArrayList <Integer> ();
tmpvector
myNum
row++;
}
}
//initialize Every DataTable to the Front
public void populateDynamicDataTable() {
if (myList != null && myList
dynamicDataTable = new HtmlDataTable();
int columns = ((List) myList
System
for (int i =
ValueBinding myItem =
FacesContext
UIColumn column = new UIColumn();
HtmlOutputText outputText = new HtmlOutputText();
outputText
outputText
column
column
dynamicDataTable
}
}
}
public void populateHeaderDataTable() {
if (myHeader != null && myHeader
headerDataTable = new HtmlDataTable();
int columns = ((List) myHeader
FacesContext facesContext = FacesContext
Application application = facesContext
for (int i =
HtmlCommandLink commandLink =
(HtmlCommandLink) application
String valueBindingExpression =
ValueBinding valueBinding = application
commandLink
commandLink
commandLink
commandLink
commandLink
Class[] params = { ActionEvent
MethodBinding actionListener =
application
commandLink
commandLink
UIColumn column = new UIColumn();
column
column
headerDataTable
}
}
}
public void populateNumDataTable() {
if (myNum != null && myNum
numDataTable = new HtmlDataTable();
UIOutput output = new UIOutput();
ValueBinding myItem =
FacesContext
output
// Set column
UIColumn column = new UIColumn();
column
column
numDataTable
}
}
//Test Actions and ActionListeners
public void setSelectedDocumentId(ActionEvent event) throws Exception
{
}
// Getters
public HtmlDataTable getDynamicDataTable() throws Exception {
if (dynamicDataTable == null) {
loadMyList(); // Reload to get most recent data
populateDynamicDataTable();
}
return dynamicDataTable;
}
public HtmlDataTable getHeaderDataTable() throws Exception {
if (headerDataTable == null) {
loadMyHeader(); // Reload to get most recent data
populateHeaderDataTable();
}
return headerDataTable;
}
public HtmlDataTable getNumDataTable() throws Exception {
if (numDataTable == null) {
loadMyNum(); // Reload to get most recent data
populateNumDataTable();
}
return numDataTable;
}
public List<List<Integer>> getMyNum() {
return myNum;
}
public List<List<String>> getMyHeader() {
return myHeader;
}
public List<List<String>> getMyList() {
return myList;
}
// Setters
public void setDynamicDataTable(HtmlDataTable dynamicDataTable) {
this
}
public void setHeaderDataTable(HtmlDataTable headerDataTable) {
this
}
public void setMyHeader(List<List<String>> myHeader) {
this
}
public void setNumDataTable(HtmlDataTable numDataTable) {
this
}
public void setMyNum(List<List<Integer>> myNum) {
this
}
public void setMyList(List<List<String>> myList) {
this
}
}
faces
<?xml version=
<!DOCTYPE faces
<faces
<managed
<managed
<managed
<managed
</managed
</faces
styles
border: thin solid black;
}
text
font
color: Snow;
font
background: Teal;
}
text
font
background: #F
}
text
font
background: white;
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26840.html