+ Start a Discussion
pierpipierpi 

Passing parameters from VF to apex controller

It is probably an easy question, but I have been looking at the messages on the board and I can't still figure this out.  I need to display the translation of a given key (string) for multiple keys.  Basically is as if i need to call multiple times the same method with different parameters.  I was thinking to define a controller with a map of all possible keys (and their associated translation). 

 

I tried the following (simplified version):

 

(i also tried to assign to inputParam below a dynamically "retrieved" string <apex:param name="currText" value="{!num}" />)

 

<apex:page controller="DictionaryController">

   <apex:outputText value="Translation for one is: {!outParam}">
      <apex:param assignTo="{!inputParam}" value="one" />
      <apex:param name="currText" value="one" />
      <apex:param name="q" value="{!outParam}"/>
   </apex:outputText>

</apex:page>

and the controller:

 

public with sharing class DictionaryController {
 public String inputParam {get; set;}
 private String outParam;
 

//the getOutParam method also does not work (inputParam is null) if it tries to get the inputParam value, which should

//have been set previously via the apex:param .... assignTo declaration in the apex page.


 public String getOutParam(){
  String currText = System.currentPageReference().getParameters().get('currText');
  
  if( currText == 'one') return 'uno';
  else return 'altro';
 }
 
 public String getNum() {
  return 'one';
 }
}

 

Thanks a lot for the help.

bob_buzzardbob_buzzard

Unfortunately, the apex param tag when used with outputText doesn't work in the way that you are hoping.  From the docs:

 

For example, if you use "My {0}" as the value

of an outputText component and then include a param in the body

of the outputText component, the value of the param tag replaces

the {0} in the output text string.

 

If you are simply going through a number of translations for a particular value, I'd suggest storing them in a List and iterating them via a PageBlockTable or a repeat. 

pierpipierpi
Thanks for the explanation.