0

We have a visualforce presenting a list of dates. It uses a repeater to display the dates to a user and I have been trying to add a button to the repeater that then saves the value to the controller to update the record. It is a detail page visualforce page.

Visualforce

<apex:page standardController="Order" extensions="customOrderExtenstionTest" showHeader="false" standardStylesheets="false" >
 <apex:form>
    <apex:actionregion>
         <apex:repeat value="{!list}" var="currentDate">
            <apex:outputText value="{0,date, EEEE dd MMMM yy}">
                <apex:param value="{!currentDate}"/>    
            </apex:outputText>
            <apex:commandLink  style="btn" action="{!saveDate}" value="Select Date" reRender="hidden"> {!currentDate}
               <apex:param name="selectedDate" id="param1" value="{!currentDate}" assignTo="{!selectedDate}"/>
            </apex:commandLink>
            <apex:outputPanel id="hidden" rendered="false"/>
        </apex:repeat>
    </apex:actionregion>
 </apex:form>
</apex:page>

And the apex is pretty simple:

Apex Custom Controller

public with sharing class BulkyItemOrderCalendarController 
public Date selectedDate {get;set;}
...
public pageReference saveDate(){
    try{
        system.debug('SELECTED DATE ============' + selectedDate);
        currOrder.Allocated_Date__c = selectedDate;
        update currOrder;
        return null;
    }
    catch(Exception e){
        System.debug('Exception occurred '+String.valueOf(e));
        ApexPages.addMessages(e);
        return null;
    }
}

An error is always displayed stating "Argument cannot be null". However I can see the content of {!currentDate} printed on the VF page. I am aware of the commandButton issue so I have tried commandLink without success (above) but I also tried the rerender of a hidden panel hack too.

Thanks, sorry I fear it is another obvious mistake/misunderstanding.

2
  • 2
    I think you have to add the name attribute to your <apex:param> tag for it to actually bind back to the controller. Can't hunt down where I read that at the moment. – Adrian Larson Sep 13 '17 at 16:09
  • Thanks, I added a name attribute in (I edited the code above) but I am afraid the same thing happens. – sfdc_beginner1 Sep 13 '17 at 16:13
4

Yes as Adrian mentioned in comment Name works as a key so you need to add that as well. Without it you don't get any error but your value will not be passed to controller.

Apex:param

Also Date type can't be directly passed as Apex:param only support string, number, or boolean value. So you need to convert it into string pass it into controller and then in controller change it into date again.

<apex:param name="setDescription" value="{!TEXT(date2)}" assignTo="{!dateString}" />
2
  • 1
    Thanks that is much better. Thanks. I can see the date being passed and in the debug it is format as yyyy-mm-dd yet I am receiving an error stating: "Exception occurred System.TypeException: Invalid date: 2017-10-27" I used "date.parse(selectedDate);" – sfdc_beginner1 Sep 14 '17 at 9:22
  • got it working with date.valueOf(selectedDate); thanks. – sfdc_beginner1 Sep 14 '17 at 10:03

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.