0

I want to use one h:inputText to call search methods in multiple beans. User is asked to type a place name in the h:inputText, place is a variable in all beans, each searchMethod then finds records with place criteria.
Questions are first: How do I call multiple beans methods for one h:inputText and without a h:commandButton? Second: How do I redirect to a search page with all results grouped by bean names after pressing Enter by user?

I found this SO question regarding using h:inputText without h:commandButton but how do I call multiple beans and how do I redirect to search_results.xhtml page.

I'm using jsf 2.2

Update
I wrote bellow code but I don't know how to set render attribute so that it redirects to search.xhtml page. I've set it to place which is the id of input text and it just reloads the page.

<h:inputText id="place" value="#{bean.place}"
     onkeypress="if(event.keyCode === 13){onchange(event); return false;}"
     onchange="return event.keyCode !== undefined">
     <f:param name="place" value="#{bean.place}"/>                                            
    <f:ajax listener="#{bean.goToSearch}" render="place"/>
</h:inputText>  

goToSearch():

public String goToSearch(AjaxBehaviorEvent event){                
    return "Search.xhtml?faces-redirect=true&amp;includeViewParams=true";
}
5
  • 2
    It makes no sense to do it in multiple beans. It's just against JSF working methodology. Just use an action method in a @ViewScoped managed bean and invoke as many controllers as you want from there.
    – Aritz
    Feb 18, 2014 at 14:10
  • Thanks @XtremeBiker It's a good idea. How about redirecting to another page? Feb 18, 2014 at 14:21
  • 2
    Just return "search_results?faces-redirect=true" in your action method once you've finished your server side job.
    – Aritz
    Feb 18, 2014 at 14:23
  • @XtremeBiker Thanks for your comment. I added some workaround to my question. I still didn't manage it to work. Feb 18, 2014 at 22:30
  • I used FacesContext.getCurrentInstance().getExternalContext().redirect"Search.xhtml?faces-redirect=true&amp;includeViewParams=true" and it worked. Feb 19, 2014 at 2:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.