How to Add Command Buttons to Data Tables with RichFaces 3.3.x

faces-config.xml

<?xml version="1.0"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
  <managed-bean>
    <managed-bean-name>sample</managed-bean-name>
    <managed-bean-class>br.eti.fernandoribeiro.sample.SampleBean</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope> <!-- required as mentioned in http://java.net/jira/browse/JAVASERVERFACES-69 -->
  </managed-bean>
</faces-config>

page.xhtml

<?xml version="1.0" encoding="ISO-8859-1"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.org/rich" xmlns:ui="http://java.sun.com/jsf/facelets">
  <h:form>
    <rich:dataTable value="#{sample.itemList}" var="item">
      <rich:column>
        <f:facet name="header">
          <h:outputText value="Message" />
        </f:facet>
        <h:outputText value="#{item.msg}" />
      </rich:column>
      <rich:column>
        <f:facet name="header">
          <h:outputText value="Action" />
        </f:facet>
        <h:commandButton action="#{sample.sendMessage}" value="Say Hello">
          <f:setPropertyActionListener target="#{sampleBean.msg}" value="#{item.msg}" />
        </h:commandButton>
      </rich:column>
    </rich:dataTable>
  </h:form>
</ui:composition>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s