选中多个复选框进行编辑后显示错误消息

时间:2015-10-28 06:02:43

标签: jsf

选中多个复选框后,我显示错误消息。当我选择多个复选框时,我点击编辑按钮,我得到弹出窗口。而不是弹出窗口我需要显示错误消息。

这是我的jsf页面

<!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:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">

<h:head>
</h:head>
<h:body>
    <h:form id="myForm">
        <div id="page" class="box">
            <div class="msg">
                <h2>View Outbound Home Page</h2>
                <hr />
                <p:dialog header="Set Status:" widgetVar="assign" modal="true">
                    <h:panelGrid columns="2" style="width:400px; height:50px">
                        <p:outputLabel value="Status" />
                        <h:selectOneMenu id="status" value="#{leadEditBean.status}">
                            <f:selectItem itemLabel="--Select one Value--" />
                            <f:selectItems value="#{leadEditBean.typeOfStatus}" />
                        </h:selectOneMenu>
                    </h:panelGrid>
                    <h:commandButton value="Update"
                        actionListener="#{leadEditBean.changeStatus()}" />
                </p:dialog>


                <p:dialog header="Set Reminder Date and Time" widgetVar="setTime"
                    id="dialog1" resizable="true">
                    <h:panelGrid columns="2" cellpadding="10" cellspacing="10">
                        <h:outputText value="set remind time"></h:outputText>
                        <p:calendar showOn="button" pattern="yyyy-MM-dd hh:mm:ss"
                            value="#{leadEditBean.date}"></p:calendar>
                        <h:commandButton value="Set"
                            action="#{leadEditBean.setRemainderCall()}"></h:commandButton>
                    </h:panelGrid>
                </p:dialog>
            </div>
            <p:messages for="outbondhome" style="text-align:center"
                closable="true"></p:messages>
            <div class="callbutton">
                <h:panelGrid columns="4">

                    <p:commandButton id="statusbtn" value="Change Status"
                        class="button" onclick="PF('assign').show();" ajax="true"
                        update=":myForm:tbl" disabled="#{leadEditBean.disabled}" />

                    <p:commandButton id="settime" value="Set Remind Time"
                        class="button" onclick="PF('setTime').show();" ajax="true"
                        update=":myForm:tbl" disabled="#{leadEditBean.disabled}"></p:commandButton>
                    <h:commandButton value="Yesterday Calls"
                        action="#{leadEditBean.yesterdayCall}" class="button"
                        immediate="true" />

                    <h:commandButton value="Remainder Calls"
                        action="#{leadEditBean.reminderCallsByTime()}" class="button"
                        immediate="true" />

                </h:panelGrid>
            </div>
            <br></br> <br></br>
            <p:dataTable id="tbl" var="lead" value="#{leadEditBean.enquiryTOs}"
                widgetVar="filteredlead" rowsPerPageTemplate="25,50,75,100,10000"
                filteredValue="#{leadEditBean.filterednewLeadList}"
                paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                rows="25" paginator="true" rowKey="#{lead.leadId}"
                rowIndexVar="rowIndex" selection="#{leadEditBean.leadrTos}"
                style="width:100%;">
                <f:facet name="header">
                    <p:outputPanel>
                        <h:outputText value="Search " style="margin-left:840px;" />
                        <p:inputText id="globalFilter"
                            onkeyup="PF('filteredlead').filter()" style="width:150px"
                            placeholder="Enter Phone Number" maxlength="10" />
                    </p:outputPanel>
                </f:facet>
                <p:ajax event="rowSelectCheckbox"
                    listener="#{leadEditBean.onRowSelect}"
                    update=":myForm:settime :myForm:statusbtn " />
                <p:ajax event="rowUnselectCheckbox"
                    listener="#{leadEditBean.onRowUnselect}"
                    update=":myForm:settime :myForm:statusbtn " />

                <p:column headerText="" style="width:30px;" selectionMode="multiple">

                </p:column>
                <p:column headerText="Lead Id" style="width:120px;">
                    <h:outputText value="#{lead.leadId}" />
                </p:column>
                <p:column headerText="Lead Name">
                    <h:outputText value="#{lead.firstName}" />
                </p:column>
                <p:column headerText="Email">
                    <h:outputText value="#{lead.emailId}" />
                </p:column>
                <p:column headerText="Phone No" filterMatchMode="contains"
                    filterBy="#{lead.phoneNum}">
                    <h:outputText value="#{lead.phoneNum}" />
                </p:column>

                <p:column headerText="PinCode">
                    <h:outputText value="#{lead.area.pincode}" />
                </p:column>

                <p:column rendered="#{leadEditBean.hideColumn}">
                    <f:facet name="header">
                        <h:outputText value="Remainder Date" />
                    </f:facet>
                            #{lead.time}
                        </p:column>

                <p:column headerText="Edit" style="width:40px;">
                    <p:commandButton icon="ui-icon ui-icon-pencil"
                        actionListener="#{leadEditBean.getLeadEnquiryEntityForEdit(lead)}"
                        oncomplete="PF('edit').show()" ajax="true"
                        update=":myForm:dialog2" />
                </p:column>
            </p:dataTable>
        </div>

        <p:dialog header="Update Lead" widgetVar="edit" id="dialog2"
            resizable="true" modal="true">
            <p:messages for="home"></p:messages>
            <h:panelGrid columns="4" cellpadding="10" cellspacing="4">
                <h:outputText value="LeadId" />
                <h:outputText value="#{leadEditBean.leadList.leadId}" />

                <h:outputText />
                <h:outputText />

                <h:outputText value="First Name" />
                <h:inputText class="input"
                    value="#{leadEditBean.leadList.firstName}"></h:inputText>

                <h:outputText value="Email" />
                <h:inputText class="input" value="#{leadEditBean.leadList.emailId}"></h:inputText>

                <h:outputText value="Mobile number" />
                <h:inputText class="input" value="#{leadEditBean.leadList.phoneNum}"></h:inputText>

                <h:outputText value="Pincode" />
                <h:selectOneMenu class="input" value="#{leadEditBean.pincode}">
                    <f:selectItem itemValue="#{leadEditBean.pincode}" />
                    <f:selectItems value="#{applicationController.typeOfPincode}"></f:selectItems>
                </h:selectOneMenu>
            </h:panelGrid>

            <h:panelGrid>
                <p:commandButton id="enquiry" value="Send to Enquiry"
                    update=":myForm:tbl" onclick="PF('send').show();"
                    style="margin-left:250px" ajax="true"></p:commandButton>
            </h:panelGrid>

                <h:commandButton value="Update" ajax="true" update=":myForm:dialog" style="margin-left:265px"
                    actionListener="#{leadEditBean.updateLeadEnquiryEntity}" />
                <h:commandButton value="Cancel" action="#{leadEditBean.cancel}" />
        </p:dialog>

        <div id="footer">
            <p>copy right</p>
        </div>
    </h:form>
</h:body>

</html>

这是我的豆子

 package com.model.acim.common.controller;

@Component
@ManagedBean
@RequestScoped
public class LeadEditBean extends BaseBean<T> {

    @Autowired
    @Qualifier("baseServiceImpl")
    private BaseService<T> baseService;

    private int leadID;
    private String firstName;
    private String lastName;
    private String phoneNumber;
    private String emailId;
    private String address;
    private String area;
    private String city;
    private String pincode;
    private List<LeadEnquiryTO> enquiryTOs;
    private AreaTO areaTO = new AreaTO();
    private StateTO stateTO;
    private CityTO cityTO;
    private LeadEnquiryTO enquiryTO = new LeadEnquiryTO();
    private LeadEnquiryTO leadList=new LeadEnquiryTO();
    private LeadEnquiryTO LeadEnquiryTOUpdate=new LeadEnquiryTO();
    private List<LeadEnquiryTO> newLeadList;
    private List<LeadEnquiryTO> filterednewLeadList;
    private List<LeadEnquiryTO> leadrTos;
    List<LeadEnquiryTO> allLeads;
    private Timestamp setTime;
    private String branch;
    private Date date;
    private String status;
    private List<LeadEnquiryTO> leadEnquiryToListAd = null;
    HttpSession session = null; 
        int noOfSelctions=0;
    private Boolean disabled = true;
    private Boolean hideColumn = false;
    private List<LeadEnquiryTO> leadEnquiryToList = null;
    int emp_id;

    int selectionForEdit=0;
    public int getNoOfSelctions() {
        return noOfSelctions;
    }

    public void setNoOfSelctions(int noOfSelctions) {
        this.noOfSelctions = noOfSelctions;
    }

    public List<LeadEnquiryTO> getLeadEnquiryToList() {
        return leadEnquiryToList;
    }

    public void setLeadEnquiryToList(List<LeadEnquiryTO> leadEnquiryToList) {
        this.leadEnquiryToList = leadEnquiryToList;
    }

    public void getLeadEnquiryEntityForEdit(LeadEnquiryTO to){
        int size = leadrTos.size();
        if(size<=1){
            this.setLeadID(to.getLeadId());
            leadList = baseService.getLeadEnquiryEntityForEdit(to.getLeadId());
            this.setLeadID(leadList.getLeadId());
            this.setFirstName(leadList.getFirstName());
            this.setLastName(leadList.getLastName());
            this.setPhoneNumber(leadList.getPhoneNum());
            this.setEmailId(leadList.getEmailId());
            this.setAddress(leadList.getAddress());
            String areaName = leadList.getArea().getAreaName();
            this.setArea(areaName);
            this.setPincode(leadList.getArea().getPincode());
            this.setCity(leadList.getArea().getCity().getCityName());
        }
        else
        {
            FacesContext.getCurrentInstance().addMessage(
                    "home",
                    new FacesMessage("Please select only One Value or One Row"));
        }
    }

    public void onRowSelect(SelectEvent event)
    {
        noOfSelctions = noOfSelctions+1;
        @SuppressWarnings("unused")
        LeadEnquiryTO sp = (LeadEnquiryTO) event.getObject();
        disabled=false;
    }
    public void onRowUnselect(UnselectEvent event) 
    {
        noOfSelctions=noOfSelctions-1;
        @SuppressWarnings("unused")
        LeadEnquiryTO sp = (LeadEnquiryTO) event.getObject();
        if (noOfSelctions<=0) {
            disabled=true;
        } else {
            disabled=false;
        }

    }
    public void updateLeadEnquiryEntity(){
        LeadEnquiryTOUpdate.setLeadId(leadList.getLeadId());
        LeadEnquiryTOUpdate.setFirstName(leadList.getFirstName());
        LeadEnquiryTOUpdate.setLastName(leadList.getLastName());
        LeadEnquiryTOUpdate.setPhoneNum(leadList.getPhoneNum());
        LeadEnquiryTOUpdate.setAddress(leadList.getAddress());
        LeadEnquiryTOUpdate.setEmailId(leadList.getEmailId());
        areaTO= getAreaTOByid();
        LeadEnquiryTOUpdate.setArea(areaTO);

        int result =    baseService.updateLeadEnquiryEntity(LeadEnquiryTOUpdate);
        if (result>0) {
            FacesContext.getCurrentInstance().addMessage(
                    "leadhome",
                    new FacesMessage("Updated Successfully"));

        } else {
            FacesContext.getCurrentInstance().addMessage(
                    "leadhome",
                    new FacesMessage("Not Updated Successfully"));
        }

        enquiryTOs = baseService.getLeadEnquiryByEmployeeId(emp_id);
    }

    public void getLeadEnquiryByEmployeeId(){
        session = (HttpSession) FacesContext
                .getCurrentInstance().getExternalContext()
                .getSession(false);
         emp_id = (Integer) session.getAttribute("employeeId");
        enquiryTOs = baseService.getLeadEnquiryByEmployeeId(emp_id);
    }
    //setters getter
  }

1 个答案:

答案 0 :(得分:2)

您应该考虑将复选框更改为单选按钮。原则上,这是单一选择[Checkbox or radio button]的正确比喻。

<p:column ... selectionMode="single">