0

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>
Yurii
  • 4,811
  • 7
  • 32
  • 41
Simon L
  • 173
  • 1
  • 11
  • What type of Scope you are using? – ashokhein Sep 12 '14 at 05:31
  • Your problem is covered by points 4 and/or 5 of http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked – BalusC Sep 12 '14 at 06:34
  • @BalusC I changed my controller from `@Model` which include `@RequestScoped` to `@ManagedBean @ViewScoped`, now it works. But I don't know why the `@RequestScoped` will cause this issue. And also can you show me how to get the active selected row by not inserting a button/link in each row? – Simon L Sep 12 '14 at 14:26
  • Both CDI and JSF have their own bean scopes from reqeust, session, application etc., like `@javax.enterprise.context.RequestScoped` and `@javax.faces.bean.RequestScoped`, but JSF has ViewScoped which CDI doesn't have. What's the difference between the 2 set of scope annotation? – Simon L Sep 12 '14 at 15:03

0 Answers0