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 <[EMAIL PROTECTED]> 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


Reply via email to