function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
akarwaakarwa 

CheckBox not working with Action Support

Hi,

 

 

I am trying to display a message when checbox in my Visual force page is checked. I am using action support for my check box component. The re rendering part the section is working, but the set property of the checkbox  is not getting invoked i.e. I am not able to capture the checkbox value if its checked or unchecked.

 

Below is my source code. Thanks in advance

 

Controller

 

public Boolean specialInvest{

      get{

            if(specialInvest == null){

                  specialInvest = true;

            }

                       

            return specialInvest;  

      }

      set;

    }

 

 

Visual Force page

 

<apex:page standardController="Case" extensions="RMAEditPageController" action="{!pageLoad}">     
<script>


    var windowRef;
    var intervalId = 0;
    var globalObj;
    function openLookUpWindow(obj){
        //alert(obj);  
        var ele = document.getElementById(obj);
        var accId = document.getElementById("j_id0:rmaForm:block:RMASection:AccountNameItem:AccountName_lkid").value;
        //alert(accId);
        checkToOpenWindow(accId)
        //setTimeout(checkToOpenWindow, 2*1000);
    }
   
    function checkToOpenWindow(accountId){
        windowRef = window.open('/apex/lookUp?id='+accountId,'','width=500, height=300, scrollbars=yes, resizable=yes, menubar=no, status=no,toolbar=no');
        //checkWindowStatus();
    }
               
              
</script>
  <apex:form id="rmaForm" >
        <apex:pageMessages />
        <apex:pageBlock mode="edit" id="block" rendered="true" >
                <apex:pageBlockButtons location="both">
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!saveAdd}" value="Save & Add or Mass Upload RMA Item"/>
                <apex:commandButton action="{!cancel}" value="Cancel"/>
        </apex:pageBlockButtons>
           
            <apex:pageBlockSection id="RMASection" title="RMA" columns="2" >
                <apex:pageBlockSectionItem id="AccountNameItem">
                    <apex:outputLabel for="AccountName">Account Name</apex:outputLabel>
                    <apex:panelGroup >
                        <apex:inputField required="true" id="AccountName" value="{!Case.AccountID}" />
                    </apex:panelGroup>
                </apex:pageBlockSectionItem>
               
                <apex:pageBlockSectionItem id="ReturnTypeItem">
                    <apex:outputLabel for="ReturnType">Return Type</apex:outputLabel>
                    <apex:panelGroup >
                        <apex:inputField required="true" id="ReturnType" value="{!Case.Return_Type__c}"/>
                    </apex:panelGroup>
                </apex:pageBlockSectionItem>

                <apex:pageBlockSectionItem id="ShipToItem">
                    <apex:outputLabel for="ShipTo">Ship To</apex:outputLabel>
                    <apex:panelGroup >
                        <apex:inputText value="{!shipToNum}" id="ShipTo" onclick="javascript&colon;openLookUpWindow('{!$Component.RMASection}');" >
                        </apex:inputText>
                        <apex:commandButton reRender="ShipTo" action="{!lookUp}"  image="{!$Resource.lookupIcon}"  onclick="javascript&colon;openLookUpWindow('{!$Component.RMASection}');"/>
                    </apex:panelGroup>
                </apex:pageBlockSectionItem>
               
                <apex:pageBlockSectionItem id="InvoiceToItem">
                    <apex:outputLabel for="InvoiceTo">Invoice To</apex:outputLabel>
                    <apex:panelGroup >
                        <apex:inputField id="InvoiceTo"  value="{!Case.Invoice_To1__c}"/>
                    </apex:panelGroup>
                </apex:pageBlockSectionItem>
                               
                <apex:pageBlockSectionItem id="CustomerPOItem">
                    <apex:outputLabel for="CustomerPO">Customer PO</apex:outputLabel>
                    <apex:panelGroup >
                        <apex:inputField id="CustomerPO"  value="{!Case.Customer_PO__c}"/>
                    </apex:panelGroup>
                </apex:pageBlockSectionItem>
               
                <apex:pageBlockSectionItem id="ContactNameItem">
                    <apex:outputLabel for="ContactName">Contact</apex:outputLabel>
                    <apex:panelGroup >
                        <apex:inputField id="ContactName"  value="{!Case.ContactID}"/>
                    </apex:panelGroup>
                </apex:pageBlockSectionItem>
               
                 <apex:pageBlockSectionItem id="DescriptionItem">
                    <apex:outputLabel for="Description">Description</apex:outputLabel>
                    <apex:panelGroup >
                        <apex:inputField id="Description"   value="{!Case.Description}"/>
                    </apex:panelGroup>
                </apex:pageBlockSectionItem>
               
                <apex:pageBlockSectionItem id="SpecialInvestigationItem">
                    <apex:outputLabel for="SpecialInvestigation">Special Investigation</apex:outputLabel>
                    <apex:panelGroup >
                        <apex:inputCheckbox id="SpecialInvestigation"   value="{!specialInvest}">
                            <apex:actionSupport event="onclick" reRender="note"/>
                        </apex:inputCheckBox>
                    </apex:panelGroup>
                </apex:pageBlockSectionItem>

               
                 <apex:pageBlockSectionItem id="StatusItem">
                    <apex:outputLabel for="Status">Status</apex:outputLabel>
                    <apex:panelGroup >
                        <apex:outputField id="Status"  value="{!Case.Status}" />
                    </apex:panelGroup>
                </apex:pageBlockSectionItem>

                </apex:pageBlockSection>
           
                           
                <apex:pageBlockSection title="Order Numbers" columns="2" id="OrderNumberSection">
                <apex:pageBlockSectionItem id="OrderNumberItem">
                    <apex:outputLabel for="OrderNumber">Order Number</apex:outputLabel>
                    <apex:panelGroup >
                        <apex:inputField id="OrderNumber"  value="{!Case.Original_Order_Number__c}"/>
                    </apex:panelGroup>
                </apex:pageBlockSectionItem>

                 <apex:pageBlockSectionItem id="OrderLineNumberItem">
                    <apex:outputLabel for="OrderLineNumber">Order Line Number</apex:outputLabel>
                    <apex:panelGroup >
                        <apex:inputField id="OrderLineNumber"  value="{!Case.Original_Order_Line_Number__c}"/>
                    </apex:panelGroup>
                </apex:pageBlockSectionItem>
              </apex:pageBlockSection>
              </apex:pageBlock>
              <apex:pageBlock id="note">
                  <apex:pageMessages id="msg" rendered="{!specialInvest}"></apex:pageMessages>
              </apex:pageBlock>
          </apex:form>   
</apex:page>

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Duncan_IdahoDuncan_Idaho

I threw something together to see if I could get it to work:

 

Controller:

 

public with sharing class testController {
	
	public boolean testBool {get; set;}
	
	public testController()
	{
		testBool = false;
	}

}

 Page:

<apex:page controller="testController">
<apex:form id="testForm">
Check the box to show the message.
<apex:inputcheckbox value="{!testBool}">
<apex:actionSupport event="onclick" reRender="messageBox"/>
</apex:inputcheckbox>

<apex:outputpanel id="messageBox">
<apex:outputtext rendered="{!testBool}">Uncheck the box to hide the message.</apex:outputtext>
</apex:outputpanel>
</apex:form>
</apex:page>

 Seems to work. You can try the demo here: http://hartye-developer-edition.na8.force.com/testpage

 

 

All Answers

Duncan_IdahoDuncan_Idaho

the apex:pagemessages tag is used to display salesforce error messages or custom error messages set in the controller. Are you sure there is a message to display?

 

If you do know there is a message to display, I would test the page with "msg" set to rendered="true" and see if it works. I'm not sure how the apex:pagemessages tab behaves when it's rerendered with ajax.

akarwaakarwa

Hi Duncan

 

Thanks for the prompt reply

 

You are right. It was just for testing pupose. But my problem is that setter method is not geeting invoked by action support when checkbox ( specialInvest ) is checked because of which I am not able to capture the checkbox value and render the pageblock (id = "note") based on check box value. 

Duncan_IdahoDuncan_Idaho

I threw something together to see if I could get it to work:

 

Controller:

 

public with sharing class testController {
	
	public boolean testBool {get; set;}
	
	public testController()
	{
		testBool = false;
	}

}

 Page:

<apex:page controller="testController">
<apex:form id="testForm">
Check the box to show the message.
<apex:inputcheckbox value="{!testBool}">
<apex:actionSupport event="onclick" reRender="messageBox"/>
</apex:inputcheckbox>

<apex:outputpanel id="messageBox">
<apex:outputtext rendered="{!testBool}">Uncheck the box to hide the message.</apex:outputtext>
</apex:outputpanel>
</apex:form>
</apex:page>

 Seems to work. You can try the demo here: http://hartye-developer-edition.na8.force.com/testpage

 

 

This was selected as the best answer
akarwaakarwa

Thanks a lot Duncan for your help

 

Actually the issue with my page was the required fields were not filled up, so the AJAX call was not invoking the set property of the checkbox.

 

Its working now

 

Thanks again :smileyhappy:

community Name.ax928community Name.ax928

Could you pls let me konw how you solved the issue.