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
mavsmavs 

issue in passing parameters to outputlink

hi

 

I want to pass the selected value of the radio as a parameter to OutputLink value. Below is the code

 

I selected 2008 and clicked on the Run Report Link, this is how the URL value is

 

http://abc=/

 

When it should have been http://abc=2008/

 

Does anyone see issue with the code below? Please advise...

 

Thanks

 

<apex:page controller="output_test">
    <apex:form >
    <apex:pageBlock >
        <apex:outputLabel value="Select Year" />
            <apex:selectRadio value="{!year_num}" rendered="true">
            <apex:selectOptions value="{!items}"/>
            </apex:selectRadio>                  
     <apex:outputlink target="_blank" value="http://abc={!year_num}">Run Report</apex:outputlink>
    
     </apex:pageBlock>
     </apex:form>
</apex:page>

 

public class output_test
{
    String year_num = null;
                
    public List<SelectOption> getItems() 
    {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('2008','2008')); 
        options.add(new SelectOption('2009','2009')); 
        options.add(new SelectOption('2010','2010')); 
        options.add(new SelectOption('2011','2011')); 
        
        return options; 
    }
                   
    public String getYear_num() 
    {
        return year_num;
    }
                    
    public void setYear_num(String year_num) 
    { 
        this.year_num = year_num; 
    }
}

 

Best Answer chosen by Admin (Salesforce Developers) 
WesNolte__cWesNolte__c

Ah I see, for this I think we're best off using a commandLink e.g.

 

<apex:page controller="output_test">
    <apex:form >
    <apex:pageBlock >
        <apex:outputLabel value="Select Year" />
            <apex:selectRadio value="{!year_num}" rendered="true">
            <apex:selectOptions value="{!items}"/>
            </apex:selectRadio>                  
     <apex:commandLink target="_blank" action="{!myaction}" value="Run Report"></apex:commandLink>
    
     </apex:pageBlock>
     </apex:form>
</apex:page>
public class output_test
{
    public String year_num{get;set;};
                
    public List<SelectOption> getItems() 
    {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('2008','2008')); 
        options.add(new SelectOption('2009','2009')); 
        options.add(new SelectOption('2010','2010')); 
        options.add(new SelectOption('2011','2011')); 
        
        return options; 
    }
                   
    public String getYear_num() 
    {
        return year_num;
    }
                    
    public void setYear_num(String year_num) 
    { 
        this.year_num = year_num; 
    }

    public PageReference myaction(){
PageReference pr = new PageReference('http://th3silverlining.com');
pr.put('abc',year_num);
return pr;
}
}

All Answers

Ispita_NavatarIspita_Navatar

Please do modify the code as per the text highlighted in red below:-

 

<apex:pageBlock >
        <apex:outputLabel value="Select Year" />
            <apex:selectRadio value="{!year_num}" rendered="true">
            <apex:selectOptions value="{!items}"/>
            </apex:selectRadio>                  
     <apex:outputlink target="_blank" value="page3&abc={!year_num}" >Run Report</apex:outputlink>
    
     </apex:pageBlock>

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

mavsmavs

HI - Still no luck

 

I changed the output link as mentioned , When clicked on the output link

 

<apex:outputlink target="_blank" value="page3&abc={!year_num}" >Run Report</apex:outputlink>

 

This is what i got.

apex/page3&abc=

 

I am looking for selected radio value to appear

apex/page3&abc=2008

 

 

Please advise

WesNolte__cWesNolte__c

Hey

 

You can try using the param tag

 

 

<apex:outputLink value="http://th3silverlining.com">Run Report
	<apex:param name="abc" value="{!year_num}"/>
</apex:outputLink>

 

Cheers,
Wes

 

mavsmavs
<apex:outputLink value="http://silverlining.com">Run Report
	<apex:param name="abc" value="{!year_num}"/>
</apex:outputLink>  
The output is coming as http://silverlining.com?abc=

 

nope...it dint work either

 

I know this is simple, but not sure where i am doing wrong...

 

 

 

WesNolte__cWesNolte__c

In that case your year_num variable must be empty. I just tested with that precise code and it works.

 

Wes

WesNolte__cWesNolte__c

It is null initially

 

public class output_test
{
    String year_num = null;
                
    public List<SelectOption> getItems() 
    {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('2008','2008')); 
        options.add(new SelectOption('2009','2009')); 
        options.add(new SelectOption('2010','2010')); 
        options.add(new SelectOption('2011','2011')); 
        
        return options; 
    }
                   
    public String getYear_num() 
    {
        return year_num;
    }
                    
    public void setYear_num(String year_num) 
    { 
        this.year_num = year_num; 
    }
}
Try giving it an initial value, or change the selectlist on your page before you push the button. Wes
mavsmavs
public class output_test
{      
    public String year_num { get; set; }    
            
     public List<SelectOption> getItems() 
     {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('2008','2008')); 
        options.add(new SelectOption('2009','2009')); 
        options.add(new SelectOption('2010','2010')); 
        options.add(new SelectOption('2011','2011')); 
        
        return options; 
     }
}

 

 Thank you.

 

Putting initial value will pass what ever value was initialized. If another value is selected, it still passes the initial value.

 

I tried the above method as well..but no luck..:smileysad:

 

By the way

I did not get what you are saying (in red below) could you please eloborate?

Try giving it an initial value, or change the selectlist on your page before you push the button

 

 

WesNolte__cWesNolte__c

Ah I see, for this I think we're best off using a commandLink e.g.

 

<apex:page controller="output_test">
    <apex:form >
    <apex:pageBlock >
        <apex:outputLabel value="Select Year" />
            <apex:selectRadio value="{!year_num}" rendered="true">
            <apex:selectOptions value="{!items}"/>
            </apex:selectRadio>                  
     <apex:commandLink target="_blank" action="{!myaction}" value="Run Report"></apex:commandLink>
    
     </apex:pageBlock>
     </apex:form>
</apex:page>
public class output_test
{
    public String year_num{get;set;};
                
    public List<SelectOption> getItems() 
    {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('2008','2008')); 
        options.add(new SelectOption('2009','2009')); 
        options.add(new SelectOption('2010','2010')); 
        options.add(new SelectOption('2011','2011')); 
        
        return options; 
    }
                   
    public String getYear_num() 
    {
        return year_num;
    }
                    
    public void setYear_num(String year_num) 
    { 
        this.year_num = year_num; 
    }

    public PageReference myaction(){
PageReference pr = new PageReference('http://th3silverlining.com');
pr.put('abc',year_num);
return pr;
}
}
This was selected as the best answer
mavsmavs

Thanks that worked...

 

small change

 

pr.getParameters().put('abc',year_num);