-
1. Re: Set rows in extendedDataTable as selected from backing bean
derkd Sep 20, 2011 7:18 AM (in response to derkd)Here a piece of my code. This works, I see the "rowdata equals object" log statement but now I need to say to the row "selected" but there isn't a method for that as far as I know...
public void selectRows(){
Collection<Object> s = new ArrayList<Object>(getGroups());
log.debug("set the selection to the table");
table.getTable().walk(FacesContext.getCurrentInstance(), new DataVisitor() {
@Override
public DataVisitResult process(FacesContext context, Object rowKey,
Object argument) {
log.debug("entered walk");
Collection<Object> selection = (Collection<Object>) argument;
for(Object o : selection){
table.getTable().setRowKey(rowKey);
if(table.getTable().getRowData().equals(o)){
log.debug("rowdata equals object");
table.getTable().getSelection().add(o);
log.debug("size of selection is: " + table.getTable().getSelection().size());
}
}
table.getTable().setRowKey(rowKey);
return null;
}
}, s );
}
-
2. Re: Set rows in extendedDataTable as selected from backing bean
ilya_shaikovsky Sep 20, 2011 11:57 AM (in response to derkd)1 of 1 people found this helpfulcheck the example there. http://richfaces-showcase.appspot.com/richfaces/component-sample.jsf?demo=extendedDataTable&sample=exTableSelection&skin=blueSky
As you could see selection attribute bound to list of rowKeys, So just add the rowKeys of rows which should be selected initially to that collection.
-
3. Re: Set rows in extendedDataTable as selected from backing bean
derkd Sep 21, 2011 4:34 AM (in response to ilya_shaikovsky)Ilya,
Thank you for your response. I copied the example and changed it a bit. Now the example works. Next I need to implement this in my app. The problem is as follows.
I have a list with groups which is loaded in the datatable. Right before the page is displayed I fire a page action (with pretty faces) which loads the user info. In this user info I get a list with groups. The groups in that list needs to compared with the list in the datatable. If a group in the user list matches against the list in the table I add the rowkey to the selection list. See below:
public void selectRows(){
log.debug("entered selectRows");
user = findById(WnrExtranetUser.class, user.getWnrExtranetUserId());
Collection<Object> userGroups = new ArrayList<Object>(user.getWnrExtranetGroups());
log.debug("set the selection to the table");
selection = new ArrayList<Object>();
if(table != null) {
log.debug("table is not null");
if(table.getTable() != null) {
log.debug("table.getTable is not null");
table.getTable().walk(FacesContext.getCurrentInstance(), new DataVisitor() {
@Override
public DataVisitResult process(FacesContext context, Object rowKey,
Object argument) {
log.debug("entered walk");
Collection<Object> userGroups = (Collection<Object>) argument;
for(Object userGroup : userGroups){
table.getTable().setRowKey(rowKey);
if(table.getTable().getRowData().equals(userGroup)){
log.debug("rowdata equals object");
// table.getTable().getSelection().add(userGroup);
// log.debug("size of selection is: " + table.getTable().getSelection().size());
selection.add(rowKey);
selectionItems.add((WnrExtranetGroup)userGroup);
}
}
table.getTable().setRowKey(rowKey);
return null;
}
}, userGroups );
}
}
}
When I fire this method in a page action with pretty faces the table.getTable() == null. If a fire this method after the page is shown on screen with a commandButton the row in the table is selected.
How can I fix this so that the method is fired on page load and the table.getTable isn't null anymore???
btw I went wrong with the selection on the server by calling table.getTable().getSelection().add(userGroup); instead of adding the rowKey to the selection attribute in the class which it was bind to... Why use Object and not Integer for the rowKey? Eventually it is cast to an Integer...
-
4. Re: Set rows in extendedDataTable as selected from backing bean
derkd Sep 21, 2011 5:25 AM (in response to derkd)I solved it by calling the selectRows method in a
<f:event type="preRenderView" listener="#{newExtranetUserAction.selectRows}" />
that works!
But I'm still curious why the table.getTable() resolves to null when using the page action with pretty faces.