3 Replies Latest reply on Aug 10, 2010 3:55 AM by eswaramoorthy1985

    How to search word in h:inputTextArea?

    eswaramoorthy1985

      Hi,

       

      I want to search (highlight)the word inside of h:inputtextArea.

       

      <h:inputText id="searchWordField" value="#{SearchBean.searchField}"/>
      <a4j:commandButton id="nextButtonId" value="Next"/>
      <a4j:commandButton id="prevButtonId" value="Previous"/>
      
      <h:inputTextarea id="textAreaId" rows="15" cols="140" 
                       readonly="true" 
                       value="Hi,How are you, Hi How are you, Hi how are you, Hi how are you,"/>                                                                  
      
      
      
      

       

      Here textarea contains 4 times of  Hi,How are you,  message.

       

      If i give the word Hi in textField   and click Next buuton,   then i need to highlight the word 'Hi'.

      And again click Next button, now highlight second 'Hi'.

       

      This same requirement, i need to click previous button.
      And also i search special symbol, date.

       

      In future, i will reterive filecontent, and display to textarea.. Like

      <h:inputTextarea id="textAreaId" rows="15" cols="140" 
                       readonly="true" 
                       value="#{SearchBean.fileContent}"/> 
      
      
      

       

      Help me.

      Thanks for your efforrt

        • 1. Re: How to search word in h:inputTextArea?
          sivaprasad9394
          Hi Moorthy,
          In your case,you can use the String class.suppose  if you are searching by Hi from the below string.
          String textStr="Hi,How are you,Hi How are you, Hi how are you, Hi how are you,";
          int indexValue=textStr.indexOf(searchparam text); For example consider (second Hi)
          indexValue= 15;                  (Approximately depends upon how you are giving string text with space and all)
          String a= textStr.substring(0,15);
          String criteriaStr = textStr.substring(15,SearchBean.searchField length);(for example your case hi is 2 length)
          String reminingStr = textStr.substring(search criteria text length,textStr length);
          Now you have to format the string with the CSS  styleclass.
          String fullString = a+<font class>criteriaStr<end font class> +reminingStr;
          Using this idea apply for all and similar manner Previous button clicking also.if there is need use for loop and hold Hi count values for searching second hi and next values.

          • 2. Re: How to search word in h:inputTextArea?
            ilya_shaikovsky

            you sure that for that case you need to use ajax? Maybe just try some JS solution?

            • 3. Re: How to search word in h:inputTextArea?
              eswaramoorthy1985

              Hi sivaprasad krishnaswamy ,

              In my textarea height is 15 (rows=15).

               

              For example assume this ,

              my filecontent more than 50 lines and Textarea have scrollbar option .

              And also , the word 'Hi' locations is line number 5, 25, 45,50.

               

              Now first time i click next button, Highlight the word 'hi'    in 5th line,.

              Then second time i click next button,

              now i want to highlight the word 'hi' in 25 th line, and automativally scroll down the taxtarea.

              Because the textarea height is 15 only (rows 50, cols 140).

               

              How to acheive this?