[
http://jira.jboss.com/jira/browse/RF-3364?page=all ]
Konstantin Mishin resolved RF-3364.
-----------------------------------
Fix Version/s: 3.2.1
(was: Future)
Resolution: Duplicate Issue
Assignee: Tsikhon Kuprevich (was: Konstantin Mishin)
Use column.setValueExpression("sortBy", valueExpression);
instead of column.setSortBy(valueExprs[i]);
Programmatically created dataTable is not sortable
--------------------------------------------------
Key: RF-3364
URL:
http://jira.jboss.com/jira/browse/RF-3364
Project: RichFaces
Issue Type: Bug
Affects Versions: 3.2.1
Environment: RichFaces 3.2.1.CR3
JBoss Seam 2.0.1.GA
JSF 1.2 + Facelets 1.1.14
JBoss 4.2.2.GA
JDK 1.5.0_11
Reporter: Rainer Flicker
Assigned To: Tsikhon Kuprevich
Fix For: 3.2.1
Attachments: DataTableAction.java, TestEntity.java
A programmatically created dataTable shows no sort icons in the header and clicking on
the header
has no effect.
------ xhtml snippet
---------------------------------------------------------------------------------------------------
<rich:dataTable binding="#{dataTableAction.dataTable}" var="data"
/>
-----------------------------------------------------------------------------------------------------------------------------
----- faces-config.xml snippet
-------------------------------------------------------------------------------------
<managed-bean>
<managed-bean-name>dataTableAction</managed-bean-name>
<managed-bean-class>DataTableAction</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
-----------------------------------------------------------------------------------------------------------------------------
---- Java class
---------------------------------------------------------------------------------------------------------
import java.util.ArrayList;
import java.util.List;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.application.Application;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.context.FacesContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.richfaces.component.html.HtmlColumn;
import org.richfaces.component.html.HtmlDataTable;
public class DataTableAction {
private Log log = LogFactory.getLog(DataTableAction.class);
private HtmlDataTable dataTable = null;
private List<TestEntity> testData = null;
public HtmlDataTable getDataTable() {
log.info("in getDataTable()");
if (testData == null) {
testData = new ArrayList<TestEntity>();
for (int i = 0; i < 10; i++) {
TestEntity data = new TestEntity();
data.setId(i);
data.setName("TestEntity" + i);
data.setNumber(""+i);
testData.add(data);
}
}
String[] columns = new String[] { "number", "name" };
String[] valueExprs = new String[] { "#{data.number}",
"#{data.name}" };
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
Application application = facesContext.getApplication();
ExpressionFactory elFactory =
facesContext.getApplication().getExpressionFactory();
dataTable = new HtmlDataTable();
dataTable.setValue(getTestData());
for (int i = 0; i < columns.length; i++) {
log.info("setting column[" + i + "]: " + columns[i]);
// header
HtmlOutputText header = new HtmlOutputText();
header.setValue(columns[i]);
// content
HtmlOutputText content = new HtmlOutputText();
ValueExpression valueExpression = elFactory.createValueExpression(
elContext, valueExprs[i], String.class);
content.setValueExpression("value", valueExpression);
// column
HtmlColumn column = new HtmlColumn();
column.setId("col" + i);
column.setHeader(header);
column.getChildren().add(content);
column.setSortBy(valueExprs[i]);
column.setSortable(true);
column.setSelfSorted(true);
dataTable.getChildren().add(column);
}
return dataTable;
}
public void setDataTable(HtmlDataTable dataTable) {
this.dataTable = dataTable;
}
public List<TestEntity> getTestData() {
return testData;
}
public void setTestData(List<TestEntity> testData) {
this.testData = testData;
}
}
-----------------------------------------------------------------------------------------------------------------------------
---- Java class
---------------------------------------------------------------------------------------------------------
public class TestEntity {
private long id;
private String number;
private String name;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
-----------------------------------------------------------------------------------------------------------------------------
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira