In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to control JSF from the entry point of JSF. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
The JSF framework is a very flexible and powerful framework. Almost every component of it is replaceable-its default implementation can be replaced with a user-defined functional implementation. At the same time, a number of entry points (pluggable mechanisms, similar to plug-in concepts) are provided for users to control various stages of the JSF life cycle to achieve their own goals. Here are several common pointcuts to control the JSF lifecycle.
We know that JSF divides the whole life cycle into six phases: restore view (overloaded View), apply request value (Application request values), process validation (legitimacy check), update model value (Update Model values), invork application (event handling) and render (Picture redrawing).
How to cut into the life cycle of JSF? JSF provides a number of methods:
1. Cut in from Lifecycle.
Lifecycle is the control center of JSF life cycle, which is equivalent to the human heart, and its importance and position can be imagined. In Lifecycle, it is mainly responsible for invoking the six phases of the life cycle mentioned above. Even for such an important control center, JSF also provides a way to cut in so that we can completely replace it.
1) first, you need to define the following in web.xml to let JSF know that you want to use your own Lifecyle implementation instead of the default Lifecycle implementation.
Javax.faces.LIFECYCLE_ID
Yourself.LifecyleImpl
2) the yourself.LifecyleImpl mentioned above is your own Lifecyle implementation, which must inherit from the javax.faces.lifecycle.Lifecycle virtual class and implement the virtual methods in it.
Because JSF provides many other ways for you to control JSF, it is not recommended to control JSF directly from the implementation of Lifecyle unless specifically required.
2. Cut in from PhaseListener.
PhaseListener, to put it simply, is the entry point for monitoring the above six stages. We can do this through the following steps:
1) configure phase-listener in JSF's configuration file such as faces-config.xml to tell JSF that we need to monitor its life cycle.
Yourself.YourPhaseListener
2) yourself.YourPhaseListener is your own phase-listener implementation. It must implement the javax.faces.event.PhaseListener interface. It provides three ways for you to do what you want to do:
Public void beforePhase (PhaseEvent phaseEvent): called before each phase is processed
Public void afterPhase (PhaseEvent phaseEvent): called after each phase is processed
Public PhaseId getPhaseId (): tell JSF which phase you want to monitor. You can specify one or all phases.
3. Cut in from ActionListener.
When a button is pressed or a command link is clicked, JSF invokes the pre-bound event handling method through ActionListener during the broadcast event of the invork application phase. If there is a user-defined ActionListener, JSF uses the user-defined ActionListener instead of the default ActionListener.
User-defined ActionListener must implement javax.faces.event.ActionListener interface and its interface method: public void processAction (ActionEvent actionEvent). Note that in this implementation, you must call the control's event handling method (the event handling method in JSF Backing Bean), and do image migration and other your own handling on its return value.
Import javax.el.ELContext; import javax.el.ELException; import javax.el.ExpressionFactory; import javax.el.MethodExpression; import javax.faces.application.Application; import javax.faces.application.NavigationHandler; import javax.faces.context.FacesContext; import javax.faces.event.AbortProcessingException; import javax.faces.event.ActionEvent Ublic class MyActionListener implements javax.faces.event.ActionListener {public void processAction (ActionEvent actionEvent) throws AbortProcessingException {FacesContext context = FacesContext.getCurrentInstance (); Application application = context.getApplication (); ELContext elContext = context.getELContext (); ExpressionFactory ef = context.getApplication (). GetExpressionFactory () MethodExpression me = ef.createMethod_Expression (elContext, "method for hosting bean", Void.TYPE, null); String outcome = null; / / outcome try {me.invoke (elContext, null);} catch (ELException elexp) {Throwable wrapped = elexp.getCause () Wrapped.printStackTrace ();} NavigationHandler navigationHandler = application.getNavigationHandler (); navigationHandler.handleNavigation (context, null, outcome); / / Render Response if needed context.renderResponse () }} above is what the editor shares with you on how to control JSF from the entry point of JSF. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.