This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes JSF and the fly likes Highlighting Words in JSF components Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Highlighting Words in JSF components" Watch "Highlighting Words in JSF components" New topic
Author

Highlighting Words in JSF components

Dave Brown
Ranch Hand

Joined: Mar 08, 2005
Posts: 301
Hi All,

Just wondering if the following is possible..

When I submit my record to be saved.. I check for certain 'badwords'/expletives in some of the fields. If any are found I would love to be able to highlight those words... However I'm using SelectInputText components.. So I dont think thats possible...

Secondly I have a datatable with a Lucene based search facility which populates the table depending on the search.. Again I would love to be able to highlight the search term(s) in the table of results... I imagine this would be more possible as it presents its data using OutputText components...

Any thoughts appreciated.

Thanks


Regards, Dave Brown
SCJP 6 - [url]http://www.dbws.net/[/url] - Check out Grails Forum
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Use a client side language like Javascript.


Code depot of a Java EE / JSF developer | JSF / Eclipse / Tomcat kickoff tutorial | DAO kickoff tutorial | I ♥ Unicode
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 14571
    
    7

The inputText JSF tag renders as an HTML INPUT TYPE=TEXT control, so you're out of luck there, since that control lacks fine-grained formatting features. You'd have to replace it with a smarter input text control than the standard JSF one.

outputText is much easier. Just format the property string using HTML markup and use the escape="false" attribute on the outputText element.


Customer surveys are for companies who didn't pay proper attention to begin with.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Kickoff: http://google.com/search?q=javascript+highlighting
Dave Brown
Ranch Hand

Joined: Mar 08, 2005
Posts: 301
Tim Holloway wrote:The inputText JSF tag renders as an HTML INPUT TYPE=TEXT control, so you're out of luck there, since that control lacks fine-grained formatting features. You'd have to replace it with a smarter input text control than the standard JSF one.

outputText is much easier. Just format the property string using HTML markup and use the escape="false" attribute on the outputText element.


Ahh okay thanks.. so in the case of my table.. would this be a worthy approach : User enters search term and clicks search button... I add the search phrase to session, then after applying a special Converter to each column in the table, I could pick up the search term from the session in the converter getAsString() method and look for and apply html to the found text there..

As for the InputText boxes.. Best I can do there is just apply a 'message' to the relevant box indicating that a badword was found...

Thanks for the input..
Sir General
Greenhorn

Joined: Feb 19, 2009
Posts: 1
Using Javascript would be efficient and the best solution.

I had implemented lucene search in my app. Though I just highlight the search text when a hit or a search result is selected.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Highlighting Words in JSF components
 
Similar Threads
Opening a File with the appropriate program with highlighted text
searching a row using text fields
Highlighting HTML string that spans tags
Highlight the words in files( doc, excel, pdf etc) using java
searching and replacing words in a paragraph