重置< p:selectBooleanCheckbox>页面加载 [英] reset <p:selectBooleanCheckbox> on page load

查看:93
本文介绍了重置< p:selectBooleanCheckbox>页面加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在页面加载时重置?使用JSF或CommandButton的onClick事件

How to reset on page load? Using JSF or onClick event of a CommandButton

请在此处以Javascript或Ajax发布示例

Please post here an example either in Javascript or Ajax

请有人帮我解决这个问题

Please some one help me for this issue

此处是JSF代码

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

</h:head>
<h:body>
    <p:commandButton value="Assign Permission"
        onclick="assignPermissionDlg.show()"></p:commandButton>

    <p:dialog widgetVar="assignPermissionDlg" width="75%">
        <h:form id="form">
            <p:panel>
                <p:dataTable value="#{mainBean.list}" var="perm" id="tableId">

                    <p:column headerText="Module Description:">
                        <h:outputText value="#{perm.name}" />
                    </p:column>
                    <p:column headerText="View">
                        <h:selectBooleanCheckbox id="view" value="#{perm.view}" >

                        </h:selectBooleanCheckbox>
                    </p:column>
                    <p:column headerText="Create">
                        <h:selectBooleanCheckbox id="create" value="#{perm.create}">

                        </h:selectBooleanCheckbox>

                    </p:column>
                    <p:column headerText="Edit">
                        <h:selectBooleanCheckbox id="edit" value="#{perm.edit}">

                        </h:selectBooleanCheckbox>
                    </p:column>
                    <p:column headerText="Delete">
                        <h:selectBooleanCheckbox id="delete" value="#{perm.delete}">

                        </h:selectBooleanCheckbox>
                    </p:column>

                </p:dataTable>
                <p:toolbar>
                    <p:toolbarGroup>
                        <p:commandButton value="Submit"
                            action="#{mainBean.confirmMethod}">

                            <p:confirm header="Confirmation" message="Are you sure?"
                                icon="ui-icon-alert" />
                        </p:commandButton>


                    </p:toolbarGroup>
                </p:toolbar>
                <p:confirmDialog global="true" showEffect="fade"
                    hideEffect="explode">
                    <p:commandButton value="Yes" type="button"
                        styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
                    <p:commandButton value="No" type="button"
                        styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
                </p:confirmDialog>
            </p:panel>
        </h:form>

    </p:dialog>
    <script type="text/javascript">
                $(function() {
                    $(PrimeFaces.escapeClientId('form:tableId'))
                            .on(
                                    "change",
                                    "input[type='checkbox'][name*='edit'], input[type='checkbox'][name*='create'], input[type='checkbox'][name*='delete']",
                                    function() {
                                        var tr = $(this).parent().parent();
                                        var view = tr
                                                .find("input[type='checkbox'][name*='view']");
                                        var create = tr
                                                .find("input[type='checkbox'][name*='create']");
                                        var edit = tr
                                                .find("input[type='checkbox'][name*='edit']");
                                        var deleteBox = tr
                                                .find("input[type='checkbox'][name*='delete']");
                                        if ($(this).is(':checked')) {
                                            view.prop("checked", true);
                                        } else {
                                            if (create.is(':checked') || edit.is(':checked')
                                                    || deleteBox.is(':checked')) {
                                                view.prop("checked", true);
                                            } else
                                                view.prop("checked", false);
                                        }
                                    });

                    $(PrimeFaces.escapeClientId('form:tableId')).on(
                            "change",
                            "input[type='checkbox'][name*='view']",
                            function() {
                                var tr = $(this).parent().parent();
                                var view = tr.find("input[type='checkbox'][name*='view']");
                                var create = tr.find("input[type='checkbox'][name*='create']");
                                var edit = tr.find("input[type='checkbox'][name*='edit']");
                                var deleteBox = tr
                                        .find("input[type='checkbox'][name*='delete']");
                                if ($(this).is(':not(:checked)')) {
                                    create.prop("checked", false);
                                    edit.prop("checked", false);
                                    deleteBox.prop("checked", false);
                                }
                            });
                })


                </script>


</h:body>
</html>

此处有Bean代码

public class UserPojo {

    private String name;
    private Boolean view;
    private Boolean create;
    private Boolean edit;
    private Boolean delete;

    public Boolean getView() {
        return view;
    }

    public void setView(Boolean view) {
        this.view = view;
    }

    public Boolean getCreate() {
        return create;
    }

    public void setCreate(Boolean create) {
        this.create = create;
    }

    public Boolean getEdit() {
        return edit;
    }

    public void setEdit(Boolean edit) {
        this.edit = edit;
    }

    public Boolean getDelete() {
        return delete;
    }

    public void setDelete(Boolean delete) {
        this.delete = delete;
    }

    public UserPojo() {

    }

    public UserPojo(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

下面的最后代码

import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ViewScoped;


    @ManagedBean
    @ViewScoped
    public class MainBean implements Serializable{


        /**
         * 
         */
        private static final long serialVersionUID = -1245080637297904760L;
        private List<UserPojo> list;

        public MainBean() {
              fillList();
        }

        public List<UserPojo> getList() {
            return list;
        }

        public void setList(List<UserPojo> list) {
            this.list = list;
        }

        public void fillList() {
            list = new ArrayList<UserPojo>();
            list.add(new UserPojo("Jack"));
            list.add(new UserPojo("Jhon"));
            list.add(new UserPojo("Smack"));
            list.add(new UserPojo("Jimmy"));
            list.add(new UserPojo("Dummu"));
            list.add(new UserPojo("Stakr"));
            list.add(new UserPojo("Simi"));
        }

        public void confirmMethod()
        {
            System.out.println("Save values in DB****************");
            for(UserPojo ul : list)
            {
                System.out.println("insert statement");



            }
        }

    }

Please help me to solve my issue Thanks

推荐答案

如果我了解您想要实现的目标,那将非常简单...

If I understood what you want to achieve then it's pretty much simple...

第一个设置对话框ID

first set dialog ID

 <p:dialog id="assignPermissionDlgId" widgetVar="assignPermissionDlg" width="75%">

然后将您的按钮更改为此

then alter your button to this

<p:commandButton value="Assign Permission" update=":assignPermissionDlgId"
    oncomplete="assignPermissionDlg.show()"></p:commandButton>

我认为,每次打开对话框时,您都会看到先前选中的复选框,这样,在显示对话框之前,先对其进行更新,更新会导致重新渲染.

I think that each time you are opening the dialog you are seeing the previous checkboxes selected, in this way you update the dialog before you show it, the update cause the re-rendering.

但是我看不到您要将复选框的值保存在哪里! 注意:如果您在复选框中有值,答案将有所不同.....

But I can't see where you are saving the checkboxes values ! Note: If you have values in checkboxes the answer would be different.....

这篇关于重置&lt; p:selectBooleanCheckbox&gt;页面加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆