-
1. Selection gives wrong key to backing bean
nimoh Apr 20, 2011 5:49 PM (in response to nimoh)<rich:extendedDataTable width="#{participationStatusHandler.tableWidth}px" height="489px"
id="SubjectTable"
value="#{participationStatusHandler.subjectDataModel}"
var="subjectRow" rows="12" reRender="bottomScroller"
sortMode="single" selectionMode="single"
selection="#{participationStatusHandler.selectedParticipant}"
tableState="#{participationStatusHandler.tableState}"
noDataLabel="#{messages['txtParticipantsNoResults']}"
rowClasses="standardTable_Row1, standardTable_Row2"
styleClass="standard"
onRowMouseOver="mouseOverTableRow(this)"
onRowMouseOut="mouseOutTableRow(this)"
onRowClick="selectedTableRow=this;clickTableRow(event)"
renderIfSinglePage="true" headerClass="subjectTableHeader">
<a4j:support event="onselectionchange" action="#{participationStatusHandler.takeSelection}"/>
...
</rich:extendedDataTable>
<rich:datascroller align="center" for="SubjectTable" styleClass="paginator"
id="bottomScroller" ajaxSingle="false"/>
-
2. Selection gives wrong key to backing bean
nimoh Apr 20, 2011 5:55 PM (in response to nimoh)public ExtendedTableDataModel<ParticipationStatusBean> getSubjectDataModel() {
if (subjectDataModel == null) {
subjectDataModel = new ExtendedTableDataModel<ParticipationStatusBean>(
new DataProvider<ParticipationStatusBean>() {
private static final long serialVersionUID = 6868890472318L;
public ParticipationStatusBean getItemByKey(Object key) {
for (ParticipationStatusBean b : participants) {
if (key.equals(getKey(b))) {
return b;
}
}
return null;
}
public List<ParticipationStatusBean> getItemsByRange(int firstRow, int endRow) {
return participants.subList(firstRow, endRow);
}
public Object getKey(ParticipationStatusBean b) {
return b.getKey();
}
public int getRowCount() {
return participants.size();
}
});
subjectDataModel.setRowIndex(-1);
}
return subjectDataModel;
}
public List<ParticipationStatusBean> getParticipants() {
return participants;
}
public void setParticipants(List<ParticipationStatusBean> participants) {
this.participants = participants;
}
public Object getTableState() {
return tableState;
}
public void setTableState(Object tableState) {
this.tableState = tableState;
}
public void takeSelection() {
this.clickedBean = null;
Iterator<Object> iterator = this.getSelectedParticipant().getKeys();
while (iterator.hasNext()) {
Object key = iterator.next();
getSubjectDataModel().setRowKey(key);
this.clickedBean = getSubjectDataModel().getRowData();
}
}
public ParticipationStatusBean getClickedBean() {
return this.clickedBean;
}
public SimpleSelection getSelectedParticipant() {
if(this.selectedParticipant == null) {
this.selectedParticipant = new SimpleSelection();
}
return this.selectedParticipant;
}
public void setSelectedParticipant(SimpleSelection selectedParticipant) {
this.selectedParticipant = selectedParticipant;
}
-
3. Selection gives wrong key to backing bean
ilya_shaikovsky Apr 21, 2011 4:30 AM (in response to nimoh)sorry but it works for me If I'm just adding dataScroller to our 3.3.3.Final demo:
public class ExtendedTableBean {
private String sortMode = "single";
private String selectionMode = "multi";
private Object tableState;
private Selection selection = new SimpleSelection();
private List<Capital> capitals = new ArrayList<Capital>();
private ExtendedTableDataModel<Capital> dataModel;
private List<Capital> selectedCapitals = new ArrayList<Capital>();
public String getSortMode() {
return sortMode;
}
public void setSortMode(String sortMode) {
this.sortMode = sortMode;
}
public String getSelectionMode() {
return selectionMode;
}
public void setSelectionMode(String selectionMode) {
this.selectionMode = selectionMode;
}
public ExtendedTableBean() {
}
public void takeSelection() {
selectedCapitals.clear();
Iterator<Object> iterator = getSelection().getKeys();
while (iterator.hasNext()) {
Object key = iterator.next();
getCapitalsDataModel().setRowKey(key);
selectedCapitals.add(getCapitalsDataModel().getRowData());
}
}
public ExtendedTableDataModel<Capital> getCapitalsDataModel() {
if (dataModel == null) {
dataModel = new ExtendedTableDataModel<Capital>(new DataProvider<Capital>() {
private static final long serialVersionUID = 5054087821033164847L;
public Capital getItemByKey(Object key) {
for (Capital c : capitals) {
if (key.equals(getKey(c))) {
return c;
}
}
return null;
}
public List<Capital> getItemsByRange(int firstRow, int endRow) {
return capitals.subList(firstRow, endRow);
}
public Object getKey(Capital item) {
return item.getName();
}
public int getRowCount() {
return capitals.size();
}
});
}
return dataModel;
}
and
<rich:extendedDataTable rows="#{10}"
value="#{extendedTableBean.capitalsDataModel}" var="cap" id="table"
width="580px" height="400px"
sortMode="#{extendedTableBean.sortMode}"
selectionMode="#{extendedTableBean.selectionMode}"
tableState="#{extendedTableBean.tableState}"
selection="#{extendedTableBean.selection}">
<rich:column sortable="false" label="Flag" id="col_1">
<f:facet name="header">
<h:outputText value="Flag" id="flag"/>
</f:facet>
<h:graphicImage value="#{cap.stateFlag}" id="cap_state_flag"/>
</rich:column>
<rich:column sortable="true" sortBy="#{cap.state}" id="col_2"
filterBy="#{cap.state}" filterEvent="onkeyup" width="170px"
label="State Name">
<f:facet name="header">
<h:outputText value="State Name" id="state_name"/>
</f:facet>
<h:outputText value="#{cap.state}" id="cap_state"/>
</rich:column>
<rich:column sortable="true" sortBy="#{cap.name}" id="col_3"
filterBy="#{cap.name}" filterEvent="onkeyup" width="170px"
label="State Capital">
<f:facet name="header">
<h:outputText value="State Capital" id="state_capital"/>
</f:facet>
<h:outputText value="#{cap.name}" id="cap_name"/>
</rich:column>
<rich:column sortable="false" label="Time Zone" id="col_4">
<f:facet name="header">
<h:outputText value="Time Zone" id="time_zone"/>
</f:facet>
<h:outputText value="#{cap.timeZone}" id="cap_time_zone"/>
</rich:column>
<a4j:support reRender="selectiontable" id="extended_table_bean_take_selection"
action="#{extendedTableBean.takeSelection}"
event="onselectionchange" />
<f:facet name="footer">
<rich:datascroller></rich:datascroller>
</f:facet>
</rich:extendedDataTable>
-
4. Selection gives wrong key to backing bean
nimoh Apr 21, 2011 9:07 AM (in response to ilya_shaikovsky)The only difference I see is that your data scroller is in the footer of the table, while mine uses the "for" attribute. Not sure if that would make a difference.
Anyway, since posting, I have gone a different route. I am manually setting the selected row by passing the key of the selected row to a javascript function that sets it on the backing bean. I am then waiting for this operation to complete before allowing the user to take action that would require the selection to be set on the backing bean.