I am new to JSF, I couldn't sort it out. Any prompt explanation is appreciated.
My case is fairly simple, I have a <h:dataTable>
display a list of query result, I want to get the selected row and trigger a method in my controller for further operation (like modify or delete). If I put commandButton inside the dataTable, as the doSth2
, it doesn't get into the action method doSth() in MyController class, but if I move the button outside the dataTable, like the doSth1
, it works perfectly. Can anyone explain why there is such a difference.
BTW, how can I get the active selected row in the dataTable and pass it to the action method. Actually I read some threads which show that you can pass the row data by action="#{myController.doSth(_tran)}"
. First this doesn't work in my case, I don't like the doSth2
button to be displayed in every row of the table either. Thanks a lot.
<h:form id="form1">
<p>
<h:panelGrid columns="4">
<h:commandButton id="otherButton" .../>
<h:commandButton id="doSth1" value="doSth1" styleClass="pushbutton"
action="#{myController.doSth}"/>
</h:panelGrid>
</p>
</h:form>
...
<h:form id="form2">
<h:dataTable var="_tran" value="#{trans}" rendered="#{not empty trans}" styleClass="simpletablestyle">
<h:column>
<f:facet name="header">col1</f:facet>
#{_tran.id}
</h:column>
...
<h:column>
<h:commandButton id="doSth2" value="doSth2" styleClass="pushbutton"
action="#{myController.doSth}"/>
</h:column>
</h:dataTable>
</h:form>