You need to sign in to do that
Don't have an account?

Passing Parameters from Visualforce Page to Controller methods
Am I allowed to pass a parameter from my visualforce page to a controller method?
I want to create a method which returns boolean TRUE or FALSE depending on if the related list contains any records. I'm trying to avoid creating 15-20 get/set methods.
Code:
VisualForce Page Segment: <apex:page standardController="Account" extensions="AccountHiddenListControllerExtension"> </apex:detail> <apex:relatedList list="contacts" rendered="{!doesRelatedListExist('contacts'}">> </apex:relatedList> <apex:relatedList list="ActivityHistories" rendered="{!doesRelatedListExist('ActivityHistories'}">> </apex:relatedList> </apex:detail> </apex:page> Controller class: public boolean doesRelatedListExist(String listName) { if (listName.equals('contacts')) { return ((this.getContactList().size()) > 0); } if (listName.equals('ActivityHistories')) { return ((this.getActivityHistoriesList().size()) > 0); } // default value return true; }
The controller saves correctly; however, i get the following error message when saving the visualforce page:
Error: Unknown function doesRelatedListExist. Check spelling.
Thanks in advance.
Message Edited by wsthesis on 12-25-2008 06:26 PM
The good news is that there is a 100% VF component based way to do this - no flurry of apex code getters etc. I created a not exactly obvious custom component:
that can be used like this:
Message Edited by dchasman on 12-30-2008 11:20 PM
All Answers
Jeremy Kraybill
Austin, TX
The good news is that there is a 100% VF component based way to do this - no flurry of apex code getters etc. I created a not exactly obvious custom component:
that can be used like this:
Message Edited by dchasman on 12-30-2008 11:20 PM
Jeremy Kraybill
Austin, TX
dchasman wrote:
This gets to be so much simpler in the Spring '09 release because I finally added support for List and array getSize() in VF formulas which would allow you to simply use rendered="{!account.contacts.size > 0}" but that will have to wait a little bit longer.
Nice! I will definitely be looking forward to this new feature.
I am trying to do it in pageblock, but not able to fig it out.
VF:
<apex:column headerValue="Remove">
<apex:commandButton value="Remove" action="{!removeProduct}" />
<apex:param assignTo="{!removeProductCode}" value="{!s.pbEntry.ProductCode}"/>
</apex:column>
In Controller, I have String Obj removeProductCode and method removeProduct. But for some reason I am not able to get the
"s.pbEntry.ProductCode" in controller. I tried name attr in <apex:param/> as well.
thanks for the time..
Try this:
1) Added param tag inside of the commandButton tag
2) Added rerender to button. There is (maybe was) a bug where param doesn't work with commandButton if rerender is not defined.
3) Also added name attribute to param as I have seen strange behavior when this is not added.
Hope that helps,
Jason
I tried many different solution, one was what you mentioned.
for now I am using the the apex:commandlink and is working fine. .
thanks
While trying to use {!account.contacts.size > 0} in visualforce page i get the error Error: Invalid field 'size' for SObject 'Contact'. I have a VF page with standardController="Account". It does not have any extensions.