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
James Moore 52James Moore 52 

How do i render a VF page based on URL parameters?

Hello, 

I'm trying to render a visualforce page based on a value passed from another record.  The Custom Button URL i'm using to open the VF page is:
/apex/AvailableInstructors?id={!Lesson__c.Id}&Date_c={!Lesson__c.Lesson_Date__c}


and rendering the records using the following:
 
<apex:pageblocktable value="{!schedules}" var="s" columns="13" rendered="{!Schedule_Availability__c.Date__c== DATEVALUE($CurrentPage.parameters.Date__c)}" >
The VF page is showing all records and not rendering it based on the date value passed.  Any help would be appreciated!

Thanks!
Best Answer chosen by James Moore 52
JeffreyStevensJeffreyStevens
Okay - if you're using the standard controller - I don't think you can limit the records from the standard record set.  You might have to write a custom controller.

Check out this post...
https://developer.salesforce.com/forums/#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=906F0000000Au1WIAS

If you really want to stay with the StandardRecordSet controller - then you could go away from the PageBlockTable tag, build an HTML table, with do an apex repeat tag - and then conditionally render the <TR>'s.  I think you'll have about as much learning curve eitherway.

 

All Answers

JeffreyStevensJeffreyStevens
the rendered attribute is a boolean that will flag if the pageBlockTable tag will be rendered or not.  So - All you're doing is generating a boolean for if the parameter equals the Schedule_Availability__c.Date__c.  Check your controller - What is Schedule_Availability__c?  

You would need to limit the list "schedules" in your controller to the value of the $currentpage.parameters.Date__c.

(And check your apex call - you only have one underscore for the Date_c parameters - are you expecting two?
James Moore 52James Moore 52
@JeffreyStevens good catch on the Date_c parameter. I'm using the standard controller on the Custom Object Schedule_Availability__c , not a custom controller.  I'm trying to keep things as easy as possible.  
AdamDawAdamDaw
If it's not an issue with the date_c vs date__c, then it might be a typing issue. Are you sure it's properly being populate and the types i.e. dateformat match?
James Moore 52James Moore 52
@AdamDaw so both fields Schedule_Availability__c.Date__c and  $CurrentPage.parameters.Date__c are Field Type: Date.  I was getting an error on the data type, but tried to correct that using: DATEVALUE($CurrentPage.parameters.Date__c) Also, I have corrected Date_c to be Date__c, but the VF page is now throwing an error : Computed an invalid date, such as February 29th on a non-leap year. Please contact your administrator; formula fields can cause such errors.  
AdamDawAdamDaw
Doesn't sound like your date type is coming through properly. I would recommend printing both to the page to see what it's actually outputting.
JeffreyStevensJeffreyStevens
Okay - if you're using the standard controller - I don't think you can limit the records from the standard record set.  You might have to write a custom controller.

Check out this post...
https://developer.salesforce.com/forums/#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=906F0000000Au1WIAS

If you really want to stay with the StandardRecordSet controller - then you could go away from the PageBlockTable tag, build an HTML table, with do an apex repeat tag - and then conditionally render the <TR>'s.  I think you'll have about as much learning curve eitherway.

 
This was selected as the best answer
AdamDawAdamDaw
I just clued in to the fact that you're running this on the pageblock table itself. As Jeffrey said, this would only work to hide the entire table. It can't filter individual rows. The repeat method Jeffrey mentioned is likely the best one. That or an extension on the controller that would filter the initial set, and then display that modified set in the pageblocktable.
JeffreyStevensJeffreyStevens
Ya - here's a stab a doing with all in VF - a rough stab...
 
<table>
  <apex:repeat value="{!schedules}" var="schedule" id="theRepeat">
    <apex:outputText value="" rendered="{!if(schedule.date__c==DATEVALUE($CurrentPage.parameters.Date__c,true,false)}" >
      <tr>
          <td><apex:outputField value="{!schedule.Date__c}" /></td>
         <td><apex:outputfield value="{!schedule.CustomFieldNo2__c}" /></td>
      </tr>
    </apex:outputText>
  </apex:repeat>
</table>

something like that.
AdamDawAdamDaw
Only thing I would change there is maybe switch to an outputPanel instead of outputText. 
 
James Moore 52James Moore 52
Thank you AdamDaw and JefferyStevens!  I was afraid i may have to create a custom controller for this. I'll try the HTML table and see how that comes out!
Ghulam ChaudharyGhulam Chaudhary
Hi James Moore ,

<apex:pageblocktable value="{!schedules}" var="s" columns="13" rendered="{!Schedule_Availability__c.Date__c== DATEVALUE($CurrentPage.parameters.Date__c)}" >

this is a amizing method to render a PageBlockTable on a VF page using URL parameter...........

Thank you so much,
Ghulam