Code: Select all
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
<title>Table Example</title>
</h:head>
<h:body>
<h:form id="theForm">
<p:growl id="growl" showDetail="true"/>
<p:dataTable var="theBean" value="#{tableExample.beanList}"
id="theTable" dynamic="true" style="width: 200px" >
<p:columnGroup type="header">
<p:row></p:row>
</p:columnGroup>
<p:columns value="#{theBean.columns}" var="cols" columnIndexVar="colIdx" >
<p:commandLink update="bt" onsuccess="d1.show()">
<nobr><h:outputText value="bb #{cols} | #{theBean.columnIds[colIdx]}" /></nobr>
<f:setPropertyActionListener value="#{cols}" target="#{tableExample.selectedCell2}" />
</p:commandLink>
</p:columns>
</p:dataTable>
</h:form>
<p:dialog header="Dialog Test" widgetVar="d1" width="400" height="200">
<h:panelGrid id="bt" columns="1" style="margin-bottom:10px" >
<h:form id="dialogForm" prependId="false">
<h:panelGrid id="bt_inner" columns="2" style="margin-bottom:10px" >
<h:outputLabel for="theLimit" value="Set:" />
<h:inputText id="theLimit" value="xyz" />
<p:button value="Cancel" type="reset" oncomplete="dlg.hide()"/>
<p:commandButton value="submit" actionListener="#{tableExample.setLimit}" onclick="dlg.hide()" update="theTable"/>
</h:panelGrid>
</h:form>
</h:panelGrid>
</p:dialog>
</h:body>
</html>
Code: Select all
package demo;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
@ManagedBean
@SessionScoped
public class BeanExample {
private String col1;
private String col2;
private String id1;
private String id2;
private double limit1;
private double limit2;
private List<String> columns;
private List<String> columnIds;
public BeanExample() {
}
public BeanExample(String col1, String col2, String id1, String id2, double limit1, double limit2) {
super();
this.col1 = col1;
this.col2 = col2;
this.id1 = id1;
this.id2 = id2;
this.limit1 = limit1;
this.limit2 = limit2;
columns = new ArrayList<String>();
columns.add("col1");
columns.add("col2");
columns.add("col3");
columns.add("col4");
columnIds = new ArrayList<String>();
columnIds.add("id1");
columnIds.add("id2");
columnIds.add("id3");
columnIds.add("id4");
}
public String getCol1() {
System.out.println("...getting col1...");
return col1;
}
public void setCol1(String col1) {
System.out.println("setting col1..."+col1);
this.col1 = col1;
}
public String getCol2() {
System.out.println("...getting col2...");
return col2;
}
public void setCol2(String col2) {
this.col2 = col2;
}
public String getId1() {
return id1;
}
public void setId1(String id1) {
this.id1 = id1;
}
public String getId2() {
return id2;
}
public void setId2(String id2) {
this.id2 = id2;
}
public double getLimit1() {
return limit1;
}
public void setLimit1(double limit1) {
this.limit1 = limit1;
}
public double getLimit2() {
return limit2;
}
public void setLimit2(double limit2) {
this.limit2 = limit2;
}
public List<String> getColumns() {
System.out.println("...getting columns...");
return columns;
}
public void setColumns(List<String> columns) {
this.columns = columns;
}
public List<String> getColumnIds() {
return columnIds;
}
public void setColumnIds(List<String> columnIds) {
this.columnIds = columnIds;
}
}
Code: Select all
package demo;
import java.util.ArrayList;
import java.util.Map;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
@ManagedBean
@SessionScoped
public class TableExample {
private List<BeanExample> beanList;
private String selectedCell;
private String selectedCell2;
private double currLimit;
private String first;
private String last;
private String label;
public TableExample() {
System.out.println("initializing...");
BeanExample b1 = new BeanExample("Joe","Smith","1|a","1|b",10.5,1.2);
BeanExample b2 = new BeanExample("Dan","Jones","2|a","2|b",11.5,2.2);
BeanExample b3 = new BeanExample("Howie","Long","3|a","3|b",12.5,3.2);
BeanExample b4 = new BeanExample("Bob","Sakamano","4|a","4|b",13.5,4.2);
BeanExample b5 = new BeanExample("Jerry","Seinfeld","5|a","5|b",14.5,5.2);
BeanExample b6 = new BeanExample("George","Castanza","6|a","6|b",15.5,6.2);
BeanExample b7 = new BeanExample("Kosmo","Kramer","7|a","7|b",16.5,7.2);
beanList = new ArrayList<BeanExample>();
beanList.add(b1);
beanList.add(b2);
beanList.add(b3);
beanList.add(b4);
beanList.add(b5);
beanList.add(b6);
beanList.add(b7);
}
public List<BeanExample> getBeanList() {
System.out.println("getting beanList...");
return beanList;
}
public void setBeanList(List<BeanExample> beanList) {
this.beanList = beanList;
}
public String getSelectedCell() {
if (selectedCell != null)
System.out.println("getSelectedCell "+selectedCell);
else
System.out.println("getSelectedCell");
return selectedCell;
}
public void setSelectedCell(String selectedCell) {
if (selectedCell != null)
System.out.println("setSelectedCell "+selectedCell);
else
System.out.println("setSelectedCell");
this.selectedCell = selectedCell;
}
public String getSelectedCell2() {
if (selectedCell2 != null)
System.out.println("getSelectedCell2 "+selectedCell2);
else
System.out.println("getSelectedCell2 NULL");
return selectedCell2;
}
public void setSelectedCell2(String selectedCell2) {
if (selectedCell2 != null)
System.out.println("setSelectedCell2 "+selectedCell2);
else
System.out.println("setSelectedCell2 NULL");
this.selectedCell2 = selectedCell2;
}
public double getCurrLimit() {
currLimit = -1.0;
if (selectedCell != null) {
int idx = Integer.parseInt(selectedCell.substring(0,selectedCell.indexOf("|"))) - 1;
BeanExample b = beanList.get(idx);
String col = selectedCell.substring(selectedCell.indexOf("|")+1);
if (col.equals("a"))
currLimit = b.getLimit1();
else if (col.equals("b"))
currLimit = b.getLimit2();
System.out.println("getCurrLimit: "+currLimit+" "+b.getCol1()+" "+b.getCol2());
}
return currLimit;
}
public void setCurrLimit(double currLimit) {
this.currLimit = currLimit;
}
public String getFirst() {
if (selectedCell != null) {
int idx = Integer.parseInt(selectedCell.substring(0,selectedCell.indexOf("|"))) - 1;
BeanExample b = beanList.get(idx);
System.out.println("getFirst: "+b.getCol1());
return b.getCol1();
}
return first;
}
public void setFirst(String first) {
this.first = first;
}
public String getLast() {
if (selectedCell != null) {
int idx = Integer.parseInt(selectedCell.substring(0,selectedCell.indexOf("|"))) - 1;
BeanExample b = beanList.get(idx);
System.out.println("getLast: "+b.getCol2());
return b.getCol2();
}
return last;
}
public void setLast(String last) {
this.last = last;
}
public String getLabel() {
if (selectedCell != null) {
String col = selectedCell.substring(selectedCell.indexOf("|")+1);
System.out.println("getLabel: "+col);
if (col.equals("a"))
return "Col1";
else if (col.equals("b"))
return "Col2";
}
return label;
}
public void setLabel(String label) {
this.label = label;
}
public void setLimit() {
if (selectedCell != null)
System.out.println("setLimit cell: "+selectedCell);
else
System.out.println("setLimit NO CELL defined");
Map<String, String> requestParameterMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
if (requestParameterMap.containsKey("dialogForm:theLimit")) {
/*String limitStr = requestParameterMap.get("dialogForm:theLimit");
System.out.println("new limit: "+limitStr);
double newLimit = Double.parseDouble(limitStr);
int idx = Integer.parseInt(selectedCell.substring(0,selectedCell.indexOf("|"))) - 1;
String col = selectedCell.substring(selectedCell.indexOf("|")+1);
BeanExample b = beanList.get(idx);
if (col.equals("a"))
b.setLimit1(newLimit);
else if (col.equals("b"))
b.setLimit2(newLimit);*/
}
}
}