-
1. Re: rich:scrollableDatatable : selection after sorting does not working!
ilya_shaikovsky Aug 5, 2010 7:19 AM (in response to yshashidhar)you encountering the same issue which present at online demo for now livedemo.exadel.com/richfaces-demo/richfaces/scrollableDataTable.jsf.
And ther reason is correction made by my mistake in demo code https://jira.jboss.org/browse/RF-8206 . The reason is simple - selection contains rowIndexes and if you will get the items not from wrapped model but from your original list - it returns still the objects which corresponds to indexes without sorting applied (RF not updates the model itself but just return wrapped modified model for representation).
Two solutions there:
1) use binding. getRowData using the index from the component. (Previously was implemented in this way but I prefer not to deal with component bindings so simplified the code and forgot about that sorting problem )
2) wrap the model as done there http://livedemo.exadel.com/richfaces-demo/richfaces/extendedDataTable.jsf. so as you could see it works correctly and additionally not deals with component instance but just gets the object from the model.
check full demo code following http://jboss.org/richfaces/demos
-
2. Re: rich:scrollableDatatable : selection after sorting does not working!
yshashidhar Aug 5, 2010 8:11 AM (in response to ilya_shaikovsky)Thank you very much for the reply...
I tried this at my method:
Iterator<Object> iterator = selection.getKeys();
insepctionCharactersticsList = new ArrayList<InspectionCharacteristics>();
Object obj = iterator.next();
Integer key = (Integer)obj;
System.out.println(inspectionPlanList.get(key).getGroup());But still I see the key in output is referring wrong id. Any help please..!
Also, the link you gave for extendeddatatable is not opening. It seems javascript is not working, can you share that code with me here?
Appreciate your further responses.
Cheers,
Shashi
-
3. Re: rich:scrollableDatatable : selection after sorting does not working!
ilya_shaikovsky Aug 5, 2010 10:09 AM (in response to yshashidhar)For the second question about ExtendedDataTable way - you could check full richfaces-demo sources there http://anonsvn.jboss.org/repos/richfaces/branches/community/3.3.X/samples/richfaces-demo/
And about the previous SDT code (thus I still prefer not to use binding and use the EDT sample way)
public String takeSelection() { getSelectedCars().clear(); if (getSelection().isSelectAll()) { getSelectedCars().addAll(allCars); } else { Iterator<Object> iterator = getSelection().getKeys(); while (iterator.hasNext()) { Object key = iterator.next(); table.setRowKey(key); if (table.isRowAvailable()) { getSelectedCars().add( (DemoInventoryItem) table.getRowData()); } } } return null; }
where table - SDT component instance passed using binding
-
4. Re: rich:scrollableDatatable : selection after sorting does not working!
yshashidhar Aug 6, 2010 12:42 AM (in response to ilya_shaikovsky)Thanks for helping me out...
I think I am missing something here. Please check whether I am going in right direction.
I have below Bean instance variables declared -
public class QualityInspectionPlan {
...
private ArrayList<InspectionPlan> inspectionPlanList = new ArrayList<InspectionPlan>();
private SimpleSelection selection;
...}
And scrollabaledataTable mapped to -
ArrayList<InspectionPlan> inspectionPlanList;
My xhtml Code -
<rich:scrollableDataTable id="QIP_inspectionPlanTable" value="#{qualityIP.inspectionPlanList}"
var="insPlan"
onRowDblClick="#{qualityIP.fetchInsChars()}"
selection="#{qualityIP.selection}" rowKeyVar="rkv" sortMode="single">
<a4j:support event="onRowDblClick" reRender="QIP_inspectionCharTable"
action="#{qualityIP.fetchInsChars()}"/>....
And I am calling fetchInsChars() method inside my bean which has below code -
Iterator<Object> iterator = getSelection().getKeys();
Object obj = iterator.next();
Integer key = (Integer)obj;
System.out.println(inspectionPlanList.get(key).getGroup());Now the question to me is, when you say "
table.setRowKey(key);
" what does the table mean.In my case I want to set the row key to ArrayList<InspectionPlan>.
Thanks in advance for your help
Cheers,
Shashi
-
5. Re: rich:scrollableDatatable : selection after sorting does not working!
yshashidhar Aug 6, 2010 6:59 AM (in response to yshashidhar)Any one please...!
-
6. Re: rich:scrollableDatatable : selection after sorting does not working!
yshashidhar Aug 9, 2010 12:41 AM (in response to yshashidhar)I tried having one new method as below -
public ScrollableTableDataModel<InspectionPlan> getInspectionDataModel(){ if (dataModel == null) { dataModel = new ScrollableTableDataModel<InspectionPlan>(new DataProvider<InspectionPlan>(){ private static final long serialVersionUID = 5054087821033164847L; public InspectionPlan getItemByKey(Object key) { for(InspectionPlan c : inspectionPlanList){ if (key.equals(getKey(c))){ return c; } } return null; } public List<InspectionPlan> getItemsByRange(int firstRow, int endRow) { return inspectionPlanList.subList(firstRow, endRow); } public Object getKey(InspectionPlan item) { return item.getGroup(); } public int getRowCount() { return inspectionPlanList.size(); } }); } return dataModel; }
And I have declared dataModel as below
private ScrollableTableDataModel<InspectionPlan> dataModel;
unfortunately, I couldn't instantiate dataModel with scrollableTableDataModel.. I see below error -
"Cannot instantiate the type ScrollableTableDataModel<InspectionPlan>"
Any suggetions please...?
-
7. Re: rich:scrollableDatatable : selection after sorting does not working!
ilya_shaikovsky Aug 9, 2010 3:57 AM (in response to yshashidhar)And I am calling fetchInsChars() method inside my bean which has below code -
Iterator<Object> iterator = getSelection().getKeys();
Object obj = iterator.next();
Integer key = (Integer)obj;
System.out.println(inspectionPlanList.get(key).getGroup());Now the question to me is, when you say "
table.setRowKey(key);
" what does the table mean.In my case I want to set the row key to ArrayList<InspectionPlan>.
table is UIComponent instance of the data table in my code. And you still trying to work with original list.
P.S. If you will choose to use dataModel as in last coment - please use modifiable model and not scrollableTableDataModel(it was used in the past and then we made SDT component compatible with our standard extended and modifiable models).
-
8. Re: rich:scrollableDatatable : selection after sorting does not working!
ilya_shaikovsky Aug 9, 2010 3:59 AM (in response to yshashidhar)I see below error -
"Cannot instantiate the type ScrollableTableDataModel<InspectionPlan>"
please post complete exceptions in such cases.
And b.t.w. please just try to checkout richfaces-demo and use extendedDataTable example for check (just change the table to SDT there and all should works out of the box.)
-
9. Re: rich:scrollableDatatable : selection after sorting does not working!
yshashidhar Aug 9, 2010 4:06 AM (in response to ilya_shaikovsky)Hi, thanks for the reply...
That was a compilation error... and I wrote my code as below
public ScrollableTableDataModel<InspectionPlan> getInspectionDataModel(){ if (dataModel == null) { dataModel = new ScrollableTableDataModel<InspectionPlan>(new DataProvider<InspectionPlan>(){ private static final long serialVersionUID = 5054087821033164847L; public InspectionPlan getItemByKey(Object key) { for(InspectionPlan c : inspectionPlanList){ if (key.equals(getKey(c))){ return c; } } return null; } public List<InspectionPlan> getItemsByRange(int firstRow, int endRow) { return inspectionPlanList.subList(firstRow, endRow); } public Object getKey(InspectionPlan item) { return item.getGroup(); } public int getRowCount() { return inspectionPlanList.size(); } }); } return dataModel; }
the idea I will use above method as below (if it works fine).
while (iterator.hasNext()) { Object key = iterator.next(); System.out.println(getCapitalsDataModel().getObjectByKey(key).toString()); }
I haven't done anything specific here, I just used your demo classes method and modified it accordingly... Can you please cross check and let me knwo?
-
10. Re: rich:scrollableDatatable : selection after sorting does not working!
ilya_shaikovsky Aug 9, 2010 4:15 AM (in response to yshashidhar)yup, getItemByKey - should works fine for you there.
-
12. Re: rich:scrollableDatatable : selection after sorting does not working!
ilya_shaikovsky Aug 9, 2010 4:43 AM (in response to yshashidhar)As I written above please use our ExtendedDataModel or ModifiableModel as it shown at RF demo.
-
13. Re: rich:scrollableDatatable : selection after sorting does not working!
yshashidhar Aug 9, 2010 7:35 AM (in response to ilya_shaikovsky)I apologize if I am so stupid at here... but i am very new in using richafaces...
I see I manager myselft to reach almost edge with the help of you, but I am getting big fat error NullPointerException. Here is what I have done.
My xhtml piece of Code:
<rich:scrollableDataTable id="QIP_inspectionPlanTable" value="#{qualityIP.inspectionPlanList}"
var="insPlan"
onRowDblClick="#{qualityIP.fetchInsChars()}"
selection="#{qualityIP.selection}" rowKeyVar="rkv" sortMode="single">
<a4j:support event="onselectionchange" reRender="QIP_inspectionCharTable"
action="#{qualityIP.fetchInsChars()}"/>My fetchInsChars method:
Iterator<Object> iterator = getSelection().getKeys(); while (iterator.hasNext()) { Object key = iterator.next(); InspectionPlan ip = (InspectionPlan) getInspectionDataModel().getObjectById(key); if(getInspectionDataModel().getObjectById(key) != null ){ System.out.println("Success, but let's see what happens..."); System.out.println("Success, group = "+ip.getGroup()); } else System.out.println("Failed again!!! :-( , ip got null value! + "+getInspectionDataModel().getObjectById(key)); }
My getInspectionDataModel method:
public ScrollableTableDataModel<InspectionPlan> getInspectionDataModel() { if (dataModel == null) { dataModel = new ScrollableTableDataModel<InspectionPlan>() { @Override public List<InspectionPlan> loadData(int startRow, int endRow, SortOrder sortOrder) { // this method is called twice in the case of sorting: first // during decode and then during encode, with sort order if (sortOrder != null) { ScrollableTableDataModel sortableModel = new org.richfaces.model.internal.ComponentSortableDataModel( "rowId", inspectionPlanList, sortOrder); return sortableModel.loadData(startRow, endRow, sortOrder); } return inspectionPlanList; } @Override public int getRowCount() { if (inspectionPlanList != null) { return inspectionPlanList.size(); } return 0; } @Override public Object getWrappedData() { throw new UnsupportedOperationException(); } @Override public void setWrappedData(Object data) { throw new UnsupportedOperationException(); } }; } return dataModel; }
And the error :
16:41:03,847 INFO [STDOUT] Failed again!!! :-( , ip got null value! + null
Please help me to understand the mistake I made...
-
14. Re: rich:scrollableDatatable : selection after sorting does not working!
christophe.fischbach Sep 8, 2010 10:25 AM (in response to yshashidhar)Hi Shashidharn,
I seen your post and I have the same problem.
After many tests, I found how to solve it:
If you use the extendedDataTable instead of the scrollableDataTable it will work fine.
I don't know if the problem come from the RF library but in fact when you use the scrollableDataTable the "getKey()" method defined in your "DataProvider" it still return the line number and not your custom key...
Ilya, can you confirm this is a normal or this is a bug? Thx
Have fun!