An Introduction To JBoss RichFaces
Application
Creating a new project
- Select File/New/JSF Project
- For the project name, enter “richfaces-start”
- For JSF environment, select JSF 1.2, Facelets, RichFaces
- For a template, select one based on the Tomcat version you are using
- Click Finish to create the project
Creating the model class
As we are dealing with users, we are going to create a user model class.
In the JavaSource directory, create an example.model.User Java class and notice the package name:
package example.model;
public class User {
@Override
public String toString() {
return name + " " + email;
}
private String name;
private String email;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public User(String name, String email) {
super();
this.name = name;
this.email = email;
}
}
The class is very simple. Our application will list one or more of these users. Next, we are going to create a managed bean. The managed bean will basically be a model for the user interface we will be building shortly.
Creating the managed bean
In JavaSource, create an example.beans.UserBean Java class. Again, pay attention to the package name:
package example.beans;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import example.model.User;
public class UserBean {
private List <User>users;
public List <User>getUsers() {
return users;
}
@PostConstruct
public void init () {
users = new ArrayList <User>();
users.add (new User("Joe", "joe@gmail.com"));
users.add (new User("Charley", "charley@ymail.com"));
users.add (new User("John", "john@hotmail.com"));
users.add (new User("Greg", "greg@gmail.com"));
users.add (new User("Prescila", "prescila@aol.com"));
}
}
This class is also simple. A list of five users is created and place inside an ArrayList. The @PostConstruct annotation is useful for initializing properties. It guarantees that the annotated method will only be called once when the bean is created.
To make this bean a managed bean, we need to register it in a JSF configuration file.
- Open WebContent/WEB-INF/face-config.xml
- Switch to the Tree view
- Select Managed Beans and click Add...
- Keep the scope request
- For Class, enter the bean’s full Java class name, example.beans.UserBean
- For Name, enter or keep userBean - Click Finish
We are ready to create the user interface.
Managed bean registration looks
like this:
<managed-bean>
<managed-bean-name>userBean</managed-bean-name>
<managed-bean-class>example.beans.UserBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)






Comments
Max Katz replied on Mon, 2009/02/16 - 9:48pm
in response to:
Harshad Khasnis
Max Katz replied on Mon, 2009/02/16 - 9:51pm
in response to:
Asma Shah
nancy xiao replied on Mon, 2009/02/16 - 10:24pm
nancy xiao replied on Mon, 2009/02/16 - 10:24pm
nancy xiao replied on Mon, 2009/02/16 - 10:24pm
Thai Dang Vu replied on Sat, 2009/02/21 - 7:20am
I have a question:
Your "Save" link is in the form in the modal panel and it's going to re-render the columns "name" and "email" which are in another form. How can RichFaces know which form that has the "name" and "email" columns to re-render?
Max Katz replied on Mon, 2009/02/23 - 5:44pm
in response to:
Thai Dang Vu
It first searches the current naming container (form), then it searches the parent container and so on. At some point it will reach the root and search from there.
You can see the full algorithm here: org.ajax4jsf.renderkit.RendererUtils.findComponentFor(UIComponent, String)
Tom Schurmans replied on Wed, 2009/03/04 - 5:56am
Unexpected error processing managed bean userBean com.sun.faces.mgbean.ManagedBeanPreProcessingException: Unexpected error processing managed bean userBean at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:356) at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:201) ...
Caused by: com.sun.faces.mgbean.ManagedBeanPreProcessingException: Unexpected error processing managed property users ...
Caused by: java.lang.NullPointerException at com.sun.faces.mgbean.ManagedBeanBuilder.bakeBeanProperty(ManagedBeanBuilder.java:350) at com.sun.faces.mgbean.ManagedBeanBuilder.bake(ManagedBeanBuilder.java:107) ... 59 more
Any thoughts?
btw, the zip file you included doesn't work here. And the alternative doesn't give the extra "jsf + richfaces option" when you start a new eclipse project. Any chance you can rezip it and upload it somewhere else?
Thanks!
Max Katz replied on Sat, 2009/03/07 - 12:45am
in response to:
Tom Schurmans
@TomSch: You might have an error in Faces config file, can you post it here? As for the zip file, I'll try to upload a new or post a link on my blog.
Jean Chastain replied on Fri, 2009/03/20 - 9:27am
in response to:
Max Katz
Max, I know you're a busy guy, but I want to pick up this thread. I'm running on JBoss 5.0 and have the same problem shahasma99 is having. After the first deploy (before the modal panel is added), all I see it the title. I do have the @PostConstruct before the init(), but when I set a breakpoint on the init(), it doesn't seem to be getting there. Is there some JBoss configuration I'm missing? Or is it just not possible to break there?
TIA, Jean
Kannan Varadharajan replied on Fri, 2009/04/03 - 7:48am
Alex Cbbdjfkdjfkj replied on Fri, 2009/04/03 - 10:26am
Max Katz replied on Thu, 2009/04/09 - 10:32pm
in response to:
Jean Chastain
Max Katz replied on Thu, 2009/04/09 - 10:32pm
in response to:
Kannan Varadharajan
Max Katz replied on Thu, 2009/04/09 - 10:34pm
in response to:
Alex Cbbdjfkdjfkj
Davut Uysal replied on Fri, 2009/04/17 - 2:21am
Nghia Le replied on Mon, 2009/04/27 - 3:41pm
Nick Thomson replied on Thu, 2009/04/30 - 9:36am
Hi Maxkatz,
I'm trying to use the ajaxKeys options with a dataTable as you have described in the article and I've got it working with the dataTable and even using the dataScroller control.
However, once I enable sorting in the data table, the rows do not refresh properly. If the items are sorted in the same order as they are in the List the correct rows are redrawn, but sorting them in any other order results in the required rows not being highlighted.
I'm using Seam 2.1.1.GA and RichFaces 3.3.0.GA, the table looks like this (the keepalive is included but not shown and I've removed some of the columns)..
<rich:dataTable id="testDataTable" value="#{testBean.data}" var="data" ajaxKeys="#{testBean.ajaxKeys}" sortMode="single" rows="20">
<rich:column sortBy="#{data.id}" id="pid" style="#{data.viewing ? 'background: red' : '' }">
<f:facet name="header">
<h:outputText value="ID"/>
</f:facet>
<a4j:commandLink style="display: block; width: 100%;" action="#{testBean.SelectView(data)}" value="#{data.id}" reRender="pid,param1"/>
</rich:column>
<rich:column sortBy="#{data.testParam1}" id="param1" style="#{data.viewing ? 'background: red' : '' }">
<f:facet name="header">
<h:outputText value="Param 1"/>
</f:facet>
<a4j:commandLink style="display: block; width: 100%;" action="#{testBean.SelectView(data)}" value="#{data.testParam1}" reRender="pid,param1"/>
</rich:column>
</rich:dataTable>
And the appropriate bits from the testBean..
Any idea how to fix this?
Thanks,
Nick
Alex Cbbdjfkdjfkj replied on Tue, 2009/05/05 - 9:53am
For those having difficulty (like me!) with the step that says "For JSF environment, select JSF 1.2, Facelets, RichFaces", try this:
- After downloading the template zip file, DON'T just copy and paste the folders into the jboss template folder!
- Copy the richfaces-template-6.zip\lib\jsf-1.2-facelets-richfaces\ to your Eclipse's appropriate folder (for me, it's here: C:\eclipse_ide\plugins\org.jboss.tools.common.projecttemplates_3.0.0.GA-R200903141626-H5\lib)
- Copy the \templates\jsf-1.2-facelets-richfaces\ to your Eclipse folder (something like C:\eclipse_ide\plugins\org.jboss.tools.common.projecttemplates_3.0.0.GA-R200903141626-H5\templates)
- And don't forget the \templates\pages\jsf\
- In other words, you need to go into each downloaded item and copy its contents over to the matching folder on your jboss installation.
If you don't see the RichFaces item in the Eclipse dropdown, then you didn't copy the items over correctly. Try again. Believe it or not, this step messed me up! I finally see that item in the dropdown box and can proceed with the tutorial!Max Katz replied on Tue, 2009/05/05 - 12:13pm
in response to:
Davut Uysal
Max Katz replied on Tue, 2009/05/05 - 12:15pm
in response to:
Nghia Le
Max Katz replied on Tue, 2009/05/05 - 12:18pm
in response to:
Nick Thomson
Max Katz replied on Tue, 2009/05/05 - 12:20pm
Davut Uysal replied on Wed, 2009/05/06 - 12:57pm
in response to:
Max Katz
Debraj Ganguly replied on Sat, 2009/05/09 - 7:56am
I have a page which has a link to open a modal panel (BasePage.jsp)
h:form
..............
..............
a href="#" onclick="#{rich:component(modal_panel)}.show()">#{msg.ShowPanel}/a
...........
.........
/h:form
I am including the modal panel page in the base page after this in a separate form
h:form
ui:include src="MyModalPanel.jsp" /
h:form
MyModalPanel.jsp
----------------------
In this page I have a tab containing a number of and elements.
I also have a a4j:commandButton at the end. I have an action defined for the button.
a4j:commandButton id="save_form" value="Save" image="../../images/Save_bttn.jpg"
action="#{baseBean.save}" reRender="validation_messages_add" ajaxSingle="false" /
I am reRendering the validation message.
My problem
--------------
on clicking the save button the baseBean.save() method is called correctly but the bean is not getting reflected with the user entered value. It still hold the initialized values that i had in the base bean attrib definition.
I changed the a4j:commandButton to h:commandButton and also added the onclick function to hide the modal. I had no problem then but this closed the modal panel and the validation messages on the panle could not be viewed by the user.(page refreshed.)
Can you please guide me why the a4j:commandButton thing is unable to get the form values.
waiting for your reply,
thanks in advance
(I have purposefully ommited the '<' and '>' tags
Annie Cheng replied on Thu, 2009/05/14 - 11:20am
Max Katz replied on Tue, 2009/05/19 - 5:45pm
in response to:
Debraj Ganguly
Sorry, I don't understand the problem. Where is the input field? I'm also surpised that this works, that's JSP with Facelets...:
<ui:include src="MyModalPanel.jsp" />
Max Katz replied on Tue, 2009/05/19 - 5:46pm
in response to:
Annie Cheng
hookfi john replied on Sun, 2009/05/31 - 7:48am
jame jack replied on Mon, 2009/06/29 - 4:23pm