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
afoxmicroedgeafoxmicroedge 

Passing value from input text to URL

I am building a custom search page. I need to pass the value entered in the input text to url parameter to exexcute the search. Right now if I manually enter search term in URL it will execute the search i.e. /apex/portalcasesearch?s=testsearchterm will return page with results for testsearchterm and the value of testsearchterm will show in inputextarea. So it seems I have it backwards at the moment. Is there a way to do this without using JavaScript or jQuery? Willing to start from scratch if anybody has an idea of how to accomplish this. I am a beginner so I may be missing a very fundamental aspect and just don't realize it. 

 

VF Page

<apex:page id="portalCaseSearch"
    standardController="User" 
    extensions="PortalCaseSearchUserContExt"
    title="Search ~ Customer Portal" 
    sidebar="false">

  <apex:stylesheet value="{!$Resource.Jquery_css}"/>

  <style type="text/css">
    .newCase{
        background-color: white;
        border-width: 2px;
        border-style: solid;
        z-index: 9999;
        left: 50%;
        padding:10px 10px 20px 10px;
        position: absolute; 
        //width: 800px;
        //height: 500px;
        margin-top: center;
        margin-left: -400px;
        top:100px;
    }
    .newCaseBackground{
        background-color:black;
        opacity: 0.20;
        filter: alpha(opacity = 20);
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        z-index: 9998;
    }
  </style>
  
   <script type="text/javascript">
  function insertSearchParam(){
    var val = document.getElementById("{!$Component.searchinput}").value;
    document.location.search = "?s=" + val;
    searches();
}
document.getElementById("{!$Component.searchinput}").onkeypress = function(e){
    if (!e) e = window.event;  
    if (e.keyCode == '13'){
      insertSearchParam();
      return false;
    }
  }
</script>
  
  <body id="bodyPortalCaseSearch">
   <apex:form id="frmPortalCaseSearch">
    <apex:pageBlock id="pbPortalCaseSearch">

     <div class="table">
      <div class="tableRow">       
       <div id="searchDiv" class="tableCell">
         <apex:inputText id="searchinput" style="width:85%; height:25px;margin:0; padding: 0px 6px 0px;" title="Portal_Search_Phrase" value="{!portalSearchModel.searchTerm}"/>
         <apex:commandLink id="goSearch" title="Search"  style="text-decoration:none;" rerender="opResultsBlock">Search
             <apex:param name="searchTerm" value="{!portalSearchModel.searchTerm}"/>
         </apex:commandLink>

 

Controller:

 

public class PortalCaseSearchModel {
    
    public String searchTerm { get; set; }

    public transient QuestionSearch questionSearch { get; private set; }
    public transient QuestionFIMSSearch questionFIMSSearch { get; private set; }
    public transient QuestionAPSearch questionAPSearch { get; private set; }
    public transient ReplySearch replySearch { get; private set; } 
    public transient ReplyFIMSSearch replyFIMSSearch { get; private set; }
    public transient ReplyAPSearch replyAPSearch { get; private set; } 
    public transient SolutionSearch solutionSearch { get; private set; }
    public transient SolutionFIMSSearch solutionFIMSSearch { get; private set; }
    public transient SolutionAPSearch solutionAPSearch { get; private set; }
    public transient IdeaSearch ideaSearch { get; private set; }
    public transient IdeaFIMSSearch ideaFIMSSearch { get; private set; }
    public transient IdeaAPSearch ideaAPSearch { get; private set; }
    public transient CaseSearch caseSearch { get; private set; }
    public transient CaseFIMSSearch caseFIMSSearch { get; private set; }
    public transient CaseAPSearch caseAPSearch { get; private set; }
    public transient ContentSearch contentSearch { get; private set; }
    public transient ContentFIMSSearch contentFIMSSearch { get; private set; }
    public transient ContentAPSearch contentAPSearch { get; private set; }
    
    private final UserModel portalUserModel;
    
    public PortalCaseSearchModel(User portalUser) {
      final Map<String,String> urlParameters = ApexPages.currentPage().getParameters();   
        if(!urlParameters.containsKey('s')) {
          throw new PortalSearchException('No URL Parameters?!?');
        }
        
        if(urlParameters.size() != 1) {
          throw new PortalSearchException('More than two URL Parameters?!?');
        }
        
        this.searchTerm = urlParameters.get('s');       
        if(this.searchTerm.length() <= 1) {
          throw new PortalSearchException('Search Term has to be 2 characters or greater!');
        }
        this.portalUserModel = new UserModel(portalUser);        
        final DictionarySearch dictionarySearch = new DictionarySearch(this.searchTerm);

        
public void searches(){
    questionSearch.search();
    questionFIMSSearch.search();
    questionAPSearch.search();
    replySearch.search();
    replyFIMSSearch.search();
    replyAPSearch.search();
    solutionSearch.search();
    solutionFIMSSearch.search();
    solutionAPSearch.search();
    ideaSearch.search();
    ideaFIMSSearch.search();
    ideaAPSearch.search();
    caseSearch.search();
    caseFIMSSearch.search();
    caseAPSearch.search();
    contentSearch.search();  
    contentFIMSSearch.search();
    contentAPSearch.search(); 
}
    }

 

JitendraJitendra
If you dont want to use JQuery or Javascript. you can create a method in Controller class with return type "PageReference". Call that method from Search button (Command Button). However this will be slow as it needs to postback and then redirect to search page as compared to JQuery / JavaScript.
csorrowscsorrows

I'm very new to VF and Apex, but just wrote a custom search page and Apex controller that has a selectList and one inputText field as input, and a "Search' command button.

 

When the user clicks the "Search" button, it invokes a doSearch method in the controller that does a SOQL query, sets some search results fields, and a rerender parameter on the commandButton refreshes a couple sections on the page with the search results.

 

Was there a reason why you had to pass parameters in the URL?  I'm thinking of enhancing mine to allow parms in the URL so the page could be invoked by other systems, and show up already populated with search results in that case.  But I haven't made those changes yet.  Just using a search action on the commandButton and rerendering afterwards seems to work for me.

Chamil MadusankaChamil Madusanka

http://boards.developerforce.com/t5/Visualforce-Development/How-to-create-a-record-and-redirect-to-VF-page-that-allows/m-p/566123#M60333

 

This is a similar post. Refer this.

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.