Hi!
I know that there have been a lot of questions
regarding the dataTable, but I still can't get mine to
work.
I have a table which looks like
this:
<x:dataTable
id="pubTable"
styleClass="publicationTable"
headerClass="publicationTable_SortHeader"
rowClasses="publicationTable_row1,publicationTable_row2"
var="publication"
value="#{publicationsBean.publicationModel}"
sortColumn="#{publicationsBean.sort}"
sortAscending="#{publicationsBean.ascending}"
preserveDataModel="true"
preserveSort="true">
<h:column>
<f:facet name="header">
<h:panelGroup></h:panelGroup>
</f:facet>
<h:graphicImage alt="#{pubmgr_messages['alt_validated']}"
url="">
</h:graphicImage>
</h:column>
<h:column>
<f:facet name="header">
<x:commandSortHeader columnName="code" arrow="true">
<h:outputText value="Code" />
</x:commandSortHeader>
</f:facet>
<x:commandLink action="" immediate="true" styleClass="publication_select">
<x:outputText value="#{publication.code}" />
</x:commandLink>
</h:column>
<h:column>
<f:facet name="header">
<x:commandSortHeader columnName="name" arrow="true">
<h:outputText value="Name" />
</x:commandSortHeader>
</f:facet>
<h:outputText value="#{publication.names['en']}" />
</h:column>
</x:dataTable>
styleClass="publicationTable"
headerClass="publicationTable_SortHeader"
rowClasses="publicationTable_row1,publicationTable_row2"
var="publication"
value="#{publicationsBean.publicationModel}"
sortColumn="#{publicationsBean.sort}"
sortAscending="#{publicationsBean.ascending}"
preserveDataModel="true"
preserveSort="true">
<h:column>
<f:facet name="header">
<h:panelGroup></h:panelGroup>
</f:facet>
<h:graphicImage alt="#{pubmgr_messages['alt_validated']}"
url="">
</h:graphicImage>
</h:column>
<h:column>
<f:facet name="header">
<x:commandSortHeader columnName="code" arrow="true">
<h:outputText value="Code" />
</x:commandSortHeader>
</f:facet>
<x:commandLink action="" immediate="true" styleClass="publication_select">
<x:outputText value="#{publication.code}" />
</x:commandLink>
</h:column>
<h:column>
<f:facet name="header">
<x:commandSortHeader columnName="name" arrow="true">
<h:outputText value="Name" />
</x:commandSortHeader>
</f:facet>
<h:outputText value="#{publication.names['en']}" />
</h:column>
</x:dataTable>
The table is rendered to
this:
<table id="pubForm:pubTable"
class="publicationTable">
<thead>
<thead>
<tr><th
class="publicationTable_SortHeader"></th><th
class="publicationTable_SortHeader"><a href=""
id="pubForm:pubTable:_id11">Code</a></th><th
class="publicationTable_SortHeader"><a href=""
id="pubForm:pubTable:_id16">Name↓</a></th></tr></thead>
<tbody>
<tr class="publicationTable_row1"><td><img id="pubForm:pubTable:_id9" src="" alt="validate status"/></td><td><a href="" id="pubForm:pubTable:_id13" class="publication_select">testcode1</a></td><td>testname1</td></tr>
<tr class="publicationTable_row2"><td><img id="pubForm:pubTable:_id9" src="" alt="validate status"/></td><td><a href="" id="pubForm:pubTable:_id13" class="publication_select">testcode2</a></td><td>testname2</td></tr>
<tr class="publicationTable_row1"><td><img id="pubForm:pubTable:_id9" src="" alt="validate status"/></td><td><a href="" id="pubForm:pubTable:_id13" class="publication_select">testcode3</a></td><td>testname3</td></tr>
<tr class="publicationTable_row2"><td><img id="pubForm:pubTable:_id9" src="" alt="validate status"/></td><td><a href="" id="pubForm:pubTable:_id13" class="publication_select">testcode4</a></td><td>testname4</td></tr><tbody></table>
<tbody>
<tr class="publicationTable_row1"><td><img id="pubForm:pubTable:_id9" src="" alt="validate status"/></td><td><a href="" id="pubForm:pubTable:_id13" class="publication_select">testcode1</a></td><td>testname1</td></tr>
<tr class="publicationTable_row2"><td><img id="pubForm:pubTable:_id9" src="" alt="validate status"/></td><td><a href="" id="pubForm:pubTable:_id13" class="publication_select">testcode2</a></td><td>testname2</td></tr>
<tr class="publicationTable_row1"><td><img id="pubForm:pubTable:_id9" src="" alt="validate status"/></td><td><a href="" id="pubForm:pubTable:_id13" class="publication_select">testcode3</a></td><td>testname3</td></tr>
<tr class="publicationTable_row2"><td><img id="pubForm:pubTable:_id9" src="" alt="validate status"/></td><td><a href="" id="pubForm:pubTable:_id13" class="publication_select">testcode4</a></td><td>testname4</td></tr><tbody></table>
The publicationsBean backing bean has the following
setters/getters:
public DataModel getPublicationModel()
{
if (this.publicationModel == null)
{
this.publicationModel = new ListDataModel();
}
if (this.sortablePublications == null)
{
this.sortablePublications = new SortablePublicationList(loadPublications());
}
this.publicationModel.setWrappedData(this.sortablePublications.getPublications()); <--- so I just put a list of Publications in the DataModel
this.publicationModel.addDataModelListener(new DataModelListener()
{
public void rowSelected(DataModelEvent e)
{
System.out.println("row selected:" + e.getRowIndex()); <----- clicking on a link in the table activates this for the whole column?!
}
});
return this.publicationModel;
}
public void setPublicationModel(DataModel dataModel)
{
this.publicationModel = dataModel;
}
{
if (this.publicationModel == null)
{
this.publicationModel = new ListDataModel();
}
if (this.sortablePublications == null)
{
this.sortablePublications = new SortablePublicationList(loadPublications());
}
this.publicationModel.setWrappedData(this.sortablePublications.getPublications()); <--- so I just put a list of Publications in the DataModel
this.publicationModel.addDataModelListener(new DataModelListener()
{
public void rowSelected(DataModelEvent e)
{
System.out.println("row selected:" + e.getRowIndex()); <----- clicking on a link in the table activates this for the whole column?!
}
});
return this.publicationModel;
}
public void setPublicationModel(DataModel dataModel)
{
this.publicationModel = dataModel;
}
private List loadPublications()
{
<return a List of Publication>
}
{
<return a List of Publication>
}
public String getSort()
{
if (this.sortablePublications == null)
{
this.sortablePublications = new SortablePublicationList(loadPublications());
}
return this.sortablePublications.getSort();
}
{
if (this.sortablePublications == null)
{
this.sortablePublications = new SortablePublicationList(loadPublications());
}
return this.sortablePublications.getSort();
}
public void setSort(String sort)
{
this.sortablePublications.setSort(sort);
}
{
this.sortablePublications.setSort(sort);
}
public boolean isAscending()
{
if (this.sortablePublications == null)
{
this.sortablePublications = new SortablePublicationList(loadPublications());
}
return this.sortablePublications.isAscending();
}
{
if (this.sortablePublications == null)
{
this.sortablePublications = new SortablePublicationList(loadPublications());
}
return this.sortablePublications.isAscending();
}
public void setAscending(boolean
ascending)
{
this.sortablePublications.setAscending(ascending);
}
{
this.sortablePublications.setAscending(ascending);
}
The sorting works, as it is I'm already quite happy
with the output ;-)
Yet! I can't get the id of selected Publication once
the commandLink is pressed as there seems to be a problem with the generated ids
of each row!
As far as I know, each id should be something like
pubForm:pubTable_0:_id13, pubForm:pubTable_1:_id13,
etc...?!
As all my rows have the same id (see the rendered
table), the DataModel's getDataRow() method always returns the last item from
the row (after having iterated over the whole column it
seems).
Does anyone know what my problem could
be?
The master/detail example from the myfaces examples
does get an id per row so I'm reckoning it's still
possible.
I tried using <x:updateActionListener
property="#{publicationsBean.selectedPublication}" value="#{publication}" />,
but the problem remains as the system can't differentiate between the
rows...
Many thanks in advance for any
help!!
Greetings,
Kris
Kris

