2

I'm trying to add an article search feature to a custom portal page. I have a Search Component, a Controller, and a VF page for this functionality.

The issue is when I enter an InputText in the search component, the text is not passed on to the controller and VF page, and no results are returned.

If I enter text directly in the search box on the VF page, there's success. But the requirement is for the search to be on the component so that it can be iterated on various VF pages. I've posted the code below:

The Component:

<apex:component controller="vfKeywordSearchController">
  <apex:attribute name="theSearchResults" type="String" description="Id of the section rerender."     assignTo="{!searchstring}"/>
    <apex:form >
     <apex:inputText value="{!searchstring}" id="theSearchstring" maxlength="100" size="70"/> &nbsp;
    <apex:commandButton value="Go" id="submitButton" style="width:30" reRender="" action="{!onClick}"/>
   </apex:form>
    </apex:component>

The Controller:

public with sharing class vfKeywordSearchController {

    //Page Size
     private Static Final Integer PAGE_NUMBER = 10;

     //Search String used in ArticleList tag
       public String searchstring { get; set; }

          public PageReference onClick(){
           return new PageReference('/apex/Global_Search_Test?searchParameter='+searchstring);
      }

      public vfKeywordSearchController() {
   String qryString = 'SELECT Id, title, UrlName, LastPublishedDate,LastModifiedById FROM     KnowledgeArticleVersion WHERE (PublishStatus = \'online\' and Language = \'en_US\')';
       List<KnowledgeArticleVersion> articleList= Database.query(qryString);
     maxSize = articleList.size() ;
     }

  //Keeps track of current page & max size of article list
   Integer currentPage = 1;
    Integer maxSize = 1;

   // Returns whether we need to see previous button or not
      public boolean getPrevRequired() {
    return currentPage > 1;
      }

      // Returns whether we need to see next button or not
      public boolean getNextRequired() {
      return currentPage * PAGE_NUMBER < maxSize;
     }

     //Returns current page number 
    public Decimal getCurrentPageNumber() {
     return this.currentPage;
      }

     //action for next click
      public PageReference next() {
      if(maxSize > this.currentPage * PAGE_NUMBER) {
       this.currentPage = this.currentPage + 1;
        }
      return null;
     }    

      //action for previous click
      public PageReference previous() {        
       if(this.currentPage > 1)
        this.currentPage = this.currentPage - 1;
       return null;
       }
       }

The VF Page:

    <apex:page id="mypage" controller="vfKeywordSearchController">
         <apex:composition template="LATemplate">
          <c:LASearchComponent theSearchResults="Global_Search_Test:theSearchResults"/>
              <apex:define name="body">
             <apex:form >
             <apex:inputText value="{!searchstring}" id="theSearchstring" maxlength="100" size="70"/> &nbsp;
                 <apex:commandButton value="Go" id="submitButton" style="width:30" reRender=""  action="{!onClick}"/>
                 <apex:panelGroup id="theSearchResults" >
               <apex:panelGrid width="100%">
                 <table width="99%">
           <tr>
             <th width="33%">Title</th>
            <th width="33%">Article Type</th>
            <th width="33%">Summary</th>
            </tr>
            </table>
         <knowledge:articleList articleVar="article" pageNumber="{!currentPageNumber}" Keyword=" {!searchstring}" hasMoreVar="false" pageSize="10">
             <table  width="99%">
             <tr>
             <td width="33%">
              <apex:outputLink target="_blank" value="{!URLFOR($Action.KnowledgeArticle.View, article.id,['popup' = 'true'])}">{!article.title}</apex:outputLink>
                 </td>
              <td width="33%"><apex:outputText >{!article.articleTypeLabel}</apex:outputText></td>
              <td width="33%"><apex:outputText >{!article.abstract}</apex:outputText></td>
                </tr>
           </table>
            </knowledge:articleList>
            </apex:panelGrid> 
          <apex:panelGrid columns="2">
          <apex:commandLink action="{!previous}" value="Previous" style="{!IF(prevRequired = true,'display:block','display:none')}" reRender="theSearchResults"/> 
             <apex:commandLink action="{!next}" value="Next"  style="{!IF(nextRequired = true,'display:block','display:none')}" reRender="theSearchResults"/>  
             </apex:panelGrid>
             </apex:panelGroup>
        </apex:form>
           </apex:define>
    </apex:composition>
        </apex:page>

I appreciate any pointers.

1 Answer 1

1

I was working on actionFunction and came across your question about getting inputText value to controller.

Its a simple code where user enters the number of units in the input and onBlur the total price is calculated.

Hope it helps you.

Component:

<apex:component controller="clsActionFunction">
<apex:form>
    <apex:pageBlock>
        <apex:pageBlockSection columns="2">
            <apex:pageBlockSectionItem>
                <apex:outputText value="Price"/>
                <apex:inputText onBlur="calculateTotal()" value="{!Quantity}"/>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem>
                <apex:outputText id="totalPrice" value = "Total Price : {!total}"/>
            </apex:pageBlockSectionItem>
            <apex:actionFunction name="calculateTotal" action="{!CalculateTotal}" rerender="totalPrice"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>

Visualforce Page:

<apex:page controller="clsActionFunction">
    <c:vfActionFunctionComponent/>
</apex:page>

Controller:

public with sharing class clsActionFunction {

    public integer Quantity {get;set;}
    public integer Total{get;set;}

    public pageReference CalculateTotal()
    {   
        system.Debug('Quantity : ' + Quantity);
        Total = Quantity *100;
        system.Debug('Total Price : ' + total);
        return null;
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .