On Tue, 31 May 2005 15:35:05 +0200, "Kris Verhoye" <[EMAIL PROTECTED]> wrote :
> This is a multi-part message in MIME format. > > > 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="#{publicationsBean.validated == > 'true' ? pubmgr_messages['img_greenlight'] : > pubmgr_messages['img_redlight']}"> > </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="#{publicationsBean.goToPublicationDetail}" 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> > > <tr><th class="publicationTable_SortHeader"></th><th > class="publicationTable_SortHeader"><a href="#" > onclick="clear_pubForm();document.forms['pubForm'].elements['autoScroll' > ].value=getScrolling();document.forms['pubForm'].elements['pubForm:_link > _hidden_'].value='pubForm:pubTable:_id11';if(document.forms['pubForm'].o > nsubmit){document.forms['pubForm'].onsubmit();}document.forms['pubForm'] > .submit();return false;" id="pubForm:pubTable:_id11">Code</a></th><th > class="publicationTable_SortHeader"><a href="#" > onclick="clear_pubForm();document.forms['pubForm'].elements['autoScroll' > ].value=getScrolling();document.forms['pubForm'].elements['pubForm:_link > _hidden_'].value='pubForm:pubTable:_id16';if(document.forms['pubForm'].o > nsubmit){document.forms['pubForm'].onsubmit();}document.forms['pubForm'] > .submit();return false;" > id="pubForm:pubTable:_id16">Name↓</a></th></tr></thead> > <tbody> > <tr class="publicationTable_row1"><td><img id="pubForm:pubTable:_id9" > src="/pubmgr/images/redlight.gif" alt="validate status"/></td><td><a > href="#" > onclick="clear_pubForm();document.forms['pubForm'].elements['autoScroll' > ].value=getScrolling();document.forms['pubForm'].elements['pubForm:_link > _hidden_'].value='pubForm:pubTable:_id13';if(document.forms['pubForm'].o > nsubmit){document.forms['pubForm'].onsubmit();}document.forms['pubForm'] > .submit();return false;" 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="/pubmgr/images/redlight.gif" alt="validate status"/></td><td><a > href="#" > onclick="clear_pubForm();document.forms['pubForm'].elements['autoScroll' > ].value=getScrolling();document.forms['pubForm'].elements['pubForm:_link > _hidden_'].value='pubForm:pubTable:_id13';if(document.forms['pubForm'].o > nsubmit){document.forms['pubForm'].onsubmit();}document.forms['pubForm'] > .submit();return false;" 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="/pubmgr/images/redlight.gif" alt="validate status"/></td><td><a > href="#" > onclick="clear_pubForm();document.forms['pubForm'].elements['autoScroll' > ].value=getScrolling();document.forms['pubForm'].elements['pubForm:_link > _hidden_'].value='pubForm:pubTable:_id13';if(document.forms['pubForm'].o > nsubmit){document.forms['pubForm'].onsubmit();}document.forms['pubForm'] > .submit();return false;" 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="/pubmgr/images/redlight.gif" alt="validate status"/></td><td><a > href="#" > onclick="clear_pubForm();document.forms['pubForm'].elements['autoScroll' > ].value=getScrolling();document.forms['pubForm'].elements['pubForm:_link > _hidden_'].value='pubForm:pubTable:_id13';if(document.forms['pubForm'].o > nsubmit){document.forms['pubForm'].onsubmit();}document.forms['pubForm'] > .submit();return false;" id="pubForm:pubTable:_id13" > class="publication_select">testcode4</a></td><td>testname4</td></tr><tbo > dy></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.getPublic > ations()); <--- 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> > } > > public String getSort() > { > if (this.sortablePublications == null) > { > this.sortablePublications = new > SortablePublicationList(loadPublications()); > } > return this.sortablePublications.getSort(); > } > > public void setSort(String sort) > { > this.sortablePublications.setSort(sort); > } > > public boolean isAscending() > { > if (this.sortablePublications == null) > { > this.sortablePublications = new > SortablePublicationList(loadPublications()); > } > return this.sortablePublications.isAscending(); > } > > public void setAscending(boolean 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 > > Hi Kris, Have you tried passing a param with a unique identifier for the row and using an actionlistener to get the selected row? -Mark