+ Start a Discussion
sravusravu 

Help Needed!!!!!!!!!!! <apex:param> not working with the <apex:inputcheckbox>

Hi,

 

I am trying to get the list of  records from a custom object. I am having a input checkbox in the last column of the datatable. When anyone selects the checkbox, I am using a actionsupport component to send the Id of that record to the controller and perform. The id value is not passed to the controller. I am getting an error, Attempt to de-reference a null object.

 

The requirement is I have to display the sessions based on the dates. Users can register to the sessions by selecting the check boxes and click on register button. When they click register, he must be registered for all the selected sessions. 

 

Could anyone help me with this issue

 

Here is my Visualforce Page

 

 

<apex:page controller="sessionRegisterController">
<apex:form >
<apex:outputPanel >
<apex:selectRadio value="{!sessionDate}">
<apex:selectOptions value="{!SessionDates}" >
</apex:selectOptions>
<apex:actionSupport action="{!refreshsessionList}" event="onchange"/>
</apex:selectRadio>
</apex:outPutPanel>
<apex:outputPanel >
<apex:dataTable value="{!Sessions}" var="s">
<apex:column headerValue="Session Name" value="{!s.Session_Name__c}"/>
<apex:column headerValue="Presenters" value="{!s.Session_Name__c}"/>
<apex:column headerValue="Time" value="{!s.Session_Name__c}"/>
<apex:column headerValue="Location" value="{!s.Session_Name__c}"/>
<apex:column headerValue="Register">
<apex:inputCheckbox value="{!sessionChecked}">
<apex:inputHidden value="{!s.Id}"/>
<apex:actionSupport event="onclick" action="{!selectedSessions}">
<apex:param name="sessionId" value="{!s.Id}" assignTo="{!sessionId}"/>
</apex:actionSupport>
</apex:inputCheckbox>
</apex:column>
</apex:dataTable>
<apex:commandButton value="Register" action="{!Registration}"/>
</apex:outputPanel>
</apex:form>
</apex:page>

 

 

Here is my Controller

 

public with sharing class sessionRegisterController{

public String sessionDate{get;set;}
public Apexpages.StandardSetController con {get;set;}
public Boolean sessionChecked {get;set;}
public Id sessionId {get;set;}
public List<Id> selectedList {get;set;}

public sessionRegisterController(){
Sessions__c defaultDate = [select Id, Session_Date__c from Sessions__c order by Session_Date__c asc limit 1];
sessionDate = defaultDate.Session_Date__c;
refreshsessionList();
sessionChecked = false;
}

public void selectedSessions(){
if(sessionChecked==true)
selectedList.add(sessionId);
}


public List<SelectOption> getSessionDates(){
List<SelectOption> options = new List<SelectOption>();
List<Sessions__c> sessionList = [select Id, Session_Date__c from Sessions__c order by Session_Date__c asc];
Set<String> sessionSet = new Set<String>();
for(Sessions__c session: sessionList){
if(sessionSet.contains(session.Session_Date__c)){
}
else{
sessionSet.add(session.Session_Date__c);
options.add(new selectOption(session.Session_Date__c,session.Session_Date__c));
}
}
return options;
}

public void refreshsessionList(){
con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id,Session_Name__c, Presenters__c,Session_Time__c,Session_Location__c from Sessions__c where Session_Date__c=:sessionDate]));
con.setPageSize(10);
}

public void next(){
con.next();
}

public void previous(){
con.previous();
}

public Boolean getHasNext(){
return con.getHasNext();
}

public Boolean getHasPrevious(){
return con.getHasPrevious();
}

public List<Sessions__c> getSessions(){
return con.getRecords();
}

public PageReference Registration(){
User u = [select Id, Email,ContactId, CommunityNickName from User where id = :userinfo.getUserId()];
List<Sessions__c> registerList = [Select Id from Sessions__c where Id in :selectedList];
for(Sessions__c session : registerList){
Attendees_Registrations__c register = new Attendees_Registrations__c();
register.Sessions__c =session.Id;
register.Contact__c = u.ContactId;
register.AttendeeEmail__c = u.Email;
register.AttendeeEcas__c = u.CommunityNickname;
register.User__c = u.Id;
insert register;
}
return null;
}

}

Thanks, in advance

bob_buzzardbob_buzzard

I've found that since around the Winter 11 release, parameters don't get passed back to the controller unless the actionsupport component has a rerender attribute.  It seems like it needs to be an Ajax style request for this to work.

 

Thus I've ended up surrounding lots of my pages with outputPanel components that rerender most if not all of the entire page, and rerendering these.

JhogueJhogue

Why does the inputField param not get passed? What have i done wrong? It works for the Remove commandLink but not the inputField. Any help would be great..

 

            <apex:outputPanel id="dataItemsList">
                <apex:pageBlockSection id="itemsPageBlockSection" title="Items List"
                    columns="1" collapsible="false">
                    <apex:pageBlock id="itemsPageBlock">
                        <apex:pageMessages />
                        <apex:outputPanel layout="block" styleClass="container">
                            <apex:pageBlockTable id="pageBlockTableItems"
                                value="{!lstDetail}" var="det" style="width:100% padding:4px;"
                                rowClasses="even,odd" columns="4" columnsWidth="20%,70%,5%,5%">
                                <apex:column id="colSkuNumber" headerValue="SKU Number"
                                    style="border:1px solid #f3f3eb;">
                                    <apex:pageBlockSectionItem >
                                        <apex:actionRegion >
                                            <apex:inputField style="width:90%"
                                                value="{!det.detail.SKU_Number__c}">
                                                <apex:actionSupport event="onchange"
                                                    action="{!findSkuNumber}" rerender="dataItemsList"
                                                    immediate="true">
                                                    <apex:param id="selectedRowId" value="{!det.recId}" />
                                                </apex:actionSupport>
                                            </apex:inputField>
                                        </apex:actionRegion>
                                    </apex:pageBlockSectionItem>
                                </apex:column>
                                <apex:column headerValue="Description"
                                    style="border:1px solid #f3f3eb;">
                                    <apex:outputField style="width:100%"
                                        value="{!det.detail.Description__c}" />
                                </apex:column>

                                <apex:column headerValue="Quantity"
                                    style="border:1px solid #f3f3eb;">
                                    <apex:inputField style="width:50%"
                                        value="{!det.detail.Quanity__c}">
                                        <apex:actionSupport event="onchange" rerender="dataItemsList">
                                        </apex:actionSupport>
                                    </apex:inputField>
                                </apex:column>

                                <apex:column style="border:1px solid #f3f3eb;">
                                    <apex:commandLink value="Remove" action="{!Del}"
                                        rerender="dataItemsList" immediate="true">
                                        <apex:param name="rowToBeDeleted" value="{!det.recId}"
                                            assignTo="{!itemRowId}"></apex:param>
                                    </apex:commandLink>
                                </apex:column>

                            </apex:pageBlockTable>
                            <apex:commandbutton value="Add Row" action="{!Add}"
                                rerender="dataItemsList,msg" />
                        </apex:outputPanel>
                    </apex:pageBlock>
                </apex:pageBlockSection>
            </apex:outputPanel>


 

 

 

JhogueJhogue

Looks like I bone headed it... I had Id=selectedRowId and needed to use name=selectedRowId

 

Still have to rerender the whole page at this point. but it looks like i got it working..

 

Thanks

J