rich:suggestionbox, ajax and pages.xml
romain.dev.easycity.com Dec 15, 2008 6:30 PMHi guys,
I'm using JBoss 4.2.3.GA and Seam 2.1.1.CR1.
I have a problem with rich:suggestionbox calling the init method of its page Session Bean everytime I type a new letter :(
Here is the configuration :
- pages.xml
<page view-id="/index.xhtml" action="#{indexManager.init}">
...
</page>
- index.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<rich:suggestionbox
id="#{suggestionBoxId}"
for="#{inputTextId}"
suggestionAction="#{globalServiceManager.autocompleteCtgDetails}"
var="suggestedCtg"
requestDelay="100"
ignoreDupResponses="true">
<h:column id="#{suggestionBoxId}-col-#{suggestedCtg.id}">
<h:outputText id="#{suggestionBoxId}-output-#{suggestedCtg.id}" value="#{fn:toLowerCase(suggestedCtg.name)}"/>
</h:column>
</rich:suggestionbox>
</ui:composition>- IndexManagerBean
@Stateful
@Scope(SESSION)
@Name("indexManager")
public class IndexManagerBean implements IndexManagerLocal, Serializable {
private boolean isAjaxCall = false;
public void init() {
System.out.println("> init...");
if (!isAjaxCall) {
System.out.println("> init !");
//
// Some code
//
}
}
/**
* WebRemote call. In the case of a AJAX call. Block init method rewrite.
*/
public void startAjaxCall() {
System.out.println("Start >");
isAjaxCall = true;
}
public void endAjaxCall() {
System.out.println("< End");
isAjaxCall = false;
}
}
I use the isAjaxCall flag to prevent multiple init() code when an ajax request is fired. This is very ugly but it's the only way I found to fix it so far.
It works with a4j but I didn't find a method like actionListener in richfaces :
<a4j:outputPanel id="resultLstCtrl">
<ui:include src="/include/pages/root/index/review-list-navigation-ajax.xhtml" />
</a4j:outputPanel>
<a4j:form>
<a4j:jsFunction name="refreshResultLstCtrl"
reRender="resultLstCtrl"
actionListener="#{indexManager.startAjaxCall}"
requestDelay="100"
ignoreDupResponses="true" oncomplete="index.refreshResultLstCtrlCallbackComplete();"/>
</a4j:form>
Is there a better way to fix this ?