在页面加载时重置<selectbooleancheckbox> </selectbooleancheckbox>

时间:2014-01-16 08:29:34

标签: javascript jquery jsf primefaces

如何重置页面加载?使用CommandButton的

请在此处以Javascript或Ajax

发布示例

请帮助我解决这个问题

<?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" />
    <title>Test</title>
</h:head>
<h:body>
<h:form>
<p:commandButton value="Assign Permission" onclick="moduleDialog.show()"></p:commandButton>
</h:form>

<p:dialog widgetVar="moduleDialog" id="dlg">
<p:panel>
    <h:form id="form">
    <p:dataTable value="#{roleModule.modulesList}" var="modules" id="table">
        <p:column headerText="Module ID:">
            <h:outputText value="#{modules.moduleID}" />
        </p:column>
        <p:column headerText="Root Module ID:">
            <h:outputText value="#{modules.rootID}" />
        </p:column>
        <p:column headerText="Module Description:">
            <h:outputText value="#{modules.moduleDescription}" />
        </p:column>
        <p:column headerText="View">
            <h:selectBooleanCheckbox id="view" value="#{modules.view}">
                <p:ajax update=":form:table" listener="#{roleModule.permissionCheck}" />
            </h:selectBooleanCheckbox>
        </p:column>
        <p:column headerText="Create">
            <h:selectBooleanCheckbox id="create" value="#{modules.create}">
                <p:ajax update=":form:table" listener="#{roleModule.permissionCheck}" />
            </h:selectBooleanCheckbox>

        </p:column>
        <p:column headerText="Edit">
            <h:selectBooleanCheckbox  id="edit" value="#{modules.edit}">
                <p:ajax update=":form:table" listener="#{roleModule.permissionCheck}" />
            </h:selectBooleanCheckbox>
        </p:column>
        <p:column headerText="Delete">
            <h:selectBooleanCheckbox id="delete" value="#{modules.delete}">
                <p:ajax update=":form:table" listener="#{roleModule.permissionCheck}" />
            </h:selectBooleanCheckbox>
        </p:column>

        </p:dataTable>
        <p:toolbar>
        <p:toolbarGroup>
        <p:commandButton onchange="" value="Submit"  action="#{roleModule.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>  
    </h:form>
    </p:panel>
    </p:dialog>

</h:body>
</html>

bean代码

 import java.io.Serializable;


    public class Module implements Serializable {
        private static final long   serialVersionUID    = 176253618089501709L;
        private String moduleID,rootID,moduleDescription;
        private boolean view,edit,delete,create;

        public String getModuleID() {
            return moduleID;
        }

        public void setModuleID(String moduleID) {
            this.moduleID = moduleID;
        }

        public String getRootID() {
            return rootID;
        }

        public void setRootID(String rootID) {
            this.rootID = rootID;
        }

        public String getModuleDescription() {
            return moduleDescription;
        }

        public void setModuleDescription(String moduleDescription) {
            this.moduleDescription = moduleDescription;
        }

        public boolean isView() {
            return view;
        }

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

        public boolean isEdit() {
            return edit;
        }

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

        public boolean isDelete() {
            return delete;
        }

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

        public boolean isCreate() {
            return create;
        }

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

        @Override
        public String toString() {
            return "Module [moduleID=" + moduleID + ", rootID=" + rootID + ", moduleDescription=" + moduleDescription + ", view=" + view + ", edit=" + edit + ", delete=" + delete + ", create=" + create + "]";
        }

    }

最终代码

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.event.AjaxBehaviorEvent;
@ManagedBean
@ViewScoped
public class RoleModule implements Serializable{

    private static final long   serialVersionUID    = 1L;

    private List<Module> modulesList;

    @PostConstruct
    public void init() {
        modulesList = new ArrayList<Module>();

        Module m1 = new Module();
        m1.setModuleID("1");
        m1.setRootID("root");
        m1.setModuleDescription("desc1");
        modulesList.add(m1);

        Module m2 = new Module();
        m2.setModuleID("2");
        m2.setRootID("root");
        m2.setModuleDescription("desc2");
        modulesList.add(m2);
    }

    public void permissionCheck(AjaxBehaviorEvent event){
        Boolean value = (Boolean) ((UIInput) event.getComponent()).getValue();

        UIInput component = ((UIInput) event.getComponent());

        FacesContext context = FacesContext.getCurrentInstance();
        Module module = context.getApplication().evaluateExpressionGet(context, "#{module}", Module.class);

        System.out.println(module+","+value+","+component.getId());

        switch(component.getId()){
            case "create":
            case "delete":          
            case "edit":
                if (value){
                    module.setView(true);
                }
                break;
            case "view":
                if (!value){
                    module.setCreate(false);
                    module.setDelete(false);
                    module.setEdit(false);
                }
        }
    }

    public List<Module> getModulesList() {
        return modulesList;
    }

    public void setModulesList(List<Module> modulesList) {
        this.modulesList = modulesList;
    }

}

请帮我解决我的问题

0 个答案:

没有答案