0

I would like to get the id of datatables row to call click() on a hidden button in the same table cell. It is done that way because all buttons have to look like h:commandButton and i couldn't force p:commandButton look like them. And h:commandbutton doesn't have oncomplete event. I know I could use DataModel, but is there another way to do it (using JS, JQuery)? When i put hardoced id (p:table:4:hiddenButton) everything is ok, but how to get that row number for each cell??

<h:form id="p">
 <h:dataTable value="#{bean.paymentList}" var="pmt" id="table" >
   ...
    <h:column>
    <f:facet name="header">
      <h:outputText value="#{bundle.action}" />
     </f:facet>
     <h:commandButton  type="button" value="#{bundle.approve}" 
            onclick="document.getElementById('p:table:??:hiddenButton').click();" />
      <p:commandButton  id="hiddenButton" value="hidden" style="display: none;"
       oncomplete="if (#{pmt.errorsNum} > 0) {
       return confErrDial.show();
       } else {
       return confDial.show();};">
      <f:setPropertyActionListener value="#{pmt.id}" target="#{bean.holder}" />
      </p:commandButton>
     </h:column>
 </h:dataTable>
</h:form>

EDIT:

Ok i did some trick using JQuery, it may be not nice but works.

What I did: I added id to h:commandButton and on onclick event i get id of h:commandButton and replace its id with id of hidden p:commandbutton, so its code is now:

<h:commandButton id="button" type="button" value="#{bundle.approve}" 
onclick="document.getElementById(($(this).attr('id')).replace('button','hiddenButton')).click();"

Still maybe someone knows better solution.

PS: It is strange because $(this).parent().attr('id') is null. I think it has something with that no element is created with id p:table:0 p:table:1 etc...

  • 1
    if you want `oncomplete` in `h:commandButton` look in my answer over here http://stackoverflow.com/a/15806084/617373 – Daniel Aug 08 '13 at 10:45
  • @Daniel thanks for your answer , but i have another problem with h:commandButton - it doesn't sets property with f:setPropertyActionListener, I could use f:param but i would like to avoid changeing bean code. But I used your solution in other place (one less p:commandButton :) , thanks! ) – michalorlik Aug 08 '13 at 11:11
  • 1
    That's because you forgot to remove `type="button"` or to include `f:ajax`. All with all, this approach is pretty clumsy. – BalusC Aug 08 '13 at 12:14
  • Yeah with that f:setPropertyActionListener works. Now i have two working solutions and i'll leave the choice to team leader. Thanks! – michalorlik Aug 08 '13 at 12:47

0 Answers0