This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSF and the fly likes DataModel in Jsf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "DataModel in Jsf" Watch "DataModel in Jsf" New topic
Author

DataModel in Jsf

Nipun Bahr
Ranch Hand

Joined: Jul 09, 2008
Posts: 55

Hi All,

How can I refer to a column in DataModel object?
Rok Koncina
Greenhorn

Joined: Nov 30, 2011
Posts: 5
Hello,

DataModel represents only rows. Each row is an entry, usually an instance of a class or array of data.
Column represents certain data (usually field) of every entry.

What do you want to do with a column?
Do you want to refer to the whole column or just one column in one row?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15960
    
  19

You cannot refer to a DataModel column as a unit, because the major dimension for dataModel is row, nor column.

However an individual cell within a DataModel row is accessed as a property of the row object.


Customer surveys are for companies who didn't pay proper attention to begin with.
Nipun Bahr
Ranch Hand

Joined: Jul 09, 2008
Posts: 55



Thanks Rok and Tim for the reply.

Rok I want to refer to a column in the row.
David Cheng-Hk
Greenhorn

Joined: Dec 02, 2011
Posts: 2
Define your own data table like this:

DataColumn : class represents a single column in a rowset
DataRow: ArrayList<DataColumn> will represent a rowset
DataTable: ArrayList<DataRow> will represent a list of rowset, i.e. a data table

in each class, have those getter/setter ready to provide access to each column/row

assuming you have MyFaces Tomahawk:
then bind the <t:dataTable> to the datatable implementation in your backing bean
<t:dataTable id="mydataTable" border="1" cellspacing="5"
binding="#{myBean.myDataTable}" var="myDT"
rowIndexVar="rowIndex"
rowStyleClass="#{(rowIndex % 2 == 1 ? 'odd' : 'even')}">
<!-- first column -->
<t:column>
<!-- header of first column -->
<f:facet name="header">
<t:selectBooleanCheckbox id="cbxSelectAll"
binding="#{myBean.cbxSelectAll}"
onclick="selectAll(this, 'cbxChecked')" />
</f:facet>
<!-- value of first column -->
<t:selectBooleanCheckbox id="cbxChecked"
value="#{myBean.selectedIds[myDT.myColumnName]}" />
</t:column>
<!-- 2nd column -->
<t:column>
<!-- header of 2nd column -->
<f:facet name="header">
<hutputText value="2nd Column Header" />
</f:facet>
<!-- value of 2nd column -->
<hutputText value="#{myDT.myColumnName}" />
</t:column>
...
</t:dataTable>

in the backing bean:
HtmlSelectBooleanCheckbox cbxSelectAll; to keep track if the "select all" checkbox has been checked
Map<Integer, Boolean> selectedIds; Map to keep track which item has been selected
HtmlDataTable myDataTable = new HtmlDataTable();
 
Consider Paul's rocket mass heater.
 
subject: DataModel in Jsf
 
Similar Threads
Jtable sorting; problem with getValueAt
How to access the current row index in dataTable
How to pass parameter to h:commandButton
jsf data table
Design Approach - All SCEA's plz comment