Forums Register Login

How to accessing PhaseId from managed bean

+Pie Number of slices to send: Send
Hi

I want to access the current PhaseId when a method is called on a managed bean given that the bean has not implemented the PhaseListener interface. Means to know what is the current phase in which this method is being called. Is it possible? I have googled but could not find any working way.

Regards
+Pie Number of slices to send: Send
If you want a backing bean to know what phase its methods are being called from, you're probably about to do something horrible. Backing beans are supposed to be essentially POJOs.

As far as it goes, the phases that invoke the various methods are quite predictable, but since the methods themselves shouldn't exhibit variant behavior depending on phase, there's not much point in knowing. Phase Listeners are not normally backing bean objects.
+Pie Number of slices to send: Send
well, not that much horrible..
Actually I am stuck with a problem in doing true pagination. Here is the code

The backing bean



The class that extends DataModel for pagination



the jsf page



Now here when the first time page is loaded, everything is ok. When I hit '2' to show the second page, the method "getTableModel" in 'Paginator' backing bean is called three times. first in "APPLY_REQUEST_VALUES" phase and then two time is in "RENDER_RESPONSE" phase. In real situation where data base will be involved it means three database hits which is surly not a good thing. First I dont want database hit in "APPLY_REQUEST_VALUES" phase as it will again query db. If I get to know that this method is being called in "APPLY_REQUEST_VALUES" phase then I can restrict it.and Secondly, I have no Idea that why is the "getTableModel" method called twice in "RENDER_RESPONSE" phase.

Thanks in advance
+Pie Number of slices to send: Send
You are planning something horrible. Getter methods should not have side-effects, nor should they attempt to do extensive logic. It's not good practice even for POJOS, and JSF backing bean "get" methods can be invoked multiple times, depending on the context. Even within the same phase.

You should do your paging in the action processors, not in "get" methods. If you're trying to avoid using a session-scope object, you're not going to have an easy time of it. Depending on the version of JSF you're using, a request-scope object could set up the datamodel in a @PostConstruct method. Or in JSF2, you can use View scope. For earlier versions of JSF, it's better to just use session scope, but release the datamodel when you're done with it (in the action method that takes you away from that view).

In certain rare cases, I have been forced to setup something in a "get" method. The way I did it was like this:
Crusading Chameleon likes the size of this ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2801 times.
Similar Threads
passing parameter from non JSF URL to JSF backing bean
EJB file descriptor for the Stateless Bean
How to assign a value to a request scoped managed bean property?
questions about setRollbackOnly() for BMT
Passing Params
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:34:32.