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
TheMythicalTheMythical 

Can we pass parameters from visualforce to apex?

I want to do something like this:

 

rendered="{!confirmMessagesExist('CONFIRM')},

 

I have a function defined in Apex class called getConfirmMessagesExist.

 

But each time I save the page, it says can not find function name confirmMessagesExist. Any Idea?

 

Can we pass parameters from visualforce to apex? Thanks!

Rajesh ShahRajesh Shah

You can use the param apex tag to pass the parameter from Visualforce to apex. Heres an example:

 

 

<apex:actionSupport event="onclick" action="{!findDates}" reRender = "Dates ,TranscriptPanel"> <apex:param name="paramid" value="{!UserLists.UserId}"/> </apex:actionSupport> //////////// Heres the controller part // Inside the function findDates() String msgId = :ApexPages.currentPage().getParameters().get('paramid')

 

 

 

Edwin VijayEdwin Vijay

You cannot pass parementers like the way you have done.. even though that sounds a sensible format that is not supported as of now..

 

But as Rajesh has said you can use <apex:param> to pass parameters

NikhilNikhil

This is a wrong way of calling a apex method

Attibute rendered can only use formula functions/OR apex class properties{getter/setter}

available within salesforce

 

you can use it like this wasy as per your requirement

 

rendered = "{!IF(ConfirmMessagesExist == 'CONFIRM' ,true,false)}"

 

not ths will work and will also not give you any error like  can not find function name confirmMessagesExist.

 

Happy coding....

TheMythicalTheMythical

Here is the thing, I want to write a common function to decide whether a particular type of message exists and I will use this function in the visualforce page many times, so I need to pass the message type to this common function.

 

I can't use 'rendered={!IF(message=='CONFIRM', true, false)}'  because the message should return a value based on the parameter value. Thanks!

miteshsuramiteshsura

I have similar situation. Can you tell how to use the actionSupport with commandButton? I have pageBlock that displays the product with its productcode along with remove button for each row.

 

When I hit remove, I want ProductCode of the row to pass to Controller, but just can't do it.

 

VF:

<apex:column headerValue="Remove">  
                    <apex:commandButton value="Remove" action="{!removeProduct}" />
                    <apex:actionSupport event="onclick" action="{!removeProduct}" >                                
                        <apex:param name="removeProductCode" value="{!s.pbEntry.ProductCode}"/>  
                    </apex:actionSupport>
                </apex:column>

 

Controller:

//Remove the product from selected list
    public PageReference removeProduct(){
        String removeProductCode = ApexPages.currentPage().getParameters().get('removeProductCode');
        system.debug(removeProductCode);
        return null;
    }

 

in debug log I do not see any value for the ProductCode. Thanks.

Edwin VijayEdwin Vijay

Hello Mitesh,

 

One problem that i could see in your code is that the apex:param tag does not work with apex:commandbutton. This is a long known bug that has been existing for a while... For your specific requirement you need not even have a actionsupport..

 

Try using a apex:commandlink instead of apex:commandbutton...

 

If you want the link to look like a button, here is the workaround

 

 

<apex:commandlink action="{!removeProduct}">                         
                        <apex:param name="removeProductCode" value="{!s.pbEntry.ProductCode}"/>  
                       <apex:commandbutton value="Remove" />
</apex:commandlink>

 

 

miteshsuramiteshsura

no wonder it was not working, I fig'd to use a link instead of button yday. I will try the work around for button, will be helpful in future.. do you know any fix for commandbutton and param ?? thank you ..