-
1. RichFaces4: lazy loading with dataTable and dataScroller
ilya_shaikovsky Apr 19, 2011 4:22 AM (in response to runk)1 of 1 people found this helpfulone of the samples in developers demo already contains code which loads data partially using JPA based model http://anonsvn.jboss.org/repos/richfaces/branches/4.0.X/examples/iteration-demo/
soon it will be migrated to the richfaces-showcase
-
2. Re: RichFaces4: lazy loading with dataTable and dataScroller
runk Apr 19, 2011 4:38 PM (in response to ilya_shaikovsky)Hi Ilya,
thanks for your answer. However this example looks to be for the tree stuff. I don't quite need that. I found some posts suggesting to implement org.richfaces.model.DataProvider and org.richfaces.model.ExtendedTableDataModel but I guess this is no longer relevant (RichFaces4).
I need lazy loading with rich:dataTable and rich:dataScroller.
10x
-
3. RichFaces4: lazy loading with dataTable and dataScroller
ilya_shaikovsky Apr 19, 2011 6:24 AM (in response to runk)1 of 1 people found this helpfulno it's not for tree stuff
see:
-
4. RichFaces4: lazy loading with dataTable and dataScroller
ilya_shaikovsky Apr 19, 2011 6:25 AM (in response to ilya_shaikovsky)it's probably slightly more complex than you need because filtering/sorting also present there. but you should be able to get the idea of just ExtendedDataModel from there. Just ignore methods which belongs to Arrangeable interface.
-
5. RichFaces4: lazy loading with dataTable and dataScroller
runk Apr 19, 2011 6:30 AM (in response to ilya_shaikovsky)Alright, I'll try it out. Thanks a lot.
-
6. Re: RichFaces4: lazy loading with dataTable and dataScroller
runk Apr 19, 2011 4:37 PM (in response to runk)Hi,
I managed to get it working. Here's a very very simple implementation of org.ajax4jsf.model.ExtendedDataModel:
import javax.faces.context.FacesContext; import org.ajax4jsf.model.DataVisitor; import org.ajax4jsf.model.ExtendedDataModel; import org.ajax4jsf.model.Range; import org.ajax4jsf.model.SequenceRange; public class TestDataModel extends ExtendedDataModel<String> { private String[] data = new String[] {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; private Integer rowKey = null; @Override public void setRowKey(Object o) { rowKey = (Integer) o; } @Override public Object getRowKey() { return rowKey; } @Override public void walk(FacesContext fc, DataVisitor dv, Range range, Object o) { SequenceRange sr = (SequenceRange) range; int currentRow = sr.getFirstRow(); int rows = sr.getRows(); for(int i = 0; i < rows; i++) { dv.process(fc, currentRow++, o); } } @Override public boolean isRowAvailable() { return rowKey != null; } @Override public int getRowCount() { return data.length; } @Override public String getRowData() { return data[rowKey]; } @Override public int getRowIndex() { return -1; } @Override public void setRowIndex(int rowIndex) { throw new UnsupportedOperationException(); } @Override public Object getWrappedData() { throw new UnsupportedOperationException(); } @Override public void setWrappedData(Object data) { throw new UnsupportedOperationException(); } }
and this is how it's used:
<rich:dataTable value="#{test.model}" var="i" rows="2" > <rich:column> #{i} </rich:column> <f:facet name="footer"> <rich:dataScroller /> </f:facet> </rich:dataTable>
where #{test.model} is an instance of TestDataModel.
Basically your "lazy" code should go into the walk() method.
10x again Ilya
-
7. Re: RichFaces4: lazy loading with dataTable and dataScroller
nikh123123 Apr 29, 2011 5:51 AM (in response to runk)I'm using similar logic except that the data is lazily loaded from a webserivce and hence my getRowCount method returns totalResults instead of the current list size. And I call the webservice method in the walk method. I have a few commandLinks in my dataTable. and every time I click on the commandLink, the walk method is executed. which in turn calls the web service which I do not want to happen. What could be the cause of this?
-
8. Re: RichFaces4: lazy loading with dataTable and dataScroller
nikh123123 Apr 29, 2011 10:19 AM (in response to nikh123123)I'm kinda stuck here. Can someone point me to the right direction please?
-
9. Re: RichFaces4: lazy loading with dataTable and dataScroller
runk May 1, 2011 2:48 AM (in response to nikh123123)Apparently the form which your data table is in gets posted when you click on the command links (which is normal). That's why the walk() method is called again ... your data table gets posted along your command links. You can try to nest an AJAX component and specify what exactly needs to be posted as part of your request.
-
10. Re: RichFaces4: lazy loading with dataTable and dataScroller
nikh123123 May 1, 2011 3:54 PM (in response to runk)Thanks for the reply Ric! Ok do you mean I need to use a component like a4j:commandLink with an execute=@this or @region?
-
11. Re: RichFaces4: lazy loading with dataTable and dataScroller
runk May 2, 2011 3:37 AM (in response to nikh123123)Yes, either a4j:commandLink or a4j:ajax.
Good luck.
-
12. Re: RichFaces4: lazy loading with dataTable and dataScroller
elisei May 11, 2011 10:14 AM (in response to runk)Hi all,
I also found a nice method here:
I thought it would be easier just to implement the DataProvider. But, as I see, the ExtendedTableDataModel isn't part of Richfaces 4.0.0.Final any more, right?
/Elisei
-
13. Re: RichFaces4: lazy loading with dataTable and dataScroller
jonleyo Apr 5, 2015 3:56 PM (in response to runk)Be careful if you're loading some data under the "walk" method.
It is invoked during "render response" phase.
If you're are trying to fetch with a database, you could have a surprise exception.