How do I pass a parameter from component to a Visualforce page?

  • Can I pass a email value from a visualforce component to a Visualforce page? I have used components for reusing Company's logo and few images...

    <apex:component>
        <apex:image value="{!$Resource.Logo}"> </apex:image>
    </apex:component>
    

    Is it possible to pass variable to a visualforce page?

    Thanks.

  • The easiest way is to pass in the controller of your visualforce page. This means you'll need either a custom controller or an extension. When you pass in the controller, you can then call getters or setters on the controller given they are publicly accessible.

    For example:

    <apex:component>
        <apex:attribute name="ctrl" description="My controller" type="MyControllerClassName" required="true"/>
        <apex:image value="{!URLFOR(ctrl.ImageUrlGetter)}"> </apex:image>
    </apex:component>
    

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM