• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

DataModel in Jsf

 
Ranch Hand
Posts: 55
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

How can I refer to a column in DataModel object?
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Saloon Keeper
Posts: 24283
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Nipun Bahr
Ranch Hand
Posts: 55
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Thanks Rok and Tim for the reply.

Rok I want to refer to a column in the row.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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">
<h:outputText value="2nd Column Header" />
</f:facet>
<!-- value of 2nd column -->
<h:outputText 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();
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic