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
jhelblingjhelbling 

How to pass a parameter to a class from an VF page ?

Hello,


I guess this question has been raised several times already but I couldn't make it working even with some example found on the Web ...

I have an APEX class containing a variable for which I need to get a value from a VF Page. Then I have another method that should return the value of this variable (nothing useful ... just an example). My class contains the following :

 


public class myClass {
    public string myVariable;
  
    public string getTheValue() {    
        return myVariable;
    }
    
    public void setMyVariable(string s) {
        myVariable = s;
    }
}

 

An my page is as follow :

<apex:page standardController="Quote" renderas="pdf">
    <html>
        <body>    
            <div style="border-width:1px; border-style:solid; position:fixed; top:450px; right:1px">
<apex:outputText value="{!theValue}">
<apex:param assignTo="{!myVariable}" value="Hello World"/>
</apex:outputText>
            </div>
        </body>
    </html>
</apex:page>

 

But I never get anything displayed in the outputText tag. I tried to put the apex:param part before the outuputText as I thought that maybe it has not been initialized ... but it didn't help.

Does anybody have an idea about what's wrong ?

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Hmm.  Not sure I quite understand this.  

 

Are you trying to execute the SOQL query each time through the outer apex:repeat?  If so, that won't fly.  You'll need to set up all your data before the page is rendered.

 

If that's not what you are looking for, can you elaborate a little?

All Answers

bob_buzzardbob_buzzard

apex:param doesn't work that way with outputtext.  The params are used as replacements in the value of the output text.

 

The Apex Developer's Guide has examples of this at:

 

http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#CSHID=pages_compref_outputText.htm|StartTopic=Content%2Fpages_compref_outputText.htm|SkinName=webhelp

 

I wrote a blog post a few days ago regarding passing parameters from the page to the controller at:

 

http://bobbuzzard.blogspot.com/2011/07/passing-parameters-to-apex-method-from.html

 

 

 

 

sravusravu

Hi,

 

Have you tried using <apex:actionSupport> tag and are you performing any action before sending the variable to the controller.

 

Could you please ellaborate you requirement and what exactly you are trying to achieve.

 

 

 

 

 

srikeerthisrikeerthi

Hi

 

You can do that in this way there is no need of using contoller when you are

using Param for outputtext.

 

<apex:page standardcontroller="Quote" renderas="pdf">

<apex:form>

<apex:outputext value="{0}">

<apex:param value="Hello Word" assignedto="{!Myvalue}" name="param">

</apex:outputtext>

</apex:form>

</apex:page>

 

I think this solves your issue.

 

Thanks

 

jhelblingjhelbling

What I'm trying to do is actually the exact same situation described here : http://stackoverflow.com/questions/4094659/is-it-possible-to-pass-argument-from-visualforce-apex-tag

 

Do I really need a custom component if I have to dynamically pass a value ?

 

Thanks,

bob_buzzardbob_buzzard

Nope, you just need to use a commandlink/commandbutton and specify the apex:param inside that component.  Ensure that your commandlink/commandbutton has a rerender attribute and that you have specified a name, assignto and value attribute for the param.  Then by the time the action method that is the target of the button/link is executed, the parameter value will be available in the controller.

jhelblingjhelbling

Going further in the development : is it possible to assign a value to an APEX variable from a VF Page WITHOUT the apex:param tag ?

 

My VF Page will be rendered as PDF and I don't need any interaction with the user. I just need to assign some value to an APEX variable, and thoses values will come from data displayed in an apex:repeat tag ... In pseudo code it would look like :

 

apex:repeat
  outputtext ...
  outputtext ...
  assign value to apex variable
     apex:repeat
         outputtext ...
         outputtext ...
     end of apeax:repeat
end of apex:repeat

 

The idea is that the 2nd apex:repeat will get its value from a SOQL request that need the variable to be set with a value coming from the 1st apex:repeat bloc ... The variable will help filter out the data.

 

Thank you very much.

bob_buzzardbob_buzzard

Hmm.  Not sure I quite understand this.  

 

Are you trying to execute the SOQL query each time through the outer apex:repeat?  If so, that won't fly.  You'll need to set up all your data before the page is rendered.

 

If that's not what you are looking for, can you elaborate a little?

This was selected as the best answer
jhelblingjhelbling

Thanks bob_buzzard.

 

It's effectively what I was trying to do ... Ok I'll then look for another way to implement this.

 

Best regards,