An Introduction To JBoss RichFaces
One thing you probably noticed is that you have a blue color schema while my screen shots have red color schema. I'm using a different skin. If you would like to change the skin, that's very easy to do. Open WEB-INF/web.xml file and change the skin parameter to ruby:
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>ruby</param-value>
</context-param>
Save and restart the server.
One thing that's still different is the font size. If you also want to change that, check out this blog entry.
Adding a modal panel
We will first create the modal panel. The modal panel has to be placed outside the original form, because it must have its own form:
<rich:modalPanel id="useredit">
<f:facet name="header">
User
</f:facet>
<h:form>
<h:panelGrid id="userinfo">
<h:outputLabel for="nameInput" value="Name:"/>
<h:inputText id="nameInput" value="#{userBean.selectedUser.name}"/>
<h:outputLabel for="emailInput" value="Email:"/>
<h:inputText id="emailInput" value="#{userBean.selectedUser.email}"/>
<h:panelGrid columns="2">
<a href="#" onclick="#{rich:component('useredit')}.hide();return false">
Close
</a>
<a4j:commandLink oncomplete="#{rich:component('useredit')}.hide();return false">
Save
</a4j:commandLink>
</h:panelGrid>
</h:panelGrid>
</h:form>
</rich:modalPanel>
The code is rather simple, I will talk about the Close and Save links shortly.
Next, we need to open the popup. To do that, we are going to add another column to the table. The column will contain a button to open the popup. We will make this column first. The coding looks like this:
...
<h:column>
<a4j:commandButton value="Edit"
oncomplete="#{rich:component('useredit')}.show()"
reRender="userinfo">
<f:setPropertyActionListener value="#{user}"
target="#{userBean.selectedUser}" />
</a4j:commandButton>
</h:column>
...
For both showing and hiding the modal panel, we use the RichFaces client-side function called #{rich:component('id')} to get a reference to the component (in our case, it’s the modal panel). Once we have a reference, we call the JavaScript API on that component. In our case, it is show() to open and hide() to close the modal panel. Later, we will be calling a save method when the Save button is clicked in the modal panel.
How do we know which row was selected which corresponds to the user we would like to edit. To accomplish that we use a standard JSF tag called f:setPropertyActionListener. It's basically a listener that will take the object in the current row and assign it to userBean.selectedUser property inside the managed bean. We don't yet have this property, so let's add it.
private User selectedUser;
public User getSelectedUser() {
return selectedUser;
}
public void setSelectedUser(User selectedUser) {
this.selectedUser = selectedUser;
}
Before we test this, there is one more thing to mention. Notice that the Edit button’s definition has a reRender attribute set to "userinfo". This is needed in order to rerender the selected user information. We first pass the selected user to the server. When the page is rendered back to the browser, we would like to rerender that property (userSelected) in order to display the selected user.
Go ahead and run the application as we did before. Before you run, make sure everything is saved and all the changes have been deployed. Your page should look like this:

We are now able to click on a particular row and display the user information in the modal panel. What we ultimately want to do is be able to edit user information, but only update the particular row for that user, instead of updating the whole table.
(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