If you are displaying search results dynamically, and it's not part of your
static markup, you can also do something like this:
class HighlightingModel extends LoadableDetachableModel<String> {
private transient IModel<String> text;
private transient IModel<String> searchWord;
HighlightingModel(IModel<String> text, IModel<String>
searchWord) {
this.text = text;
this.searchWord = searchWord;
}
@Override
protected String load() {
return text.getObject().replaceAll(searchWord.getObject(),
"<span class=\"search\">" + searchWord.getObject() + "</span>");
}
@Override
protected void onDetach() {
super.onDetach();
text = null;
searchWord = null;
}
}
IModel<String> resultDescription = new HighlightingModel(new
PropertyModel(someObject, "someProperty"), new PropertyModel(searchQuery,
"searchTerm"));
--
Jeremy Thomerson
http://www.wickettraining.com
On Wed, Oct 15, 2008 at 12:07 PM, Thomas Singer <[EMAIL PROTECTED]> wrote:
> Thanks. But how the filter should know about the request which contains the
> information about what to highlight?
>
> --
> Cheers,
> Tom
>
>
>
> Igor Vaynberg wrote:
>
>> iresponsefilter
>>
>> -igor
>>
>> On Wed, Oct 15, 2008 at 8:22 AM, Thomas Singer <[EMAIL PROTECTED]> wrote:
>>
>> OK, this looks trivial, but were should I place this code to replace all
>>> content, no matter whether it comes from a page template, border or
>>> fragment?
>>>
>>> --
>>> Cheers,
>>> Tom
>>>
>>>
>>>
>>> Martijn Dashorst wrote:
>>>
>>> tekst.replaceAll(searchword, "<span class="search">" + searchword +
>>>> "</span>");
>>>>
>>>> label.setEscapeModelStrings(false);
>>>>
>>>> Martijn
>>>>
>>>> On Wed, Oct 15, 2008 at 3:56 PM, Thomas Singer <[EMAIL PROTECTED]>
>>>> wrote:
>>>>
>>>> We are using Wicket as base for our website (www.syntevo.com). We have
>>>>> a
>>>>> simple search feature on the website, but want to extend it like it is
>>>>> known
>>>>> to work in forums: the searched words should be highlighted.
>>>>>
>>>>> Does someone already has implemented such a feature to surround plain
>>>>> words
>>>>> in the markup by a special tag?
>>>>>
>>>>> --
>>>>> Cheers,
>>>>> Tom
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
>>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>