One of the JSF 2+ nice features presented in Java enterprise edition JavaEE 6+, is that you can pass parameters to any action components action method like commandButton or commandLink components.
I liked this feature too much enjoy it, very helpful and handy, and happy coding.
References:
1- JavaEE 7 tutorial (7.5 Navigation Model).
Based on that you can minimize the number of methods inside your managed bean.How it works:
In addition, to minimize many parameters to set inside the bean to be used by action to decide navigation logic, which reduce memory consumption if your beans in scopes greater than request scope.
- Open your favorite IDE, I am going to use Netbeans 7.4.1. (Use any IDE that supports JavaEE 6 or 7).
- Create web project.
File --> New Project --> Java Web (left pan) --> Web Application (right pan) --> Next.
- Name it whatever you like (JSFeatures for me)--> Next --> Server Glassfish4 --> Java EE 7 Web profile --> Context path "/JSFeatures" --> Next.
- From frameworks chose "Java Server Faces" --> Finish.
- You should have project structure like this:
- Right click on the JSFeatures project --> new "JSF Managed Bean". and its name and config like this:
- With the bean opened in the editor page, copy and paste the following code after package statement:
- Open the index.xhtml which is generated by default, and copy the following code and past it in your file:
- Right click on the index.xhtml then --> Run; you should see something like this:
- Click submit button and watch h:outputText value, its value should be "Hi there I am an action method."
- Now everything is working fine. Let us do the actual work I need to demonstrate.
- Change addNumbers() method signature to the following (without restarting the application server):
- Bean method:
- Then your button call to:
- Press the button and output text value should be:
- Bean method:
- 13. Do it one more time:
- Bean method:
- Then your button call to:
- Press the button and output text value should be:
- Bean method:
I liked this feature too much enjoy it, very helpful and handy, and happy coding.
References:
1- JavaEE 7 tutorial (7.5 Navigation Model).
No comments :
Post a Comment