Board index JavaServer Faces General How to get p:datatable selection on composite component?

How to get p:datatable selection on composite component?

Components, Ajax Framework, Utilities and More.


Posts: 117
I have a composite component for search, consists of:
1. keyword textfield
2. "Find" command button
3. p:datatable
4. "Select" command button

When user clicks "Find" button, my app will query existing data based on keyword, with query passed from component calls, and render the result to existing datatable. The datatable itself has single selection. The question is, how can i can get selected row to be processed?

Here is the composite:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
   xmlns:ui="http://java.sun.com/jsf/facelets"
   xmlns:h="http://java.sun.com/jsf/html"
   xmlns:f="http://java.sun.com/jsf/core"
   xmlns:p="http://primefaces.prime.com.tr/ui"
   xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
   <composite:attribute name="findLabel" default="Find" />
   <composite:attribute name="selectLabel" default="Select" />
   <composite:attribute name="cancelLabel" default="Cancel" />
   <composite:attribute name="widgetVar" default="widgetVarTOV" />
   <composite:attribute name="query" type="java.lang.String"
      required="true" />
   <composite:attribute name="columnHeader_01" default="Column 01" />
   <composite:attribute name="columnHeader_02" default="Column 02" />
   <composite:attribute name="renderColumn_01" default="true" />
   <composite:attribute name="renderColumn_02" default="true" />
   <composite:actionSource name="btnFind" />
   <composite:attribute name="findListener" method-signature="void find()"
      required="true" />
   <composite:attribute name="selectListener"
      method-signature="void select()" required="true" />
</composite:interface>

<composite:implementation>
   <p:dialog widgetVar="#{cc.attrs.widgetVar}" modal="true">
      <table>
         <tbody>
            <tr>
               <td><h:inputHidden id="hdnQuery" value="#{cc.attrs.query}"
                  binding="#{tableOfValuesBean.hdnQuery}" /> <h:inputText
                  id="txtKeyword" value="#{tableOfValuesBean.keyword}"
                  maxlength="50" size="50" /><span style="padding-left: 10px" /><p:commandButton
                  id="btnFind" actionListener="#{tableOfValuesBean.doFind}"
                  update="tblValues" value="#{cc.attrs.findLabel}" /></td>
            </tr>
            <tr>
               <td><p:dataTable id="tblValues"
                  value="#{tableOfValuesBean.listValues}" var="row"
                  selection="#{tableOfValuesBean.selectedRow}">
                  <p:column selectionMode="single"/>
                  <p:column headerText="#{cc.attrs.columnHeader_01}"
                     rendered="#{cc.attrs.renderColumn_01}">
                     <h:outputText value="#{row.column_01}" />
                  </p:column>
                  <p:column headerText="#{cc.attrs.columnHeader_02}"
                     rendered="#{cc.attrs.renderColumn_02}">
                     <h:outputText value="#{row.column_02}" />
                  </p:column>
               </p:dataTable></td>
            </tr>
            <tr>
               <td></td>
            </tr>
            <tr>
               <td align="right"><p:commandButton
                  value="#{cc.attrs.cancelLabel}"
                  onclick="#{cc.attrs.widgetVar}.hide()" /> <p:commandButton
                  value="#{cc.attrs.selectLabel}"
                  action="#{cc.attrs.selectListener}" /></td>
            </tr>
         </tbody>
      </table>
   </p:dialog>
</composite:implementation>
</html>


I need to get selected row (bind to #{tableOfValuesBean.selectedRow}) to be processed on #{cc.attrs.selectListener}. Any idea how to do this? Thanks in advance
Tomcat 7.0.25
Mojarra 2.1.6
Primefaces 3.1, 3.2
Firefox 10 and IE 7/IE 8


Posts: 5
did u resolve this? how?


Return to General

cron