myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iSquareOne LLC <isquare...@yahoo.com>
Subject Re: How to tell if the request is the first time or the consequential call to the same page?
Date Tue, 25 Apr 2006 19:27:41 GMT
Thanks, Dennis,
  Right now, we are not ready to upgrade to the latest MyFaces yet.  However, I figured out
a hack to get this resolved. What I did was:
  1. Set a param in the page bean, say sequence, and save this sequence in t:saveState. It's
initial value is 0
  2. In the getters for first field on the jsp page (has to be the first  field), check if
sequence = 0. If it's 0, it's the first request to  this page, preload the records and then
change sequence = 1, otherwise,  it's the consequential calls so do not search database again.
  
  The trick is before the getter for the first field is called, the state  has been restored,
i.e., sequence = 1 in the consequential calls.
  
  Hope it may help whoever is running into this issue.
  
  - Shawn
  iSquareOne LLC

Dennis Byrne <dennis@dbyrne.net> wrote:The  latest release of MyFaces is 1.1.3 . There
is an HTTP parameter called  jsf_sequence that can be used to figure this out. You of course
would  want to put this behind a layer of abstraction in order to make a  possible future
transition to a different vendor less painful. I seem  to remember this being a requirement
for JSF 1.2, which the MyFaces  team will be sinking their teeth into very soon.

Dennis Byrne

>-----Original Message-----
>From: iSquareOne LLC [mailto:isquareone@yahoo.com]
>Sent: Sunday, April 23, 2006 09:16 PM
>To: users@myfaces.apache.org
>Subject: How to tell if the request is the first time or the consequential call to the
same page?
>
>    Hi, all,
>  I am new to this list. If my question is something that people have  asked, my apologies.
We have been actively using MyFaces in our  development for 3 months and so far everything
is fine. There are some  glitches, but we got around them. However I don’t know the answer
for  this one. Hope you all can share your opinions. Thanks in advance!
>
>      The functional requirement is:
>  On a page, say Department page, there are save, search, next, prev  links. If the user
opens this page for the first time (ie. without any  actions), load the page with all records;
otherwise, perform the action  that user clicks (if the user clicks the search, the program
should  return the matching records etc.)
>
> This page was backed  by a session scope page bean. But now, we changed it to the request
 scope. Then here is the problem: when the bean was a session scope  bean, I put the default
search call in the constructor, so that when  the page is loaded, the default search is performed
when the bean is  initialized. But now, the bean is request scope, every time it will be 
constructed, so the default search call is called every time. However,  if I move the default
search call outside the constructor, when the  page is loaded for the first time, it won’t
be called, so the page is  not loaded with records.
>
> So, my question is – is there  a way to tell if the request is the first time or the
consequential  call to the same page?
>
>      Code Snippet:
>      In the bean:
>                  public  DepartmentBean()
>                  {
>                               super();
>                               //  Initializes the delegate
>                               delegate  = (DepartmentDelegate) DelegateFactory
>                                                       .getDelegate(DepartmentDelegate.class);
>
>                               delegate.findAll();
>
>                  }
>
>      To maintain the data from Department page to the next call  to the Department page,
we use t:saveState:
>      
>      
>
>
>      So in DepartmentBean, there are also getter/setter to  populate the current page
state again.
>
>                  public void  set_state(PageGridScalarEditableBeanState _state)
>                  {
>                               searchParams  = _state.getSearchParams();
>                               searchMode  = _state.isSearchMode();
>                               editMode  = _state.isEditMode();
>                               gridBackwardable  = _state.isGridBackwardable();
>                               gridForwardable  = _state.isGridForwardable();
>                  }
>
>                  public PageState  get_state()
>                  {
>                               _state.setSearchParams(searchParams);
>                               _state.setSearchMode(searchMode);
>                               _state.setEditMode(editMode);
>                               _state.setGridBackwardable(gridBackwardable);
>                               _state.setGridForwardable(gridForwardable);
>                               return  _state;
>                  }
>
>  Notice one thing: the _state is not populated during the construction  time, so I can’t
use these variables in set_state() to determine if the  request is the first call.
>
>      Again thanks!
>
>      - Shawn
>
>   
>---------------------------------
>Celebrate Earth Day everyday!  Discover 10 things you can do to help slow climate change.
Yahoo! Earth Day




		
---------------------------------
Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates.
Mime
View raw message