Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am using inputText to capture user input and then this input needs to be passed to a URL as a parameter. I am using the following code:

<apex:form >
<apex:panelGrid columns="2" rendered="true"> 
    <apex:inputText value="{!searchText}" id="textsearch" rendered="true" />
    <apex:outputLink id="link"  value="/apex/VFPageName">Search
        <apex:param value="{!searchText}" name="searchParameter"/>
    </apex:outputLink>
</apex:panelGrid>

Controller code

public string searchText{get;set;}

The problem here is that when I enter a value in the text box and press the link the redirect is being performed but the parameter value is blank. Another strange thing is if I enter a value and press enter and then click on the link then the parameter is being passed with the correct value.

What I am looking out is for normal functionality to work i.e. user enters text and on click of the link the user is redirected with the parameter set correctly

Please advice

share|improve this question
    
How does this pass the parameter to your page? It seems like something is missing in your controller. –  JimRae Feb 2 at 19:00
add comment

3 Answers

You can not pass searchText into your link, because it will be always blank when you load your page. I would do more something like :

<apex:form >
   <apex:panelGrid columns="2" rendered="true"> 
      <apex:inputText value="{!searchText}" id="textsearch" rendered="true" />
      <apex:outputLink id="link"  action="{!processLinkClick}">Search</apex:outputLink>
   </apex:panelGrid>
 </apex:form>

public string searchText{get;set;}
 public PageReference processLinkClick() {
    return new PageReference('/apex/VFPageName?searchParameter='+searchText);
 }
share|improve this answer
add comment

I am thinking, based on what you described, that you need to do something like this:

<apex:form >
   <apex:panelGrid columns="2" rendered="true"> 
      <apex:inputText value="{!searchText}" id="textsearch" rendered="true" />
      <apex:outputLink id="link"  action="{!processLinkClick}">Search
         <apex:param value="{!searchText}" assignTo"{sText}"" name="searchParameter"/>
      </apex:outputLink>
   </apex:panelGrid>
 </apex:form>

 public String sText {get; set;}
 public PageReference processLinkClick() {
    System.debug('sText: '+sText);
    return new PageReference('/apex/VFPageName?searchParameter='+sText);
 }
share|improve this answer
add comment

Visualforce page :

<apex:form>
  <apex:panelGrid columns="2" rendered="true"> 
    <apex:inputText value="{!searchText}" id="textsearch" rendered="true" />
<apex:outputLink id="link"  value="/apex/VFPageName">Search
    <apex:param assignTo="{!SText}" value={!searchText} name="searchParameter"/>
</apex:outputLink>

And change a little bit in Controller Code -

public string SText{get;set;}

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.