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
clouddev@surashriclouddev@surashri 

Getting blank fields values after 'onclick' - using actionsupport

Hi All,

I am not able to get values from pageblockdata table into actionsupport action function after clicking checkbox associated with it.
I have a table. After loading page, I am follwing listed steps. Also attaching screenshots and code too.

1 - Screen looks like below once loaded.
User-added image

2 - Using new email id I am popoulating 2nd row, other details like firstname, lastname from contact object are populated. The function searchContact() works fine
User-added image
3 - Then clicking substitute check box on the left of first row. This invokes chngeShowFlag() function. I am just using system.debug() statement in this function.
User-added image
I am not able to trace 2nd row value in function chngeShowFlag() No values for 2nd row are show in 
system.debug('trueBookingRecords- ' + trueBookingRecords);
        system.debug('EventBookingRecords first- ' + EventBookingRecords);
Visualforce Page
 
<apex:page standardController="Special_Event__c" extensions="BSCDelegateCaptureController" id="page">
    <apex:sectionHeader title="Delegate Capture Form" subtitle="{!BSCEvent.Product__r.Name}" />
    <apex:form id="form">
        <apex:pageBlock >
        <apex:pageMessages />

        <apex:pageBlockSection id="pbs">
            <apex:pageblocktable value="{!trueBookingRecords}" var="ebrecs" id="pbt">

                <apex:Column headerValue="Substitue">
        <!--apex:actionRegion id="ar1"-->
                    <apex:inputCheckbox value="{!ebrecs.isSubstitute}" rendered="{!ebrecs.isCheckBoxShow}">

                        <apex:actionsupport event="onclick" action="{!chngeShowFlag}" rerender="pbs" immediate="true">
                            <apex:param assignto="{!index}" name="param1" value="{!ebrecs.index}"/>
                            <apex:param assignto="{!serial}" name="param2" value="{!ebrecs.serial}"/>
                            <apex:param assignto="{!isSubstitute}" name="param3" value="{!ebrecs.isSubstitute}"/>
                        </apex:actionsupport>
                    </apex:inputCheckbox>
        <!--/apex:actionRegion-->
                </apex:Column>
                
                <apex:Column >
                    <apex:facet name="header">Booking Name</apex:facet>
                    <apex:outputText value="{!ebrecs.EventBooking.Name}" rendered="{!ebrecs.isShow}"/>
                </apex:Column>

                <apex:Column >
                    <apex:facet name="header">Booking Account</apex:facet>
                    <apex:outputText value="{!ebrecs.bookingAccount.Name}" rendered="{!ebrecs.isShow}"/>
                </apex:Column>

                <apex:Column id="em" >
                    <apex:facet name="header">Email</apex:facet>
                    <apex:actionRegion >
                    <apex:outputPanel rendered="{!(ebrecs.isEmail)}">
                        <apex:inputField value="{!ebrecs.bookingContact.email}" rendered="{!ebrecs.isShow}">
                            <apex:actionsupport event="onchange" action="{!searchContact}" reRender="em,fm,lm,ph,bd">
                                <apex:param assignto="{!index}" name="param1" value="{!ebrecs.index}"/>
                                <apex:param assignto="{!serial}" name="param2" value="{!ebrecs.serial}"/>
                            </apex:actionsupport>
                        </apex:inputField>    
                    </apex:outputPanel>
                    <apex:outputPanel rendered="{!NOT(ebrecs.isEmail)}">
                        <apex:outputField value="{!ebrecs.bookingContact.email}" rendered="{!ebrecs.isShow}"/>
                    </apex:outputPanel>
                    </apex:actionRegion>
                </apex:Column>

                <apex:Column id="fm">
                    <apex:facet name="header">First Name</apex:facet>
                    <apex:outputPanel rendered="{!NOT(ebrecs.isSubstitute)}">
                        <apex:inputField value="{!ebrecs.bookingContact.firstname}" rendered="{!ebrecs.isShow}"/>
                    </apex:outputPanel>
                    <apex:outputPanel rendered="{!ebrecs.isSubstitute}">
                        <apex:outputField value="{!ebrecs.bookingContact.firstname}" rendered="{!ebrecs.isShow}"/>
                    </apex:outputPanel>
                </apex:Column>

                <apex:Column id="lm">
                    <apex:facet name="header">Last Name</apex:facet>
                    <apex:actionRegion >
                    <apex:outputPanel rendered="{!NOT(ebrecs.isSubstitute)}">
                        <apex:inputField value="{!ebrecs.bookingContact.lastname}" rendered="{!ebrecs.isShow}"/>
                    </apex:outputPanel>
                    <apex:outputPanel rendered="{!ebrecs.isSubstitute}">
                        <apex:outputField value="{!ebrecs.bookingContact.lastname}" rendered="{!ebrecs.isShow}"/>
                    </apex:outputPanel>
                    </apex:actionRegion>
                </apex:Column>

                <apex:Column id="ph">
                    <apex:facet name="header">Phone Number</apex:facet>
                    <apex:outputPanel rendered="{!NOT(ebrecs.isSubstitute)}">
                        <apex:inputField value="{!ebrecs.bookingContact.phone}" rendered="{!ebrecs.isShow}"/>
                    </apex:outputPanel>
                    <apex:outputPanel rendered="{!ebrecs.isSubstitute}">
                        <apex:outputField value="{!ebrecs.bookingContact.phone}" rendered="{!ebrecs.isShow}"/>
                    </apex:outputPanel>
                </apex:Column>

                <apex:Column id="bd">
                    <apex:facet name="header">Date of Birth</apex:facet>
                    <apex:outputPanel rendered="{!NOT(ebrecs.isSubstitute)}">
                        <apex:inputField value="{!ebrecs.bookingContact.birthdate}" rendered="{!ebrecs.isShow}"/>
                    </apex:outputPanel>
                    <apex:outputPanel rendered="{!ebrecs.isSubstitute}">
                        <apex:outputField value="{!ebrecs.bookingContact.birthdate}" rendered="{!ebrecs.isShow}"/>
                    </apex:outputPanel>
                </apex:Column>

                <apex:Column >
                    <apex:facet name="header">Booking Status</apex:facet>
                    <apex:selectList id="status" value="{!ebrecs.bookingStatus}" size="1" rendered="{!ebrecs.isShow}" disabled="{!ebrecs.isSubstitute}">
                        <apex:selectOption itemValue="novalue" itemLabel=""/>
                        <apex:selectOption itemValue="attended" itemLabel="Attended"/>
                        <apex:selectOption itemValue="noshow" itemLabel="No Show"/>
                    </apex:selectList>
                </apex:Column>
                
            </apex:pageblocktable>
        </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Controller
 
public class BSCDelegateCaptureController
{
    public Special_Event__c BSCEvent {get; set;}
    public List<Special_Event_Booking__c> BSCEventBookings {get; set;}

    public List<EventBookingRecs> EventBookingRecords {get; set;}
    public List<EventBookingRecs> trueBookingRecords {get; set;}
    public integer index {get; set;}
    public integer serial {get; set;}
    public Boolean isSubstitute {get; set;}

    public Set<Id> accIds {get;set;}

    public Map<String, Contact> allContactMap {get;set;}
    
    public class EventBookingRecs
    {
        public integer index {get; set;}
        public integer serial {get; set;}
        public Boolean isSubstitute {get; set;}
        public Boolean isShow {get;set;}
        public Boolean isCheckBoxShow {get;set;}
        public Boolean isEmail {get;set;}
        public String bookingStatus {get; set;}

        public Special_Event_Booking__c EventBooking {get; set;}
        public Account bookingAccount {get;set;}
        public Contact bookingContact {get;set;}
    }

    public List<EventBookingRecs> gettrueBookingRecords()
    {
        system.debug('Hello');
        return null;
    }

    public BSCDelegateCaptureController(ApexPages.StandardController controller) 
    {
        BSCEvent = (Special_Event__c)controller.getRecord();
        system.debug('BSCEvent - ' + BSCEvent);
        BSCEvent = [SELECT Name, Product__r.name FROM Special_Event__c where id = :BSCEvent.id];
        BSCEventBookings = [SELECT Name, Company__c, Company__r.name, Company__r.isPersonAccount, Contact__r.firstname, Contact__r.lastname, Contact__r.email, Contact__r.phone, Contact__r.birthdate FROM Special_Event_Booking__c where special_event__c = :BSCEvent.id];

        system.debug('BSCEventBookings - ' + BSCEventBookings);

        EventBookingRecords = new List<EventBookingRecs> ();
        trueBookingRecords = new List<EventBookingRecs> ();
        accIds = new Set<Id> ();
        allContactMap = new Map<String, Contact> ();

        integer counter = 0;
        integer serialCounter = 0;
        for(Special_Event_Booking__c seb : BSCEventBookings)
        {
            system.debug('Special_Event_Booking__c seb - ' + seb);

            EventBookingRecs ebrEven = new EventBookingRecs();
            ebrEven.EventBooking = seb;
            ebrEven.bookingAccount = new Account(Name=seb.Company__r.name);
            ebrEven.bookingContact = new Contact(Email=seb.Contact__r.email, FirstName=seb.Contact__r.firstname, LastName=seb.Contact__r.lastname, phone=seb.Contact__r.phone, birthdate=seb.Contact__r.birthdate);
            if(ebrEven.bookingContact.email != null)
            {
                ebrEven.isCheckBoxShow = true;
                ebrEven.isEmail = false;
            }
            else
            {
                ebrEven.isCheckBoxShow = false;
                ebrEven.isEmail = true;
            }

            ebrEven.isShow = true;
            ebrEven.isSubstitute = false;
            ebrEven.serial = serialCounter++;
            ebrEven.index = counter++;
            system.debug('ebrEven - ' + ebrEven);
            EventBookingRecords.add(ebrEven);
            

            EventBookingRecs ebrOdd = new EventBookingRecs();
            ebrOdd.EventBooking = seb;
            ebrOdd.bookingAccount = new Account(Name=seb.Company__r.name);
            ebrOdd.bookingContact = new Contact();
            ebrOdd.isCheckBoxShow = false;
            ebrOdd.isEmail = true;
            ebrOdd.isShow = false;
            ebrOdd.isSubstitute = false;
            ebrOdd.serial = serialCounter++;
            ebrOdd.index = counter++;
            system.debug('ebrOdd - ' + ebrOdd);
            EventBookingRecords.add(ebrOdd);
            counter++;

            accIds.add(seb.Company__c);
        }

       
        List<Contact> allAccountContacts = [Select Id, FirstName, LastName, Email, Phone, Birthdate From Contact where account.id in :accIds]; 

        system.debug('List<Contact> allAccountContacts - ' + allAccountContacts);
        
        for(Contact c : allAccountContacts)
        {
            allContactMap.put(c.email, c);
        }

        system.debug('allContactMap - ' + allContactMap);

        system.debug('EventBookingRecords - ' + EventBookingRecords);
        system.debug('EventBookingRecords.size() - ' + EventBookingRecords.size());
        counter = 0;
        for(EventBookingRecs er : EventBookingRecords)
        {
            if(er.isShow == true)
            {
                er.index = counter++;
                trueBookingRecords.add(er);
            }
        }
    }

    public void searchContact()
    {
        system.debug('index - ' + index);
        system.debug('serial - ' + serial);
        system.debug('trueBookingRecords[index].bookingContact.email - ' + trueBookingRecords[index].bookingContact.email);
        trueBookingRecords[index].bookingContact = allContactMap.get(trueBookingRecords[index].bookingContact.email);
        EventBookingRecords[serial].bookingContact = allContactMap.get(trueBookingRecords[index].bookingContact.email);
        system.debug('trueBookingRecords[index] - ' + trueBookingRecords[index]);
        system.debug('EventBookingRecords[serial] - ' + EventBookingRecords[serial]);
    }

    public void chngeShowFlag()
    {
        system.debug('index - ' + index);
        system.debug('serial - ' + serial);

        system.debug('trueBookingRecords- ' + trueBookingRecords);
        system.debug('EventBookingRecords first- ' + EventBookingRecords);
    }
}

Could you please help me to find exact issue? It will help a lot. Please also find VF and Apex code for your ref.

Best Regards,

Rahul
Sagar PareekSagar Pareek
Hi Rahul ,

As per screen shots there is no check box in second row. In front of EB-0704699
clouddev@surashriclouddev@surashri
HI Sagar,

I am clicking checkbox from First Row, but should get values from 1st and 2nd row in chngeShowFlag() function.

Regards,

Rahul
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Rahul

 <apex:actionsupport event="onclick" action="{!chngeShowFlag}"rerender="pbs" immediate="true">

The problem if the immediate=True property is specified, the setter methods were not being called and just will be skipped. Try removing it!

Though the document wont say that, it what happening, the documentation just says "A Boolean value that specifies whether the action associated with this component should happen immediately, without processing any validation rules associated with the fields on the page. If set to true, the action happens immediately and validation rules are skipped. If not specified, this value defaults to false.", not only it skips the validations, it never sets the values that were entered.


To know when the action support methods completes just make use of status property so that the user can see and act accordingly.

Hope it helps.,

Thanks,
balaji
clouddev@surashriclouddev@surashri
Hi Balaji,

I have used immediate as LastName is reuqired and it is giving error after screen refresh as it has now value for row 3,4 & 5. Without using immediate flag also I am not getting values from row 2 in chngeShowFlag function.

Thanks,

Rahul
Sagar PareekSagar Pareek
Hi Rahul,

Yes as Balaji sugested exculding immediate=true  should work. Other wise you can use actionFunction/javaScript remoting.
clouddev@surashriclouddev@surashri
@Sagar,

I have tested with actionFunction too, it is not working...
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Rahul,

  You will hit that as you were using inputFields, now to escape that you have left with two different ways:

1) Use input text instead of inputfields
2) use script to fetch the values.

In case of required input fields, if actions with immediate=false will trigger the validation rule that field is required. 


Note: If you were worried about input field for dates, you still can use <apex:input type="date"> tag to have input fields, other way is to use input text just for last name and have your custom validation at the controller to  check if all the requried fields were set or not.

Thanks,
Balaji
clouddev@surashriclouddev@surashri
@Balaji,

option 2 -> script looks possible. Do you have any example so that I can use similar in my vf.

Thanks
Sagar PareekSagar Pareek
Hi Rahul,

This can be a good example for you 

http://www.salesforce.com/docs/developer/pages/Content/pages_js_remoting_example.htm
clouddev@surashriclouddev@surashri
@Balaji/@Sagar,

I found the way guys. I just used inputField option required="false" for lastname. I will check for Lastname values in apex. Removed immediate from actionsupport too.

It is working fine. 

Best Regards