This time we are going to use managed bean class and Primefaces UI component alongside our JSF framework. To see how to add Primefaces to your project, you can have look at here.
Firstly, create a new dynamic project and do not forget to add JSF and Primefaces libraries. The final project structure will look like below:
Let's start with the UserBean managedbean class. It is a standard java class with @ManagedBean annotation on it. It has variable declarations and getter setter methods and business logic. I am going to use a basic managed bean class here but I might post more detailed writing about managed beans in the following weeks explaining each annotation. Our UserBean class will look like below.(By the way I still couldn't figure out how to add code blocks in my blogger:( So until I find a solution I will have to post my codes like this. Sorry for that.)
To create index.xhtml, you can first choose a new html page and then select your custom page template. index.xhtml will look like below. Pay close attention to the namespace declarations. In the body, we have a form to get information from the client. As you can see, we store all the information from client in the managedbean. A JSF page has a request life cycle. So name, age and message values are set to managed bean attributes before the action. The commandButton's action will invoke getValues method in the managed bean.In index.xhtml I added some controls using Primefaces' components for example name field is required and Message field has a character counter.<p:panel> is also a Primefaces component.
In display.xhtml we simply display the values that were applied to the managed bean earlier. You can see display.xhtml below.
As usual you can alter <welcome-file-list> in web.xml file.
Hope to see you in the next blog post!
Selen
No comments:
Post a Comment