Previous | Next
WireHose Developers Guide

Customizing the search box on specific pages

Since the main page and the tag driller page in Hello World already allow users to browse through available resources, the "Or click here to browse..." link is redundant on those pages. WHSearchBox lets you control whether this link is shown via its showBrowsePrompt binding.

Ordinarily you'd set the showBrowsePrompt to false if you were to embed the search box directly into the main page and tag driller page. But in this case, the search box is embedded into the wrapper, and Hello World doesn't even have its own tag driller page component anyway.

Another technique might be to add a method to Wrapper.java which returns true or false depending on the current page. This method might look like this:

public boolean showBrowsePrompt() {
    return (context().page() instanceof MainPage ||
        context().page() instanceof WHTagDrillerPage);
}

or this:

public boolean showBrowsePrompt() {
    return ("WHMainPage".equals(helper().currentPage()) || 
        "WHTagDrillerPage".equals(helper().currentPage());
}

However, this approach can be cumbersome to maintain. WireHose provides an alternative approach, which has the advantage of not requiring custom code: resolving the binding through the layout dictionary.

This entry in the layout dictionary sets WHSearchBox's showBrowsePrompt to true in all areas on all pages in all layouts by default:

defaults = {
   ...
    WHSearchBox = {
        showBrowsePrompt = YES;
       ...

 You'll modify the layout dictionary so showBrowsePrompt resolves to false on the main page and the tag driller page.

  1. First, set it for the main page. Find this entry in the layout dictionary:
    WHMainPage = {
        pageName = MainPage;
       ... 

    Change it so it reads:

    WHMainPage = {
        pageName = MainPage;
        WHSearchBox = { 
            showBrowsePrompt = NO; 
        }; 
       ...
  2. Next, set it on the tag driller page. Find this entry in the layout dictionary:
    WHTagDrillerPage = {
        pageName = WHTagDrillerPage;
       ... 

    Change it so it reads:

    WHTagDrillerPage = {
        pageName = WHTagDrillerPage;
        WHSearchBox = { 
            showBrowsePrompt = NO; 
        }; 
       ...
  3. Reload the page in your browser.

How this works: WHSearchBox includes a WOConditional to determine whether to show the browse prompt. The conditional's condition is bound to showBrowsePrompt. WHSearchBox.java defines this method:

public boolean showBrowsePrompt() {
    return booleanForBinding("showBrowsePrompt");
}

If WHSearchBox's showBrowsePrompt binding is bound directly to true or false, WHComponent's booleanForBinding method will return that value. But if the binding is left unbound, booleanForBinding will resolve the value via the layout dictionary.

You can use this technique in your own components. And if you're resolving simple string bindings, you don't even have to implement a method in your code -- WHComponent will resolve the value via the layout dictionary automatically. See the reference documentation for WHComponent for details.


Previous | Next