You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "Jesse Alexander (KBSA 21)" <al...@credit-suisse.com> on 2005/06/28 15:59:38 UTC

RE: dataScroller" Event Listener... exists?

Hi Joao

Best way to find this out is, to look at the samples.

The impression I got was this:
- You give the complete collection of items to the dataTable
- You configure the datascroller for the datatable
- Bingo that's all. The table is now "scrollable"

You will need more details only if you are about the try
very special things. And before doing that, it might be better 
to "play around" with the standard features.

Now what did you want to do in your "pageChangeListener"?
If you give us more details, we can help you better.

hope this helps 
Alexander 

-----Original Message-----
From: Joao Bortoletto [mailto:jbortoletto@yahoo.com] 
Sent: Tuesday, June 28, 2005 3:53 PM
To: users@myfaces.apache.org
Subject: "x:dataScroller" Event Listener... exists?

Hi friends,

    I'm starting a project with MyFaces! It appears
very cool!!! But I'm having some understand
problems...
    I've reading the documentation that said "JSF
works like Struts and Swing". 
    So... how can I handle an event over a
"dataScroler" component? 
    Is there any event listener class like
"pageChangeListener" I can implement?
    

    Thanks a lot!

    Joao Bortoletto


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: dataScroller" Event Listener... exists?

Posted by Werner Punz <we...@gmx.at>.
Btw. Joao, dont give up yet, JSF has a steep learning curve and is 
rather loosely coupled and has some leaks in the specs, but once you 
figured things out, you will become quite fast.

I implemented a full blown webapp with some ajax a bunch of custom 
controls a full blown integrated user handling etc... (you name it)
in about a time, and the app development time was about two weeks the 
rest was spent on the custom controls, because my boss came to me with a 
numbemonths r of totally insane user interface requests.
(Ajax, client side tabbed panes, autocomplete, coloring of inputs via 
validation etc... All of this UI stuff can be found in sourceforge in a 
working condition)

The datamodel handling is the trickiest part of the full show, the rest
is rather straightforward, and that is one thing you only do once.

What we really need are best practices patterns, since my own solution
is not very elegant and rather complicated, because I wrote it at a time 
when I did not have a good knowledge of JSF. I am currently thinking 
more along the lines of having clear aquire resources, releases 
resources demarkation points, which should cut down the LOCs significantly.
I know at least three mechanisms I was talking about in an earlier mail 
which should allow to get those points.

Werner


Joao Bortoletto wrote:
> Hello Werner,
> 
>    Thanks for your response... Your code was very
> useful to me!
>    I have a thousand of doubts about other jsf engines
> yet...
>    I will try to carry on studying examples and
> reading messages from this mailing list...
>    
>    Thanks again,
>    
>    Joao Bortoletto
>    
>    
> 
> --- Werner Punz <we...@gmx.at> wrote:
> 
> 
>>ok, I forgot a small fix which I did today:
>>@SuppressWarnings(value={"unchecked"})
>>	private Object getObjectFromCache() {
>>		if (_cacheWindow.size() == 0)
>>			return null;
>>		if(getRowIndex() - _cacheWindowPos >=
>>_cacheWindow.size())
>>			refillCache();
>>		return
>>_cacheWindow.get(Math.min(_cacheWindow.size()-1,
>>Math.max(0, 
>>getRowIndex() - _cacheWindowPos)));
>>	}
>>
>>
>>replace the same method below with the fixed one
>>here
>>
>>
>>
>>Werner Punz wrote:
>>
>>>Joao Bortoletto wrote:
>>>
>>>
>>>>Hi friends,
>>>>
>>>>    Following your suggestions I built my own
>>>>DataModel...
>>>>    (Werner, you warned me about "a" or "b"
>>
>>ways...
>>
>>>>Option "b" really seemed usefull, but I chose "a"
>>>>because I have a rope rounding my neck... :-D)
>>>>        Ok... now I have my own model, but it is
>>
>>static
>>
>>>>yet. So... How can I access other data from
>>
>>controller
>>
>>>>or view from it?
>>>>        Let me explain better...     I'm working
>>
>>with a managed bean 
>>
>>>>and its gives data
>>>>to a x:dataTable through a "getList" method.
>>
>>These
>>
>>>>data may depends on criteria inside a request,
>>
>>for
>>
>>>>example... how can I achieve this task?
>>>>        Is there another way to accomplish it?
>>>>
>>>
>>>Yes, you dont have to serve an entire list... you
>>
>>can implement your own 
>>
>>>Datamodel and
>>>have the datamodel itself serving it...
>>>
>>>Here is a rather huge example from my code which
>>
>>has not really publish 
>>
>>>quality yet:
>>>
>>>note as you can see the code is rather overly
>>
>>complicated the reason for 
>>
>>>this is sort of the prefetching of single pages,
>>
>>with a pageview 
>>
>>>controller I probably could have skipped half the
>>
>>lines of code, hence, 
>>
>>>I warned against approach a of prefetching:
>>>
>>>Explanation follows below the code:
>>>
>>>public class HibernateDataModel extends DataModel
>>
>>implements ICacheObject {
>>
>>>    // define a cachingWindow to keep the number
>>
>>of
>>
>>>    // connections/accessno at a sane level
>>>    // from time to time an isolation level error
>>>    // can occur since we seal the objects off
>>>    // and then close the connection
>>>    // so no real data integrity can be performed
>>
>>that way
>>
>>>    // but it should be good enough for the
>>
>>average webapp
>>
>>>    int                _cacheWindowSize    = 30;
>>>    // array list due to the fact that this one
>>
>>has the fastes
>>
>>>    // absolute access which is necessary for
>>
>>paging
>>
>>>    List            _cacheWindow        = new
>>
>>ArrayList(_cacheWindowSize);
>>
>>>    // helper idcache for faster access
>>>    Map                _idCache            = new
>>
>>TreeMap();
>>
>>>    // the cache window Position relative to the 0
>>
>>absolute
>>
>>>    int                _cacheWindowPos        = 0;
>>>    boolean            _cacheInvalidated    =
>>
>>true;
>>
>>>    // the standard variables which are defined by
>>
>>the system
>>
>>>    int                _rowCount            = -1;
>>>    int                _rowIndex            = -1;
>>>    // the associated query accessor
>>>    IDataAccessor    _queryDelegate        = null;
>>>
>>>    public void resetModel() {
>>>        _rowCount = -1;
>>>        _rowIndex = -1;
>>>        invalidateCache();
>>>        refillCache();
>>>    }
>>>
>>>    /**
>>>     *
>>>     */
>>>    public HibernateDataModel(IDataAccessor
>>
>>queryDelegate) {
>>
>>>        super();
>>>        setQueryDelegate(queryDelegate);
>>>        // refillCache();
>>>    }
>>>
>>>    public HibernateDataModel() {
>>>        super();
>>>    }
>>>
>>>    /*
>>>     * (non-Javadoc)
>>>     *
>>>     * @see
>>
>>javax.faces.model.DataModel#getRowCount() Return the
>>number 
>>
>>>of rows
>>>     *      of data objects represented by this
>>
>>DataModel. If the number 
>>
>>>of rows
>>>     *      is unknown, or no wrappedData is
>>
>>available, return -1.
>>
>>>     */
>>>    public int getRowCount() {
>>>        if (_rowCount == 0) {
>>>            return -1;
>>>        }
>>>        return _rowCount;
>>>    }
>>>
>>>    /**
>>>     * setter accessed by the query object
>>>     *
>>>     * @param rowCount
>>>     */
>>>    public void setRowCount(int rowCount) {
>>>        this._rowCount = rowCount;
>>>        // if(_rowIndex >= _rowCount-1)
>>>        // _rowIndex = -1;
>>>    }
>>>
>>>    // returns true if the dataset is within
>>>    boolean isCached() {
>>>        if (_cacheWindow == null ||
>>
>>_cacheWindow.size() == 0)
>>
>>>            return false;
>>>        else
>>>            return ((_cacheWindowPos <=
>>
>>getRowIndex()) && (getRowIndex() 
>>
>>>< (_cacheWindowPos + _cacheWindow.size())));
>>>    }
>>>
>>>    /**
>>>     * refills the cache window upon the given row
>>
>>index this one in the 
>>
>>>long
>>>     * term will possible be called from outside
>>
>>also
>>
>>>     */
>>>    @SuppressWarnings(value={"unchecked"})
>>>    public void refillCache() {
>>>        // calculate a decent new cache window
>>
>>pos, if possible with the 
>>
>>>current
>>>        // row index
>>>        // in the middle
>>>        _cacheWindowPos = Math.max(0,
>>
>>getRowIndex() - (_cacheWindowSize 
>>
>>>/ 2));
>>>        // refill the cache with the query
>>>        if (_cacheWindowSize > 0) {
>>>            _cacheWindow =
>>
>>_queryDelegate.queryDatasets(_cacheWindowPos, 
>>
>>>_cacheWindowSize);
>>>            _idCache = new TreeMap();
>>>           
>>>            for (Object elem : _cacheWindow) {
>>>                _idCache.put(((BaseDatabaseObject)
>>
>>elem).getId(), elem);
>>
>>>            }
>>>            setRowCount(_queryDelegate.getSize()
>>
>>);
>>
>>>           
>>
> setRowIndex(Math.min(Math.max(_queryDelegate.getSize()-1,
> 
>>>0), getRowIndex()));
>>>           
>>>            NavigationBean navBean2 =
>>
>>(NavigationBean) 
>>
>>>JSFUtil.getManagedBean(Constants.MBEAN_NAVBEAN);
>>
> === message truncated ===
> 
> 
> 
> 		
> ____________________________________________________ 
> Yahoo! Sports 
> Rekindle the Rivalries. Sign up for Fantasy Football 
> http://football.fantasysports.yahoo.com
> 


Re: dataScroller" Event Listener... exists?

Posted by Werner Punz <we...@gmx.at>.
Hi Joao....

I refactored and cleaned up the datamodel code
yesterday night in a late night session,
you can find something working, you can build upon in sourceforge
also combined with an example in the webapps dir. The code is under the 
apache2 license so feel free to use and alter it as you like.
There are probably one or two bugs along the way, but it should do its job.

The trick is with this datamodel, that you basically can hook pretty 
much ever orm mapper into it and it keeps the session time to a minimum.
All you have to implement is a basic query object which serves
the number of total datasets and the dataset pages.
The objects have to implement some kind of surrogate pattern, that means 
they have to be identifiable by a single id which should work in most 
cases. Datamodel save state does not work yet, I simply have not 
implemented it yet propery.



Here is the link to the code:
http://cvs.sourceforge.net/viewcvs.py/jsf-comp/componentsandbox/src/java/net/sf/myfacessandbox/backend/

or directly via anon cvs from cvs.sourceforge.net/jsf-comp

http://cvs.sourceforge.net/viewcvs.py/jsf-comp/componentsandbox/WebRoot/ 
here is the relevant webroot dir for the example the example is the orm 
datamodelTest.jsp file
here is the relevant faces-config file:
http://cvs.sourceforge.net/viewcvs.py/jsf-comp/componentsandbox/WebRoot/WEB-INF/components.xml?view=markup

with the relevant part being
<managed-bean>
		<managed-bean-name>ormDatabase</managed-bean-name>
		<managed-bean-class>
			net.sf.myfacessandbox.backend.database.tests.ORMTable
		</managed-bean-class>
		<managed-bean-scope>application</managed-bean-scope>
	</managed-bean>

for a simple simulated data source which serves the data (you have to 
replace that one with a real database, but once you see the code you get 
the clue anyway)

and for the backend bean:
<managed-bean>
   <description>backend bean for the generic orm data model demo 
form</description>
   <managed-bean-name>ormdemoBackendBean</managed-bean-name>
 
<managed-bean-class>net.sf.myfacessandbox.backend.database.tests.DemoBackendBean</managed-bean-class>
   <managed-bean-scope>request</managed-bean-scope>
  </managed-bean>
  <render-kit>

under
http://cvs.sourceforge.net/viewcvs.py/jsf-comp/componentsandbox/WebRoot/WEB-INF/faces-config.xml?rev=1.15&view=markup

Sorry for shoving in here so much data, but I think once you figure it 
out how to use it it will help you a lot...
what I posted here is just the relevant data for the demo to be able to 
connect things together,
all you basically need is the datamodel, and an implemementation of the 
query delegate, which you have to do yourself, that is it basically.
The rest of the show is done by the model itself.





Joao Bortoletto wrote:
> Hello Werner,
> 
>    Thanks for your response... Your code was very
> useful to me!
>    I have a thousand of doubts about other jsf engines
> yet...
>    I will try to carry on studying examples and
> reading messages from this mailing list...
>    
>    Thanks again,
>    
>    Joao Bortoletto
>    
>    
> 
> --- Werner Punz <we...@gmx.at> wrote:
> 
> 
>>ok, I forgot a small fix which I did today:
>>@SuppressWarnings(value={"unchecked"})
>>	private Object getObjectFromCache() {
>>		if (_cacheWindow.size() == 0)
>>			return null;
>>		if(getRowIndex() - _cacheWindowPos >=
>>_cacheWindow.size())
>>			refillCache();
>>		return
>>_cacheWindow.get(Math.min(_cacheWindow.size()-1,
>>Math.max(0, 
>>getRowIndex() - _cacheWindowPos)));
>>	}
>>
>>
>>replace the same method below with the fixed one
>>here
>>
>>
>>
>>Werner Punz wrote:
>>
>>>Joao Bortoletto wrote:
>>>
>>>
>>>>Hi friends,
>>>>
>>>>    Following your suggestions I built my own
>>>>DataModel...
>>>>    (Werner, you warned me about "a" or "b"
>>
>>ways...
>>
>>>>Option "b" really seemed usefull, but I chose "a"
>>>>because I have a rope rounding my neck... :-D)
>>>>        Ok... now I have my own model, but it is
>>
>>static
>>
>>>>yet. So... How can I access other data from
>>
>>controller
>>
>>>>or view from it?
>>>>        Let me explain better...     I'm working
>>
>>with a managed bean 
>>
>>>>and its gives data
>>>>to a x:dataTable through a "getList" method.
>>
>>These
>>
>>>>data may depends on criteria inside a request,
>>
>>for
>>
>>>>example... how can I achieve this task?
>>>>        Is there another way to accomplish it?
>>>>
>>>
>>>Yes, you dont have to serve an entire list... you
>>
>>can implement your own 
>>
>>>Datamodel and
>>>have the datamodel itself serving it...
>>>
>>>Here is a rather huge example from my code which
>>
>>has not really publish 
>>
>>>quality yet:
>>>
>>>note as you can see the code is rather overly
>>
>>complicated the reason for 
>>
>>>this is sort of the prefetching of single pages,
>>
>>with a pageview 
>>
>>>controller I probably could have skipped half the
>>
>>lines of code, hence, 
>>
>>>I warned against approach a of prefetching:
>>>
>>>Explanation follows below the code:
>>>
>>>public class HibernateDataModel extends DataModel
>>
>>implements ICacheObject {
>>
>>>    // define a cachingWindow to keep the number
>>
>>of
>>
>>>    // connections/accessno at a sane level
>>>    // from time to time an isolation level error
>>>    // can occur since we seal the objects off
>>>    // and then close the connection
>>>    // so no real data integrity can be performed
>>
>>that way
>>
>>>    // but it should be good enough for the
>>
>>average webapp
>>
>>>    int                _cacheWindowSize    = 30;
>>>    // array list due to the fact that this one
>>
>>has the fastes
>>
>>>    // absolute access which is necessary for
>>
>>paging
>>
>>>    List            _cacheWindow        = new
>>
>>ArrayList(_cacheWindowSize);
>>
>>>    // helper idcache for faster access
>>>    Map                _idCache            = new
>>
>>TreeMap();
>>
>>>    // the cache window Position relative to the 0
>>
>>absolute
>>
>>>    int                _cacheWindowPos        = 0;
>>>    boolean            _cacheInvalidated    =
>>
>>true;
>>
>>>    // the standard variables which are defined by
>>
>>the system
>>
>>>    int                _rowCount            = -1;
>>>    int                _rowIndex            = -1;
>>>    // the associated query accessor
>>>    IDataAccessor    _queryDelegate        = null;
>>>
>>>    public void resetModel() {
>>>        _rowCount = -1;
>>>        _rowIndex = -1;
>>>        invalidateCache();
>>>        refillCache();
>>>    }
>>>
>>>    /**
>>>     *
>>>     */
>>>    public HibernateDataModel(IDataAccessor
>>
>>queryDelegate) {
>>
>>>        super();
>>>        setQueryDelegate(queryDelegate);
>>>        // refillCache();
>>>    }
>>>
>>>    public HibernateDataModel() {
>>>        super();
>>>    }
>>>
>>>    /*
>>>     * (non-Javadoc)
>>>     *
>>>     * @see
>>
>>javax.faces.model.DataModel#getRowCount() Return the
>>number 
>>
>>>of rows
>>>     *      of data objects represented by this
>>
>>DataModel. If the number 
>>
>>>of rows
>>>     *      is unknown, or no wrappedData is
>>
>>available, return -1.
>>
>>>     */
>>>    public int getRowCount() {
>>>        if (_rowCount == 0) {
>>>            return -1;
>>>        }
>>>        return _rowCount;
>>>    }
>>>
>>>    /**
>>>     * setter accessed by the query object
>>>     *
>>>     * @param rowCount
>>>     */
>>>    public void setRowCount(int rowCount) {
>>>        this._rowCount = rowCount;
>>>        // if(_rowIndex >= _rowCount-1)
>>>        // _rowIndex = -1;
>>>    }
>>>
>>>    // returns true if the dataset is within
>>>    boolean isCached() {
>>>        if (_cacheWindow == null ||
>>
>>_cacheWindow.size() == 0)
>>
>>>            return false;
>>>        else
>>>            return ((_cacheWindowPos <=
>>
>>getRowIndex()) && (getRowIndex() 
>>
>>>< (_cacheWindowPos + _cacheWindow.size())));
>>>    }
>>>
>>>    /**
>>>     * refills the cache window upon the given row
>>
>>index this one in the 
>>
>>>long
>>>     * term will possible be called from outside
>>
>>also
>>
>>>     */
>>>    @SuppressWarnings(value={"unchecked"})
>>>    public void refillCache() {
>>>        // calculate a decent new cache window
>>
>>pos, if possible with the 
>>
>>>current
>>>        // row index
>>>        // in the middle
>>>        _cacheWindowPos = Math.max(0,
>>
>>getRowIndex() - (_cacheWindowSize 
>>
>>>/ 2));
>>>        // refill the cache with the query
>>>        if (_cacheWindowSize > 0) {
>>>            _cacheWindow =
>>
>>_queryDelegate.queryDatasets(_cacheWindowPos, 
>>
>>>_cacheWindowSize);
>>>            _idCache = new TreeMap();
>>>           
>>>            for (Object elem : _cacheWindow) {
>>>                _idCache.put(((BaseDatabaseObject)
>>
>>elem).getId(), elem);
>>
>>>            }
>>>            setRowCount(_queryDelegate.getSize()
>>
>>);
>>
>>>           
>>
> setRowIndex(Math.min(Math.max(_queryDelegate.getSize()-1,
> 
>>>0), getRowIndex()));
>>>           
>>>            NavigationBean navBean2 =
>>
>>(NavigationBean) 
>>
>>>JSFUtil.getManagedBean(Constants.MBEAN_NAVBEAN);
>>
> === message truncated ===
> 
> 
> 
> 		
> ____________________________________________________ 
> Yahoo! Sports 
> Rekindle the Rivalries. Sign up for Fantasy Football 
> http://football.fantasysports.yahoo.com
> 


Re: dataScroller" Event Listener... exists?

Posted by Joao Bortoletto <jb...@yahoo.com>.
Hello Werner,

   Thanks for your response... Your code was very
useful to me!
   I have a thousand of doubts about other jsf engines
yet...
   I will try to carry on studying examples and
reading messages from this mailing list...
   
   Thanks again,
   
   Joao Bortoletto
   
   

--- Werner Punz <we...@gmx.at> wrote:

> ok, I forgot a small fix which I did today:
> @SuppressWarnings(value={"unchecked"})
> 	private Object getObjectFromCache() {
> 		if (_cacheWindow.size() == 0)
> 			return null;
> 		if(getRowIndex() - _cacheWindowPos >=
> _cacheWindow.size())
> 			refillCache();
> 		return
> _cacheWindow.get(Math.min(_cacheWindow.size()-1,
> Math.max(0, 
> getRowIndex() - _cacheWindowPos)));
> 	}
> 
> 
> replace the same method below with the fixed one
> here
> 
> 
> 
> Werner Punz wrote:
> > Joao Bortoletto wrote:
> > 
> >> Hi friends,
> >>
> >>     Following your suggestions I built my own
> >> DataModel...
> >>     (Werner, you warned me about "a" or "b"
> ways...
> >> Option "b" really seemed usefull, but I chose "a"
> >> because I have a rope rounding my neck... :-D)
> >>         Ok... now I have my own model, but it is
> static
> >> yet. So... How can I access other data from
> controller
> >> or view from it?
> >>         Let me explain better...     I'm working
> with a managed bean 
> >> and its gives data
> >> to a x:dataTable through a "getList" method.
> These
> >> data may depends on criteria inside a request,
> for
> >> example... how can I achieve this task?
> >>         Is there another way to accomplish it?
> >>
> > Yes, you dont have to serve an entire list... you
> can implement your own 
> > Datamodel and
> > have the datamodel itself serving it...
> > 
> > Here is a rather huge example from my code which
> has not really publish 
> > quality yet:
> > 
> > note as you can see the code is rather overly
> complicated the reason for 
> > this is sort of the prefetching of single pages,
> with a pageview 
> > controller I probably could have skipped half the
> lines of code, hence, 
> > I warned against approach a of prefetching:
> > 
> > Explanation follows below the code:
> > 
> > public class HibernateDataModel extends DataModel
> implements ICacheObject {
> > 
> >     // define a cachingWindow to keep the number
> of
> >     // connections/accessno at a sane level
> >     // from time to time an isolation level error
> >     // can occur since we seal the objects off
> >     // and then close the connection
> >     // so no real data integrity can be performed
> that way
> >     // but it should be good enough for the
> average webapp
> >     int                _cacheWindowSize    = 30;
> >     // array list due to the fact that this one
> has the fastes
> >     // absolute access which is necessary for
> paging
> >     List            _cacheWindow        = new
> ArrayList(_cacheWindowSize);
> >     // helper idcache for faster access
> >     Map                _idCache            = new
> TreeMap();
> >     // the cache window Position relative to the 0
> absolute
> >     int                _cacheWindowPos        = 0;
> >     boolean            _cacheInvalidated    =
> true;
> >     // the standard variables which are defined by
> the system
> >     int                _rowCount            = -1;
> >     int                _rowIndex            = -1;
> >     // the associated query accessor
> >     IDataAccessor    _queryDelegate        = null;
> > 
> >     public void resetModel() {
> >         _rowCount = -1;
> >         _rowIndex = -1;
> >         invalidateCache();
> >         refillCache();
> >     }
> > 
> >     /**
> >      *
> >      */
> >     public HibernateDataModel(IDataAccessor
> queryDelegate) {
> >         super();
> >         setQueryDelegate(queryDelegate);
> >         // refillCache();
> >     }
> > 
> >     public HibernateDataModel() {
> >         super();
> >     }
> > 
> >     /*
> >      * (non-Javadoc)
> >      *
> >      * @see
> javax.faces.model.DataModel#getRowCount() Return the
> number 
> > of rows
> >      *      of data objects represented by this
> DataModel. If the number 
> > of rows
> >      *      is unknown, or no wrappedData is
> available, return -1.
> >      */
> >     public int getRowCount() {
> >         if (_rowCount == 0) {
> >             return -1;
> >         }
> >         return _rowCount;
> >     }
> > 
> >     /**
> >      * setter accessed by the query object
> >      *
> >      * @param rowCount
> >      */
> >     public void setRowCount(int rowCount) {
> >         this._rowCount = rowCount;
> >         // if(_rowIndex >= _rowCount-1)
> >         // _rowIndex = -1;
> >     }
> > 
> >     // returns true if the dataset is within
> >     boolean isCached() {
> >         if (_cacheWindow == null ||
> _cacheWindow.size() == 0)
> >             return false;
> >         else
> >             return ((_cacheWindowPos <=
> getRowIndex()) && (getRowIndex() 
> > < (_cacheWindowPos + _cacheWindow.size())));
> >     }
> > 
> >     /**
> >      * refills the cache window upon the given row
> index this one in the 
> > long
> >      * term will possible be called from outside
> also
> >      */
> >     @SuppressWarnings(value={"unchecked"})
> >     public void refillCache() {
> >         // calculate a decent new cache window
> pos, if possible with the 
> > current
> >         // row index
> >         // in the middle
> >         _cacheWindowPos = Math.max(0,
> getRowIndex() - (_cacheWindowSize 
> > / 2));
> >         // refill the cache with the query
> >         if (_cacheWindowSize > 0) {
> >             _cacheWindow =
> _queryDelegate.queryDatasets(_cacheWindowPos, 
> > _cacheWindowSize);
> >             _idCache = new TreeMap();
> >            
> >             for (Object elem : _cacheWindow) {
> >                 _idCache.put(((BaseDatabaseObject)
> elem).getId(), elem);
> >             }
> >             setRowCount(_queryDelegate.getSize()
> );
> >            
>
setRowIndex(Math.min(Math.max(_queryDelegate.getSize()-1,
> 
> > 0), getRowIndex()));
> >            
> >             NavigationBean navBean2 =
> (NavigationBean) 
> > JSFUtil.getManagedBean(Constants.MBEAN_NAVBEAN);
> 
=== message truncated ===



		
____________________________________________________ 
Yahoo! Sports 
Rekindle the Rivalries. Sign up for Fantasy Football 
http://football.fantasysports.yahoo.com

Re: dataScroller" Event Listener... exists?

Posted by Werner Punz <we...@gmx.at>.
ok, I forgot a small fix which I did today:
@SuppressWarnings(value={"unchecked"})
	private Object getObjectFromCache() {
		if (_cacheWindow.size() == 0)
			return null;
		if(getRowIndex() - _cacheWindowPos >= _cacheWindow.size())
			refillCache();
		return _cacheWindow.get(Math.min(_cacheWindow.size()-1, Math.max(0, 
getRowIndex() - _cacheWindowPos)));
	}


replace the same method below with the fixed one here



Werner Punz wrote:
> Joao Bortoletto wrote:
> 
>> Hi friends,
>>
>>     Following your suggestions I built my own
>> DataModel...
>>     (Werner, you warned me about "a" or "b" ways...
>> Option "b" really seemed usefull, but I chose "a"
>> because I have a rope rounding my neck... :-D)
>>         Ok... now I have my own model, but it is static
>> yet. So... How can I access other data from controller
>> or view from it?
>>         Let me explain better...     I'm working with a managed bean 
>> and its gives data
>> to a x:dataTable through a "getList" method. These
>> data may depends on criteria inside a request, for
>> example... how can I achieve this task?
>>         Is there another way to accomplish it?
>>
> Yes, you dont have to serve an entire list... you can implement your own 
> Datamodel and
> have the datamodel itself serving it...
> 
> Here is a rather huge example from my code which has not really publish 
> quality yet:
> 
> note as you can see the code is rather overly complicated the reason for 
> this is sort of the prefetching of single pages, with a pageview 
> controller I probably could have skipped half the lines of code, hence, 
> I warned against approach a of prefetching:
> 
> Explanation follows below the code:
> 
> public class HibernateDataModel extends DataModel implements ICacheObject {
> 
>     // define a cachingWindow to keep the number of
>     // connections/accessno at a sane level
>     // from time to time an isolation level error
>     // can occur since we seal the objects off
>     // and then close the connection
>     // so no real data integrity can be performed that way
>     // but it should be good enough for the average webapp
>     int                _cacheWindowSize    = 30;
>     // array list due to the fact that this one has the fastes
>     // absolute access which is necessary for paging
>     List            _cacheWindow        = new ArrayList(_cacheWindowSize);
>     // helper idcache for faster access
>     Map                _idCache            = new TreeMap();
>     // the cache window Position relative to the 0 absolute
>     int                _cacheWindowPos        = 0;
>     boolean            _cacheInvalidated    = true;
>     // the standard variables which are defined by the system
>     int                _rowCount            = -1;
>     int                _rowIndex            = -1;
>     // the associated query accessor
>     IDataAccessor    _queryDelegate        = null;
> 
>     public void resetModel() {
>         _rowCount = -1;
>         _rowIndex = -1;
>         invalidateCache();
>         refillCache();
>     }
> 
>     /**
>      *
>      */
>     public HibernateDataModel(IDataAccessor queryDelegate) {
>         super();
>         setQueryDelegate(queryDelegate);
>         // refillCache();
>     }
> 
>     public HibernateDataModel() {
>         super();
>     }
> 
>     /*
>      * (non-Javadoc)
>      *
>      * @see javax.faces.model.DataModel#getRowCount() Return the number 
> of rows
>      *      of data objects represented by this DataModel. If the number 
> of rows
>      *      is unknown, or no wrappedData is available, return -1.
>      */
>     public int getRowCount() {
>         if (_rowCount == 0) {
>             return -1;
>         }
>         return _rowCount;
>     }
> 
>     /**
>      * setter accessed by the query object
>      *
>      * @param rowCount
>      */
>     public void setRowCount(int rowCount) {
>         this._rowCount = rowCount;
>         // if(_rowIndex >= _rowCount-1)
>         // _rowIndex = -1;
>     }
> 
>     // returns true if the dataset is within
>     boolean isCached() {
>         if (_cacheWindow == null || _cacheWindow.size() == 0)
>             return false;
>         else
>             return ((_cacheWindowPos <= getRowIndex()) && (getRowIndex() 
> < (_cacheWindowPos + _cacheWindow.size())));
>     }
> 
>     /**
>      * refills the cache window upon the given row index this one in the 
> long
>      * term will possible be called from outside also
>      */
>     @SuppressWarnings(value={"unchecked"})
>     public void refillCache() {
>         // calculate a decent new cache window pos, if possible with the 
> current
>         // row index
>         // in the middle
>         _cacheWindowPos = Math.max(0, getRowIndex() - (_cacheWindowSize 
> / 2));
>         // refill the cache with the query
>         if (_cacheWindowSize > 0) {
>             _cacheWindow = _queryDelegate.queryDatasets(_cacheWindowPos, 
> _cacheWindowSize);
>             _idCache = new TreeMap();
>            
>             for (Object elem : _cacheWindow) {
>                 _idCache.put(((BaseDatabaseObject) elem).getId(), elem);
>             }
>             setRowCount(_queryDelegate.getSize() );
>             setRowIndex(Math.min(Math.max(_queryDelegate.getSize()-1, 
> 0), getRowIndex()));
>            
>             NavigationBean navBean2 = (NavigationBean) 
> JSFUtil.getManagedBean(Constants.MBEAN_NAVBEAN);
>            
>             navBean2.setCurrentNavSelection(_cacheWindow);
>         }
>         _cacheInvalidated = false;
>     }
> 
>     /*
>      * (non-Javadoc)
>      *
>      * @see jsf.common.ICacheObject#invalidateCache()
>      */
>     public void invalidateCache() {
>         _cacheInvalidated = true;
>     }
> 
>     /*
>      * (non-Javadoc)
>      *
>      * @see javax.faces.model.DataModel#getRowData() Return an object
>      *      representing the data for the currenty selected row index. 
> If no
>      *      wrappedData is available, return null.
>      */
>     public Object getRowData() {
>         // synchronize this just in case we implemnt
>         // an internal cache dumping mechanism
>         // for hit fault reduction
>         try {
>             synchronized (_cacheWindow) {
>                 // fetch a cached object
>                 if ((!_cacheInvalidated) && isCached() ) {
>                     return getObjectFromCache();
>                 }
>                 // reload the cache and get the object
>                 refillCache();
>                 return getObjectFromCache();
>             }
>         } catch (RuntimeException ex) {
>             invalidateCache();
>             throw ex;
>         }
>     }
> 
>     /**
>      * @return
>      */
>     @SuppressWarnings(value={"unchecked"})
>     private Object getObjectFromCache() {
>         if (_cacheWindow.size() == 0)
>             return null;
>         //TODO range check problem sometimes
>         return _cacheWindow.get(Math.min(_cacheWindow.size(), 
> Math.max(0, getRowIndex() - _cacheWindowPos)));
>     }
> 
>     /*
>      * (non-Javadoc)
>      *
>      * @see javax.faces.model.DataModel#getRowIndex() Return the 
> zero-relative
>      *      index of the currently selected row. If we are not currently
>      *      positioned on a row, or no wrappedData is available, return -1.
>      */
>     public int getRowIndex() {
>         return _rowIndex;
>     }
> 
>     /*
>      * (non-Javadoc)
>      *
>      * @see javax.faces.model.DataModel#getWrappedData() Return the object
>      *      representing the data wrapped by this DataModel, if any.
>      */
>     public Object getWrappedData() {
>         // TODO Auto-generated method stub
>         return null;
>     }
> 
>     /*
>      * (non-Javadoc)
>      *
>      * @see javax.faces.model.DataModel#isRowAvailable() Return a flag
>      *      indicating whether there is rowData available at the current
>      *      rowIndex. If no wrappedData is available, return false.
>      */
>     public boolean isRowAvailable() {
>         return getRowIndex() < getRowCount();
>     }
> 
>     /*
>      * (non-Javadoc)
>      *
>      * @see javax.faces.model.DataModel#setRowIndex(int) Set the 
> zero-relative
>      *      index of the currently selected row, or -1 to indicate that 
> we are
>      *      not positioned on a row. It is possible to set the row index 
> at a
>      *      value for which the underlying data collection does not 
> contain any
>      *      row data. Therefore, callers may use the isRowAvailable() 
> method to
>      *      detect whether row data will be available for use by the
>      *      getRowData() method. If there is no wrappedData available 
> when this
>      *      method is called, the specified rowIndex is stored (and may be
>      *      retrieved by a subsequent call to getRowData()), but no 
> event is
>      *      sent. Otherwise, if the currently selected row index is 
> changed by
>      *      this call, a DataModelEvent will be sent to the 
> rowSelected() method
>      *      of all registered DataModelListeners.
>      */
>     public void setRowIndex(int arg0) {
>         _rowIndex = arg0;
>     }
> 
>     /*
>      * (non-Javadoc)
>      *
>      * @see javax.faces.model.DataModel#setWrappedData(java.lang.Object) 
> Set the
>      *      object representing the data collection wrapped by this 
> DataModel.
>      *      If the specified data is null, detach this DataModel from any
>      *      previously wrapped data collection instead. If data is 
> non-null, the
>      *      currently selected row index must be set to zero, and a
>      *      DataModelEvent must be sent to the rowSelected() method of all
>      *      registered DataModelListeners indicating that this row is now
>      *      selected.
>      */
>     public void setWrappedData(Object arg0) {
>         // TODO Auto-generated method stub
>     }
> 
>     /**
>      * sets a query delegate, use a cached one if wanted/needed
>      *
>      * @param queryDelegate
>      * @param useCached
>      */
>     @SuppressWarnings(value={"unchecked"})
>     public void setQueryDelegate(IDataAccessor queryDelegate, boolean 
> useCached) {
>         Object tmpQueryDelegate = null;
>         if (useCached) {
>             tmpQueryDelegate = 
> JSFUtil.getSessionMap().get(createQueryKey(queryDelegate));
>             if (tmpQueryDelegate == null) {
>                 
> JSFUtil.getSessionMap().put(createQueryKey(queryDelegate), queryDelegate);
>             } else {
>                 queryDelegate = (IDataAccessor) tmpQueryDelegate;
>             }
>         }
>         setQueryDelegate(queryDelegate);
>     }
> 
>     public IDataAccessor getQueryDelegate() {
>         return _queryDelegate;
>     }
> 
>     /**
>      * @param queryDelegate
>      * @return
>      */
>     private String createQueryKey(IDataAccessor queryDelegate) {
>         return "QUERY" + this.getClass().getName() + 
> queryDelegate.getClass().getName();
>     }
> 
>     /**
>      * query delegate setter
>      *
>      * @param queryDelegate
>      */
>     public void setQueryDelegate(IDataAccessor queryDelegate) {
>         _queryDelegate = queryDelegate;
>         _queryDelegate.setDataModel(this);
>     }
> 
>     /**
>      * @param mode
>      */
>     public void setOrderMode(String mode) {
>         _queryDelegate.setOrderMode(mode);
>     }
> 
>     /**
>      * returns an object from the page cache just to be sure
>      *
>      * @param id
>      * @return
>      */
>     @SuppressWarnings(value={"unchecked"})
>     public BaseDatabaseObject getPageObjectFromId(Integer id) {
>         return (BaseDatabaseObject) _idCache.get(id);
>     }
> 
>     /**
>      * @return Returns the _cacheWindow.
>      */
>     public List get_cacheWindow() {
>         return _cacheWindow;
>     }
> 
>     /**
>      * @param window
>      *            The _cacheWindow to set.
>      */
>     public void set_cacheWindow(List window) {
>         _cacheWindow = window;
>     }
> }
> 
> 
> 
> What happens here, that an unnecessarily complicated datamodel 
> prefetches the entire page window into a local cache with criteria 
> predefined by a query delegate object and serves the data row by row
> into the current datamodel. The positional state is set by the datamodel
> via callbacks so that once a cache boundary is hit, the caching windows 
> is refreshed.
> As I said that is my approach (not quite publish quality yet, but works)
> 
> If you implement the same approach via a callback mechanism which is 
> called before and after rendering, you probably can implement the same 
> in around 30 lines of code, you just have to aquire the resources for 
> the db access before rendering, then open a session start the query, get 
> some kind of db-point/iterator on the query position it at the first set 
>  rowindex call and then serve it row by row, you can be pretty sure that 
> the data itself once the first row index is in place is called 
> sequentially.
> 
> At the end of rendering, you can release the resources close the 
> transactions and free the session.
> Note that the code above was written 5 months ago, at a time when I 
> neither was aware of the Script Phase Listeners nor of Servlet filters, 
> nor of the stuff clanahan is doing with the PageView controllers in 
> Shale. I had to work around that, and basically implemented the buggy, 
> and not very satisfying but working code above during a learning phase.
> But I am posting it anyway, to give you the idea on how to do such things.
> 
> 
> 


Re: dataScroller" Event Listener... exists?

Posted by Werner Punz <we...@gmx.at>.
Joao Bortoletto wrote:
> Hi friends,
> 
>     Following your suggestions I built my own
> DataModel...
>     (Werner, you warned me about "a" or "b" ways...
> Option "b" really seemed usefull, but I chose "a"
> because I have a rope rounding my neck... :-D)
>     
>     Ok... now I have my own model, but it is static
> yet. So... How can I access other data from controller
> or view from it?
>     
>     Let me explain better... 
>     I'm working with a managed bean and its gives data
> to a x:dataTable through a "getList" method. These
> data may depends on criteria inside a request, for
> example... how can I achieve this task?
>     
>     Is there another way to accomplish it?
> 
Yes, you dont have to serve an entire list... you can implement your own 
Datamodel and
have the datamodel itself serving it...

Here is a rather huge example from my code which has not really publish 
quality yet:

note as you can see the code is rather overly complicated the reason for 
this is sort of the prefetching of single pages, with a pageview 
controller I probably could have skipped half the lines of code, hence, 
I warned against approach a of prefetching:

Explanation follows below the code:

public class HibernateDataModel extends DataModel implements ICacheObject {

	// define a cachingWindow to keep the number of
	// connections/accessno at a sane level
	// from time to time an isolation level error
	// can occur since we seal the objects off
	// and then close the connection
	// so no real data integrity can be performed that way
	// but it should be good enough for the average webapp
	int				_cacheWindowSize	= 30;
	// array list due to the fact that this one has the fastes
	// absolute access which is necessary for paging
	List			_cacheWindow		= new ArrayList(_cacheWindowSize);
	// helper idcache for faster access
	Map				_idCache			= new TreeMap();
	// the cache window Position relative to the 0 absolute
	int				_cacheWindowPos		= 0;
	boolean			_cacheInvalidated	= true;
	// the standard variables which are defined by the system
	int				_rowCount			= -1;
	int				_rowIndex			= -1;
	// the associated query accessor
	IDataAccessor	_queryDelegate		= null;

	public void resetModel() {
		_rowCount = -1;
		_rowIndex = -1;
		invalidateCache();
		refillCache();
	}

	/**
	 *
	 */
	public HibernateDataModel(IDataAccessor queryDelegate) {
		super();
		setQueryDelegate(queryDelegate);
		// refillCache();
	}

	public HibernateDataModel() {
		super();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see javax.faces.model.DataModel#getRowCount() Return the number of rows
	 *      of data objects represented by this DataModel. If the number of 
rows
	 *      is unknown, or no wrappedData is available, return -1.
	 */
	public int getRowCount() {
		if (_rowCount == 0) {
			return -1;
		}
		return _rowCount;
	}

	/**
	 * setter accessed by the query object
	 *
	 * @param rowCount
	 */
	public void setRowCount(int rowCount) {
		this._rowCount = rowCount;
		// if(_rowIndex >= _rowCount-1)
		// _rowIndex = -1;
	}

	// returns true if the dataset is within
	boolean isCached() {
		if (_cacheWindow == null || _cacheWindow.size() == 0)
			return false;
		else
			return ((_cacheWindowPos <= getRowIndex()) && (getRowIndex() < 
(_cacheWindowPos + _cacheWindow.size())));
	}

	/**
	 * refills the cache window upon the given row index this one in the long
	 * term will possible be called from outside also
	 */
	@SuppressWarnings(value={"unchecked"})
	public void refillCache() {
		// calculate a decent new cache window pos, if possible with the current
		// row index
		// in the middle
		_cacheWindowPos = Math.max(0, getRowIndex() - (_cacheWindowSize / 2));
		// refill the cache with the query
		if (_cacheWindowSize > 0) {
			_cacheWindow = _queryDelegate.queryDatasets(_cacheWindowPos, 
_cacheWindowSize);
			_idCache = new TreeMap();
			
			for (Object elem : _cacheWindow) {
				_idCache.put(((BaseDatabaseObject) elem).getId(), elem);
			}
			setRowCount(_queryDelegate.getSize() );
			setRowIndex(Math.min(Math.max(_queryDelegate.getSize()-1, 0), 
getRowIndex()));
			
			NavigationBean navBean2 = (NavigationBean) 
JSFUtil.getManagedBean(Constants.MBEAN_NAVBEAN);
			
			navBean2.setCurrentNavSelection(_cacheWindow);
		}
		_cacheInvalidated = false;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see jsf.common.ICacheObject#invalidateCache()
	 */
	public void invalidateCache() {
		_cacheInvalidated = true;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see javax.faces.model.DataModel#getRowData() Return an object
	 *      representing the data for the currenty selected row index. If no
	 *      wrappedData is available, return null.
	 */
	public Object getRowData() {
		// synchronize this just in case we implemnt
		// an internal cache dumping mechanism
		// for hit fault reduction
		try {
			synchronized (_cacheWindow) {
				// fetch a cached object
				if ((!_cacheInvalidated) && isCached() ) {
					return getObjectFromCache();
				}
				// reload the cache and get the object
				refillCache();
				return getObjectFromCache();
			}
		} catch (RuntimeException ex) {
			invalidateCache();
			throw ex;
		}
	}

	/**
	 * @return
	 */
	@SuppressWarnings(value={"unchecked"})
	private Object getObjectFromCache() {
		if (_cacheWindow.size() == 0)
			return null;
		//TODO range check problem sometimes
		return _cacheWindow.get(Math.min(_cacheWindow.size(), Math.max(0, 
getRowIndex() - _cacheWindowPos)));
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see javax.faces.model.DataModel#getRowIndex() Return the zero-relative
	 *      index of the currently selected row. If we are not currently
	 *      positioned on a row, or no wrappedData is available, return -1.
	 */
	public int getRowIndex() {
		return _rowIndex;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see javax.faces.model.DataModel#getWrappedData() Return the object
	 *      representing the data wrapped by this DataModel, if any.
	 */
	public Object getWrappedData() {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see javax.faces.model.DataModel#isRowAvailable() Return a flag
	 *      indicating whether there is rowData available at the current
	 *      rowIndex. If no wrappedData is available, return false.
	 */
	public boolean isRowAvailable() {
		return getRowIndex() < getRowCount();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see javax.faces.model.DataModel#setRowIndex(int) Set the zero-relative
	 *      index of the currently selected row, or -1 to indicate that we are
	 *      not positioned on a row. It is possible to set the row index at a
	 *      value for which the underlying data collection does not contain any
	 *      row data. Therefore, callers may use the isRowAvailable() method to
	 *      detect whether row data will be available for use by the
	 *      getRowData() method. If there is no wrappedData available when this
	 *      method is called, the specified rowIndex is stored (and may be
	 *      retrieved by a subsequent call to getRowData()), but no event is
	 *      sent. Otherwise, if the currently selected row index is changed by
	 *      this call, a DataModelEvent will be sent to the rowSelected() 
method
	 *      of all registered DataModelListeners.
	 */
	public void setRowIndex(int arg0) {
		_rowIndex = arg0;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see javax.faces.model.DataModel#setWrappedData(java.lang.Object) 
Set the
	 *      object representing the data collection wrapped by this DataModel.
	 *      If the specified data is null, detach this DataModel from any
	 *      previously wrapped data collection instead. If data is 
non-null, the
	 *      currently selected row index must be set to zero, and a
	 *      DataModelEvent must be sent to the rowSelected() method of all
	 *      registered DataModelListeners indicating that this row is now
	 *      selected.
	 */
	public void setWrappedData(Object arg0) {
		// TODO Auto-generated method stub
	}

	/**
	 * sets a query delegate, use a cached one if wanted/needed
	 *
	 * @param queryDelegate
	 * @param useCached
	 */
	@SuppressWarnings(value={"unchecked"})
	public void setQueryDelegate(IDataAccessor queryDelegate, boolean 
useCached) {
		Object tmpQueryDelegate = null;
		if (useCached) {
			tmpQueryDelegate = 
JSFUtil.getSessionMap().get(createQueryKey(queryDelegate));
			if (tmpQueryDelegate == null) {
				JSFUtil.getSessionMap().put(createQueryKey(queryDelegate), 
queryDelegate);
			} else {
				queryDelegate = (IDataAccessor) tmpQueryDelegate;
			}
		}
		setQueryDelegate(queryDelegate);
	}

	public IDataAccessor getQueryDelegate() {
		return _queryDelegate;
	}

	/**
	 * @param queryDelegate
	 * @return
	 */
	private String createQueryKey(IDataAccessor queryDelegate) {
		return "QUERY" + this.getClass().getName() + 
queryDelegate.getClass().getName();
	}

	/**
	 * query delegate setter
	 *
	 * @param queryDelegate
	 */
	public void setQueryDelegate(IDataAccessor queryDelegate) {
		_queryDelegate = queryDelegate;
		_queryDelegate.setDataModel(this);
	}

	/**
	 * @param mode
	 */
	public void setOrderMode(String mode) {
		_queryDelegate.setOrderMode(mode);
	}

	/**
	 * returns an object from the page cache just to be sure
	 *
	 * @param id
	 * @return
	 */
	@SuppressWarnings(value={"unchecked"})
	public BaseDatabaseObject getPageObjectFromId(Integer id) {
		return (BaseDatabaseObject) _idCache.get(id);
	}

	/**
	 * @return Returns the _cacheWindow.
	 */
	public List get_cacheWindow() {
		return _cacheWindow;
	}

	/**
	 * @param window
	 *            The _cacheWindow to set.
	 */
	public void set_cacheWindow(List window) {
		_cacheWindow = window;
	}
}



What happens here, that an unnecessarily complicated datamodel 
prefetches the entire page window into a local cache with criteria 
predefined by a query delegate object and serves the data row by row
into the current datamodel. The positional state is set by the datamodel
via callbacks so that once a cache boundary is hit, the caching windows 
is refreshed.
As I said that is my approach (not quite publish quality yet, but works)

If you implement the same approach via a callback mechanism which is 
called before and after rendering, you probably can implement the same 
in around 30 lines of code, you just have to aquire the resources for 
the db access before rendering, then open a session start the query, get 
some kind of db-point/iterator on the query position it at the first set 
  rowindex call and then serve it row by row, you can be pretty sure 
that the data itself once the first row index is in place is called 
sequentially.

At the end of rendering, you can release the resources close the 
transactions and free the session.
Note that the code above was written 5 months ago, at a time when I 
neither was aware of the Script Phase Listeners nor of Servlet filters, 
nor of the stuff clanahan is doing with the PageView controllers in 
Shale. I had to work around that, and basically implemented the buggy, 
and not very satisfying but working code above during a learning phase.
But I am posting it anyway, to give you the idea on how to do such things.



Re: dataScroller" Event Listener... exists?

Posted by Joao Bortoletto <jb...@yahoo.com>.
Hi friends,

    Following your suggestions I built my own
DataModel...
    (Werner, you warned me about "a" or "b" ways...
Option "b" really seemed usefull, but I chose "a"
because I have a rope rounding my neck... :-D)
    
    Ok... now I have my own model, but it is static
yet. So... How can I access other data from controller
or view from it?
    
    Let me explain better... 
    I'm working with a managed bean and its gives data
to a x:dataTable through a "getList" method. These
data may depends on criteria inside a request, for
example... how can I achieve this task?
    
    Is there another way to accomplish it?
    
    Thanks and thanks once more!
    
    Joao Bortoletto


--- Werner Punz <we...@gmx.at> wrote:

> Joao Bortoletto wrote:
> > Hi Alexander,
> > 
> >     Thanks for your response!
> >     I've studying the example source code. It
> works
> > fine but, like you said, I'm trying to do special
> > things... here we go:
> >     
> >     I have a system that access data by oracle
> stored
> > procedures. 
> >     
> >     My team decided that data must be paginated on
> > database to avoid excessive web server memory
> usage.
> > So, stored procedures receive a given page as
> > parameter and return records based on that page.
> >     
> >     So, I'd like to have an engine that calls a
> given
> > stored procedure to get data for a given page on
> each
> > pagination request.
> >     
> >     I was trying to do that writing a custom
> > javax.faces.model.DataModel... but it appears
> hard...
> >     
> > 
> It is not that hard, although not too easy thanks to
> the overcomplicated 
> api, the main problem you face by implementing your
> own DataTable is to 
> have clear demarkation points on when you can aquire
> the DB resources 
> and when you can release them, there is simply no
> mechanism defined to 
> achive that.
> 
> Currently there are several ways known to me:
> 
> a) you can prefetch a page and serve the data from
> an internal cache 
> (which is the approach I follow currently)
> b) you can use some kind of interceptor/filter on
> the servlet, which 
> notifies the datamodel of the beginning of the
> request and the end of 
> rendering, so that you can do the resource
> management.
> There are currently several solutions preimplemented
> which can achieve 
> exactly that:
> 
> In Spring you have the OpenSessionInViewFilter
> class/interface
> and in Shale the ViewController Interface also can
> solve the problem.
> Also using ViewStateListeners on the first and last
> state of the refresh 
> cycle which notify any models currently in existence
> might work as well, 
> very elegantly.
> 
> The rest is more or less implementing the
> mechanisms, which are defined 
> by the base classes.
> 
> Approach a) might be the hardest of all, because
> adding a caching layer 
> to the datamodel, adds another dimension of
> complexity, if I had to do 
> it again, I probably ould use approach b) which was
> unknown to me when I 
> did a)
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: dataScroller" Event Listener... exists?

Posted by Werner Punz <we...@gmx.at>.
Joao Bortoletto wrote:
> Hi Alexander,
> 
>     Thanks for your response!
>     I've studying the example source code. It works
> fine but, like you said, I'm trying to do special
> things... here we go:
>     
>     I have a system that access data by oracle stored
> procedures. 
>     
>     My team decided that data must be paginated on
> database to avoid excessive web server memory usage.
> So, stored procedures receive a given page as
> parameter and return records based on that page.
>     
>     So, I'd like to have an engine that calls a given
> stored procedure to get data for a given page on each
> pagination request.
>     
>     I was trying to do that writing a custom
> javax.faces.model.DataModel... but it appears hard...
>     
> 
It is not that hard, although not too easy thanks to the overcomplicated 
api, the main problem you face by implementing your own DataTable is to 
have clear demarkation points on when you can aquire the DB resources 
and when you can release them, there is simply no mechanism defined to 
achive that.

Currently there are several ways known to me:

a) you can prefetch a page and serve the data from an internal cache 
(which is the approach I follow currently)
b) you can use some kind of interceptor/filter on the servlet, which 
notifies the datamodel of the beginning of the request and the end of 
rendering, so that you can do the resource management.
There are currently several solutions preimplemented which can achieve 
exactly that:

In Spring you have the OpenSessionInViewFilter class/interface
and in Shale the ViewController Interface also can solve the problem.
Also using ViewStateListeners on the first and last state of the refresh 
cycle which notify any models currently in existence might work as well, 
very elegantly.

The rest is more or less implementing the mechanisms, which are defined 
by the base classes.

Approach a) might be the hardest of all, because adding a caching layer 
to the datamodel, adds another dimension of complexity, if I had to do 
it again, I probably ould use approach b) which was unknown to me when I 
did a)


RE: dataScroller" Event Listener... exists?

Posted by Catalin Kormos <ca...@yahoo.com>.
Hi Joao,

Check this out:
http://issues.apache.org/jira/browse/MYFACES-47

I've started to implement once that kind of listener
tag, but for now don't have the time to finish it, but
definetly do it in the near future. 

Hope this helps,
Catalin

--- "Jesse Alexander (KBSA 21)"
<al...@credit-suisse.com> wrote:

> Hi Joao
> 
> Best way to find this out is, to look at the
> samples.
> 
> The impression I got was this:
> - You give the complete collection of items to the
> dataTable
> - You configure the datascroller for the datatable
> - Bingo that's all. The table is now "scrollable"
> 
> You will need more details only if you are about the
> try
> very special things. And before doing that, it might
> be better 
> to "play around" with the standard features.
> 
> Now what did you want to do in your
> "pageChangeListener"?
> If you give us more details, we can help you better.
> 
> hope this helps 
> Alexander 
> 
> -----Original Message-----
> From: Joao Bortoletto [mailto:jbortoletto@yahoo.com]
> 
> Sent: Tuesday, June 28, 2005 3:53 PM
> To: users@myfaces.apache.org
> Subject: "x:dataScroller" Event Listener... exists?
> 
> Hi friends,
> 
>     I'm starting a project with MyFaces! It appears
> very cool!!! But I'm having some understand
> problems...
>     I've reading the documentation that said "JSF
> works like Struts and Swing". 
>     So... how can I handle an event over a
> "dataScroler" component? 
>     Is there any event listener class like
> "pageChangeListener" I can implement?
>     
> 
>     Thanks a lot!
> 
>     Joao Bortoletto
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> http://mail.yahoo.com 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

RE: dataScroller" Event Listener... exists?

Posted by Joao Bortoletto <jb...@yahoo.com>.
Hi Alexander,

    Thanks for your response!
    I've studying the example source code. It works
fine but, like you said, I'm trying to do special
things... here we go:
    
    I have a system that access data by oracle stored
procedures. 
    
    My team decided that data must be paginated on
database to avoid excessive web server memory usage.
So, stored procedures receive a given page as
parameter and return records based on that page.
    
    So, I'd like to have an engine that calls a given
stored procedure to get data for a given page on each
pagination request.
    
    I was trying to do that writing a custom
javax.faces.model.DataModel... but it appears hard...
    
    Best regards,
    
    Joao Bortoletto

--- "Jesse Alexander (KBSA 21)"
<al...@credit-suisse.com> wrote:

> Hi Joao
> 
> Best way to find this out is, to look at the
> samples.
> 
> The impression I got was this:
> - You give the complete collection of items to the
> dataTable
> - You configure the datascroller for the datatable
> - Bingo that's all. The table is now "scrollable"
> 
> You will need more details only if you are about the
> try
> very special things. And before doing that, it might
> be better 
> to "play around" with the standard features.
> 
> Now what did you want to do in your
> "pageChangeListener"?
> If you give us more details, we can help you better.
> 
> hope this helps 
> Alexander 
> 
> -----Original Message-----
> From: Joao Bortoletto [mailto:jbortoletto@yahoo.com]
> 
> Sent: Tuesday, June 28, 2005 3:53 PM
> To: users@myfaces.apache.org
> Subject: "x:dataScroller" Event Listener... exists?
> 
> Hi friends,
> 
>     I'm starting a project with MyFaces! It appears
> very cool!!! But I'm having some understand
> problems...
>     I've reading the documentation that said "JSF
> works like Struts and Swing". 
>     So... how can I handle an event over a
> "dataScroler" component? 
>     Is there any event listener class like
> "pageChangeListener" I can implement?
>     
> 
>     Thanks a lot!
> 
>     Joao Bortoletto
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> http://mail.yahoo.com 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com