0

My page is currently using a text box to update the BillingCountry field of an Account. How can I create a pop-up window with the same update functionality?

Controller

public class AccountEditController {

    accountwrapper1 makeEdit;
    List<accountwrapper1> listAccount = new List<accountwrapper1>();
    List<Account> selectableAccount = new List<Account>();
    List<Account> selectableAccount2 = new List<Account>();
    public Boolean showPopup { get; set; }

   public AccountEditController() {
          showPopup = False;
   }

    public List<accountwrapper1> getAccounts() {
            for(Account a: [SELECT Id, Name, BillingCountry, Phone FROM Account])
            listAccount.add(new accountwrapper1(a));
            return listAccount;            
    }

     public PageReference showToPopup() {
        showPopUp = True;
         selectableAccount.clear();
        for(accountwrapper1 accwrapper : listAccount)
        if(accwrapper.selected == True)
        selectableAccount.add(accwrapper.acc);
        system.debug(selectableAccount);
        return Null;
    }

    public string BillingCountry {
        get; 
        set;
    }


    public PageReference Savemeth() {
        for(account acc :selectableAccount ) {
                acc.BillingCountry = BillingCountry;
                  selectableAccount2.add(acc);
        }    
    update selectableAccount2;
    return Null;

    }

    public PageReference cancelmeth() {        
        return Null;
    }

    public PageReference closePopup() {
        showPopup = False;    
        return Null;
    }

    public PageReference GetSelectedAccounts()
    {
       if(selectableAccount.size()>0) {
        system.debug(selectableAccount.size());
        system.debug(selectableAccount);
       return Null;
        }
        else
        return Null;
    } 


     public class accountwrapper1
    {             
        public Account acc{get; set;}      
        public Boolean selected {get; set;}
        public accountwrapper1(Account a)
        {
            acc = a;
            selected = False;
        }
    }
}

Page

<apex:page controller="AccountEditController" applyHtmlTag="true">
    <style type="text/css">
    .PopupBackground{
        background-color:black;
        opacity: 0.20;
        filter: alpha(opacity = 20);
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        z-index: 9998;
    }
    .AccountEdit{
        background-color: white;
        border-width: 2px;
        border-style: solid;
        z-index: 9999;
        left: 50%;
        padding:10px;
        position: absolute;
        width: 500px;
        margin-left: -250px;
        top:100px;
    }
    </style>
        <apex:form >
            <apex:pageBlock Title="List of Accounts" >

                   <apex:pageBlockButtons >
                        <apex:commandButton value="Get selected Records" action="{!showToPopUp}" rerender="Output" id="button"/>
                   </apex:pageBlockButtons>

                 <!-- {!showPanel}---->
                      <apex:outputPanel id="Output" >
                           <apex:outputPanel rendered="{!showPopUp}">
                           <!---{!showPanel}---------->
                               <apex:outputLabel value="BillingCountry: "></apex:outputLabel>
                               <apex:inputText id="BillingCountry" value="{!BillingCountry}" size="40" style="height:13px;font-size:11px;"/>                   
                               <apex:commandButton value="save" action="{!Savemeth}"/>
                               <apex:commandButton value="cancel" action="{!cancelmeth}"/>
                               <apex:commandButton value="cancelPopUp" action="{!closePopUp}"/>
                            </apex:outputPanel>                   
                        </apex:outputPanel>  
                 <!--   <apex:commandButton value="cancelPopUp" action="{!closePopUp}"/>--->
                   <apex:pageBlockSection Title="List of Available Accounts" columns="1" collapsible="false">
                            <apex:pageblockTable value="{!accounts}" var="a" >

                                <apex:column headerValue="Select" width="60">
                                    <apex:inputCheckbox value="{!a.Selected}" id="checkedone" />
                                </apex:column>

                                <apex:column headervalue="Account Name" value="{!a.acc.Name}" width="200"/>
                                <apex:column headervalue="Phone" value="{!a.acc.Phone}" width="300"/>
                                <apex:column headervalue="Billing Country" value="{!a.acc.BillingCountry}" width="300"/>

                            </apex:pageblocktable>
                   </apex:pageBlockSection>

            </apex:pageblock>
        </apex:form>
</apex:page>
  • so , what exactly is the issue here? what is not working and where? Perhaps a screen shot of what UI behavior you are getting would be useful – cropredy Oct 3 '16 at 16:45
  • @cropredy Here the model popup is not working it's working like a ordinary button action when clicking the "Get selected Records" the textbox and the save and another 2 buttons are showed (But it's not in show by model popup)it's my problem.I want the text box and the buttons showed by the inside the modelpopup. – MohanRaj Oct 4 '16 at 5:00
  • Please use edit and post an annotated screen shot – cropredy Oct 4 '16 at 14:05
0

Friends I got the answer of my question: The Controller:

public class AccountEditController {

    public String closePopup { get; set; }

    accountwrapper1 makeEdit;
    List<accountwrapper1> listAccount = new List<accountwrapper1>();
    List<Account> selectableAccount = new List<Account>();
    //set<Account> selectableAccount2 = new set<Account>();
    //public Boolean showPanel {get; set;}
    public Boolean showPopup { get; set; }

   public AccountEditController() {
          showPopup = False;
         //showPanel = False;
   }

    public List<accountwrapper1> getAccounts() {
        if(listAccount == Null){
            for(Account a: [SELECT Id, Name, BillingCountry, Phone FROM Account])
            listAccount.add(new accountwrapper1(a));
            return listAccount; }
        else{
            listAccount.clear();
            for(Account a: [SELECT Id, Name, BillingCountry, Phone FROM Account])
            listAccount.add(new accountwrapper1(a));
            return listAccount;            
            }           
    }

     public PageReference showToPopup() {
   // public PageReference showToPanel() {
        showPopUp = True;
        //showPanel  = True;
         selectableAccount.clear();
        for(accountwrapper1 accwrapper : listAccount)
        if(accwrapper.selected == True)
        selectableAccount.add(accwrapper.acc);
        system.debug(selectableAccount);
        return Null;              
    }

    public string BillingCountry {
        get; 
        set;
    }


    /*public PageReference Savemeth() {
        for(account acc :selectableAccount ) {
                acc.BillingCountry = BillingCountry;
                selectableAccount2.add(acc);

        }    
    update selectableAccount2;
    showPopup = False;
    return Null;

    }*/

    public PageReference Savemeth() 
    {
        map<Id, Account> mapAccountForUpdate = new map<Id, Account>();
        for(account acc :selectableAccount ) 
        {
            acc.BillingCountry = BillingCountry;
            mapAccountForUpdate.put(acc.Id, acc);
        }    
        update mapAccountForUpdate.values();
        showPopup = Null;
        BillingCountry = '';
        //showPopup = False;
        return Null;
    }

    public PageReference cancelmeth() {        
        return Null;
    }

    public PageReference closePopup() {
        showPopup = Null;
        BillingCountry = '';
        //showPopup = False;   
        return Null;
    }

    public PageReference GetSelectedAccounts()
    {
       if(selectableAccount.size()>0) {
        system.debug(selectableAccount.size());
        system.debug(selectableAccount);
        showPopup = Null;
        return Null;
        }
        else
        showPopup = Null;
        return Null;
    } 


     public class accountwrapper1
    {             
        public Account acc{get; set;}      
        public Boolean selected {get; set;}
        public accountwrapper1(Account a)
        {
            acc = a;
            selected = False;
        }
    }
}

My Page:

<apex:page controller="AccountEditController" applyHtmlTag="true">
    <style type="text/css">
    .PopupBackground{
        background-color: white;
        opacity: 0.8;
        filter: alpha(opacity = 20);
        position: absolute;
        width: 100%;
        height: 200%;
        top: -100px;
        left: 10px;
        z-index: 9998;
    }
    .AccountEdit{
        background-color: white;
        border-width: 8px;
        border-style: solid;
        z-index: 9999;
        left: 30%;
        padding:10px;
        position: absolute;
        width: 350px;
        margin-left: 75px;
        top:300px;
    }
    </style>
        <apex:form >
            <apex:pageBlock Title="List of Accounts" >

                   <apex:pageBlockButtons location="top">
                        <apex:commandButton value="Get selected Records" action="{!showToPopup}" rerender="Output" id="button"/>
                        <apex:commandButton value="cancelPopup" action="{!closePopup}" rendered="output"/>
                      <!-- <apex:commandButton value="Get selected Records" action="{!showToPanel}" rerender="Output" id="button"/>---->

                   </apex:pageBlockButtons>

                 <!-- {!showPanel}---->
                      <apex:outputPanel id="Output">
                          <apex:outputPanel styleClass="PopupBackground" layout="black" rendered="{!showPopup}">
                              <apex:outputPanel styleClass="AccountEdit" layout="black" rendered="{!showPopup}">
                         <!---  <apex:outputPanel rendered="{!showPanel}">----->
                           <!---{!showPanel}---------->
                               <apex:outputLabel value="BillingCountry: "></apex:outputLabel>
                               <apex:inputText id="BillingCountry" value="{!BillingCountry}" size="40" style="height:13px;font-size:11px;"/><br />                   
                               <center><apex:commandButton value="save" action="{!Savemeth}" reRender="Initialtable,Output"/>
                              <!-- <apex:commandButton value="cancel" action="{!cancelmeth}"/>---->
                               <apex:commandButton value="cancelPopup" action="{!closePopup}"/></center>
                                </apex:outputPanel>
                            </apex:outputPanel>                   
                        </apex:outputPanel>  
                 <!--   <apex:commandButton value="cancelPopup" action="{!closePopup}"/>--->
                   <apex:pageBlockSection Title="List of Available Accounts" columns="1" collapsible="true">
                            <apex:pageblockTable value="{!accounts}" var="a" id="Initialtable">

                                <apex:column headerValue="Select" width="60">
                                    <apex:inputCheckbox value="{!a.Selected}" id="checkedone" />
                                </apex:column>

                                <apex:column headervalue="Account Name" value="{!a.acc.Name}" width="200"/>
                                <apex:column headervalue="Phone" value="{!a.acc.Phone}" width="300"/>
                                <apex:column headervalue="Billing Country" value="{!a.acc.BillingCountry}" width="300"/>

                            </apex:pageblocktable>
                   </apex:pageBlockSection>

            </apex:pageblock>
        </apex:form>
</apex:page>

Thank you By Mohan.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.