dataTable中的commandLink未被调用

时间:2015-08-05 19:06:18

标签: jsf datatable managed-bean commandlink

我在dataTable中调用commandLink操作时遇到问题。

<h:body>
    <h:dataTable value="#{manageStaffAccountBean.accounts}" var="staff">
        <h:column>
            #{staff.surname} 
        </h:column>
        <h:column>
            <h:form>                        
                <h:commandButton value="Change status" 
                    action="#{manageStaffAccountBean.changeActivity(staff)}" />
            </h:form>
        </h:column>
    </h:dataTable>
</h:body>

点击&#34;更改状态&#34;我需要在bean中调用changeActivity()方法

Managed Bean代码:

@Named
@Scope("request")
public class ManageStaffAccountBean implements Serializable {   

    private List<Staff> accounts = null;

    public String changeActivity(Staff staff){          
        System.out.println(staff.getId());

        return "manageStaffAccounts";
    }

    public void updateAccountsList(){
        accounts = staffService.findAll();      
    }

    // ...
}

但是,它没有被调用。你能帮我找到问题吗?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。如果我们在h:dataTable中使用h:commandButton,我们的manage bean应该具有范围“session”,否则按钮将不起作用。只是JSF魔术