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:
<f:view>
<t:saveState id="_state" value="#{departmentBean._state}" />
 
 
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

Reply via email to