0

I have a <p:datatable> where the user can select the radio button corresponding to a row in order to update that row. As of now, I populate another datatable with the information to edit by having the user click a button that calls a method. However, I would like to have the second datatable populated right when the user clicks the radio button of their desired row.

<h:form id="dataForm">
    <p:panel styleClass="center" id="dataPanel">
        <!-- This is where the results of the search are displayed. -->
        <p:dataTable id="metadataitems" var="result"
            value="#{updateMetadataItemsBean.results}" styleClass="center"
            resizableColumns="true"
            selection="#{updateMetadataItemsBean.selectedMetadataItem}"
            rowKey="#{result.rowKey}" rendered="#{updateMetadataItemsBean.show}">
            <p:ajax event="rowSelectRadio" listener="#{updateMetadataItemsBean.prepareEdit}" />
            <p:column headerText="Select Item to Update" selectionMode="single" update="dataForm"></p:column>
        </p:dataTable>
    </p:panel>
    <p:panel styleClass="centered" id="dataPanel2"
        style="font-size:.75em;">
        <p:messages id="message2" showDetails="true" />
        <p:dataTable value="" var="metadataitemsInput" id="editTable">
            <!--This is what I want to update-->
        </p:dataTable>
        <p:commandButton id="submit" value="Submit"
            action="#{updateMetadataItemsBean.edit}"
            update="message2, dataForm:dataPanel" />
        <p:commandButton id="delete" value="Delete"
            action="#{updateMetadataItemsBean.delete}"
            update="message2, dataForm:dataPanel" />
    </p:panel>
</h:form>

I can't find a way to call my method as soon as the user clicks one of the radio buttons.

This is the method that its supposed to call:

public void prepareEdit(SelectEvent e) {
        //set variables that are references by <p:inplace> in datatable
    }
Cory
  • 33
  • 1
  • 12
  • Use ajax events. See http://www.primefaces.org/showcase/ui/data/datatable/selection.xhtml And next time you post code, make it an mcve. Way to noisy now – Kukeltje Jul 09 '15 at 20:51
  • How can an ajax event work with selectionMode="single" though? I tried to place the event inside the column with the selection radio button, but it said that ajax events can't be attached to non-clienholder parents. – Cory Jul 09 '15 at 20:59
  • @Kukeltje I've also updated the code to make it a bit easier to read – Cory Jul 09 '15 at 21:03
  • Same way as in the showcase. Add the ajax tag as a direct child of the datatable. If it was different, there would have been a different example – Kukeltje Jul 09 '15 at 21:14
  • You can reduce tbe code way more. All br tags, outpulabels etc – Kukeltje Jul 09 '15 at 21:17
  • @Kukeltje , I tried rowSelect and rowSelectRadio, with SelectEvent in my bean, and neither are working. Is the issue maybe the selectionmode attribute being used, since its not a regular radio button? – Cory Jul 09 '15 at 21:20
  • What PF version? And please add the code you tried to the question. Incl. The bean – Kukeltje Jul 09 '15 at 21:37
  • Try to update only the `p:panel` which contains the second `p:dataTable` and also add a correct `value` for it. Maybe this question can help you. http://stackoverflow.com/questions/27803017/primefaces-datatable-update-datatable – Miguel Jul 10 '15 at 08:02
  • @Kukeltje I added the method that I'm supposed to call. Sorry for taking so long to update. – Cory Jul 10 '15 at 13:46
  • Where is your ajax tag? – Kukeltje Jul 10 '15 at 13:54
  • @Kukeltje , I forgot to update the code here form my xhtml page, its there now. – Cory Jul 10 '15 at 14:03

0 Answers0