Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Problem with f:ajax listener sometimes not called in a portlet Benjamin Cassan June 26, 2013 8:24 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Neil Griffin June 10, 2013 10:17 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Benjamin Cassan June 11, 2013 1:03 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Juan Gonzalez June 11, 2013 1:43 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Benjamin Cassan June 11, 2013 2:04 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Juan Gonzalez June 11, 2013 2:18 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Neil Griffin June 11, 2013 3:44 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Benjamin Cassan June 11, 2013 5:11 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Benjamin Cassan June 11, 2013 5:42 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Neil Griffin June 11, 2013 8:44 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Benjamin Cassan June 12, 2013 12:21 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Neil Griffin June 11, 2013 9:40 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Vernon Singleton June 11, 2013 3:32 PM
RE: Problem with f:ajax listener sometimes not called in a portlet Benjamin Cassan June 12, 2013 12:24 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Benjamin Cassan June 13, 2013 2:44 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Neil Griffin June 13, 2013 4:08 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Benjamin Cassan June 13, 2013 5:26 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Neil Griffin June 13, 2013 5:30 AM
RE: Problem with f:ajax listener sometimes not called in a portlet Juan Gonzalez June 13, 2013 4:10 AM
Benjamin Cassan
Problem with f:ajax listener sometimes not called in a portlet
June 26, 2013 8:24 AM
Answer

Benjamin Cassan

Rank: New Member

Posts: 15

Join Date: January 2, 2013

Recent Posts

I have a jsf page with a link for calling a search with Ajax. The link is automatically clicked with javascript. The form is in several instances of a JSF 2 portlet in liferay. Usually, everything works fine, but sometimes, the listener is not called.

In the portlet:
1<h:form id="result">
2...
3  <h:commandLink id="launch">
4    <f:ajax event="click" render="errors content debug" listener="#{resultBackingBean.doSearch}" />
5  </h:commandLink>
6...
7</h:form>


When it works, I have the following traces:

 112:55:10,476 DEBUG AFTER phaseId=[RESTORE_VIEW 1] viewId=[/views/search_result.xhtml]
 212:55:10,476 DEBUG BEFORE phaseId=[APPLY_REQUEST_VALUES 2] viewId=[/views/search_result.xhtml]
 312:55:10,476 DEBUG AFTER phaseId=[APPLY_REQUEST_VALUES 2] viewId=[/views/search_result.xhtml]
 412:55:10,476 DEBUG BEFORE phaseId=[PROCESS_VALIDATIONS 3] viewId=[/views/search_result.xhtml]
 512:55:10,476 DEBUG AFTER phaseId=[PROCESS_VALIDATIONS 3] viewId=[/views/search_result.xhtml]
 612:55:10,486 DEBUG BEFORE phaseId=[UPDATE_MODEL_VALUES 4] viewId=[/views/search_result.xhtml]
 712:55:10,486 DEBUG AFTER phaseId=[UPDATE_MODEL_VALUES 4] viewId=[/views/search_result.xhtml]
 812:55:10,486 DEBUG BEFORE phaseId=[INVOKE_APPLICATION 5] viewId=[/views/search_result.xhtml]
 912:55:10,486 DEBUG doSearch called
1012:55:10,486 DEBUG AFTER phaseId=[INVOKE_APPLICATION 5] viewId=[/views/search_result.xhtml]
1112:55:10,486 DEBUG BEFORE phaseId=[RENDER_RESPONSE 6] viewId=[/views/search_result.xhtml]
1212:55:10,496 DEBUG AFTER phaseId=[RENDER_RESPONSE 6] viewId=[/views/search_result.xhtml]


I can see my own debug trace doSearch called. But sometimes, after page reloading, I do not see my trace, the listener is never called. I always have the Detected Ajax ResourceRequest trace, but there is nothing between BEFORE INVOKE_APPLICATION and AFTER INVOKE_APPLICATION.

If I want the page to work again, I have to reload it. As if something wrong was sometimes occurring during some loading, as the behavior can change only after the page is reloaded.

I tried to change the scope of the bean with doSearch (from viewScope to sessionScope), I tried to set immediate="true" for the f:ajax, I tried to use a4j:ajax, but I still have the same behavior that I don't understand... Why? emoticon
Neil Griffin
RE: Problem with f:ajax listener sometimes not called in a portlet
June 10, 2013 10:17 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2349

Join Date: July 26, 2005

Recent Posts

When you get a chance, please enable the Developer Tools in Chrome (or FireBug in FireFox) and see if there are any JavaScript errors reported by the browser when the error is being reproduced. Since you don't see any output, I am wondering if the Ajax request is even getting submitted?
Benjamin Cassan
RE: Problem with f:ajax listener sometimes not called in a portlet
June 11, 2013 1:03 AM
Answer

Benjamin Cassan

Rank: New Member

Posts: 15

Join Date: January 2, 2013

Recent Posts

I always get a log trace "Detected Ajax ResourceRequest", before the beginning of the lifecycle, and with findbugs, I see the ajax request, with a response:
1<partial-response>
2  <changes>
3    <update id="javax.faces.ViewState">6791417547372597471:4319149946307207422</update>
4  </changes>
5</partial-response>


As I understand it, the ajax request is processed, but as my listener is not called, nothing is returned by the request. On a working request, the response has several updates for the items to render.
I have no javascript errors, not even warnings.
Juan Gonzalez
RE: Problem with f:ajax listener sometimes not called in a portlet
June 11, 2013 1:43 AM
Answer

Juan Gonzalez

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2848

Join Date: October 28, 2008

Recent Posts

Plase can can you send the complete .xhtml, managed beans and faces-config.xml?

Thanks.
Benjamin Cassan
RE: Problem with f:ajax listener sometimes not called in a portlet
June 11, 2013 2:04 AM
Answer

Benjamin Cassan

Rank: New Member

Posts: 15

Join Date: January 2, 2013

Recent Posts

Here it is.

xhtml:
  1<?xml version="1.0"?>
  2
  3<f:view
  4    xmlns="http://www.w3.org/1999/xhtml"
  5    xmlns:c="http://java.sun.com/jsp/jstl/core"
  6    xmlns:f="http://java.sun.com/jsf/core"
  7    xmlns:h="http://java.sun.com/jsf/html"
  8    xmlns:ui="http://java.sun.com/jsf/facelets"
  9>
 10    <h:head >
 11    </h:head>
 12    <h:body >
 13
 14        <h:form id="result">
 15            <h:panelGroup id="errors">
 16                <ui:repeat var="error" value="#{resultModelBean.errorsList}">
 17                    <ul class="error">
 18                        <li>
 19                            <h:outputText value="#{error}" />
 20                        </li>
 21                    </ul>
 22                </ui:repeat>
 23            </h:panelGroup>
 24   
 25            <h:commandLink id="launch" binding="#{resultBackingBean.launchSearch}">
 26                <f:ajax event="click" render="errors content debug" listener="#{resultBackingBean.doSearch}" />
 27            </h:commandLink>
 28   
 29            <h:panelGroup id="content">
 30                <h:panelGroup rendered="#{(resultModelBean.feed == null) and (!resultModelBean.searchDone)}"
 31                    layout="block"
 32                    style="padding: 1em;text-align: center;">
 33                    <h:graphicImage value="/images/ajax-loader.gif" width="32" height="32" longdesc="#{i18n['result-wait']}"/>
 34                </h:panelGroup>
 35   
 36   
 37                <h:panelGroup rendered="#{(resultModelBean.feed == null) and (resultModelBean.searchDone)}">
 38                    <h:outputLabel value="#{i18n['result-noValue']}" />
 39                </h:panelGroup>
 40   
 41                <h:panelGroup rendered="#{resultModelBean.feed != null}">
 42                    <h2>
 43                        <h:panelGroup rendered="#{(resultModelBean.feed.link != null) and (!resultModelBean.feed.link.isEmpty())}">
 44                            <h:outputLink target="_blank" value="#{resultModelBean.feed.link}">
 45                                <h:outputText value="#{resultModelBean.feed.title}" />
 46                            </h:outputLink>
 47                        </h:panelGroup>
 48                        <h:panelGroup rendered="#{(resultModelBean.feed.link == null) or (resultModelBean.feed.link.isEmpty())}">
 49                            <h:outputText value="#{resultModelBean.feed.title}" />
 50                        </h:panelGroup>
 51                    </h2>
 52       
 53                    <h:outputLabel value="#{resultModelBean.feed.description}" />
 54
 55                    <ui:repeat var="category" value="#{resultModelBean.entries.entrySet().toArray()}">
 56                        <h:panelGroup rendered="#{null != category.key}">
 57                            <ul>
 58                                <li><h:outputText value="#{category.key.name}" /></li>
 59                                    <ul>
 60                                        <ui:repeat var="entry" value="#{category.value}">
 61                                            <li>
 62                                                <!-- Display with link -->
 63                                                <h:panelGroup rendered="#{(entry.link != null) and (!entry.link.isEmpty())}">
 64                                                    <h:outputLink target="_blank" value="#{entry.link}">
 65                                                        <h:outputText value="#{entry.title}" />
 66                                                    </h:outputLink>
 67                                                </h:panelGroup>
 68                                                <!-- Display without link -->
 69                                                <h:panelGroup rendered="#{(entry.link == null) || (entry.link.isEmpty())}">
 70                                                    <h:outputText value="#{entry.title}" />
 71                                                </h:panelGroup>
 72                                            </li>
 73                                        </ui:repeat>
 74                                    </ul>
 75                            </ul>
 76                        </h:panelGroup>
 77                        <h:panelGroup rendered="#{null == category.key}">
 78                            <ui:repeat var="entry" value="#{category.value}">
 79                                <ul>
 80                                    <li>
 81                                        <!-- Display with link -->
 82                                        <h:panelGroup rendered="#{(entry.link != null) and (!entry.link.isEmpty())}">
 83                                            <h:outputLink target="_blank" value="#{entry.link}">
 84                                                <h:outputText value="#{entry.title}" />
 85                                            </h:outputLink>
 86                                        </h:panelGroup>
 87                                        <!-- Display without link -->
 88                                        <h:panelGroup rendered="#{(entry.link == null) || (entry.link.isEmpty())}">
 89                                            <h:outputText value="#{entry.title}" />
 90                                        </h:panelGroup>
 91                                    </li>
 92                                </ul>
 93                            </ui:repeat>
 94                        </h:panelGroup>
 95                    </ui:repeat>
 96                </h:panelGroup>
 97            </h:panelGroup>
 98   
 99            <h:panelGroup id="debug">
100                <h:panelGroup rendered="#{resultModelBean.debugRendered}"
101                    style="color: #CCCCCC; font-size: x-small;" layout="block">
102                    <h:outputFormat value="Namespace: {0} {1}">
103                        <f:param value="#{facesContext.externalContext.encodeNamespace(':result:launch')}" />
104                        <f:param value="#{resultBackingBean.launchSearch.clientId}" />
105                    </h:outputFormat><br />
106                    <h:outputFormat value="Product: {0}">
107                        <f:param value="#{searchDataModelBean.searchCriteria.product}" />
108                    </h:outputFormat>
109                    <br />
110                    <h:outputFormat value="Search: {0}">
111                        <f:param value="#{searchDataModelBean.searchCriteria.wordSearch}" />
112                    </h:outputFormat>
113                    <br />
114                    <h:outputFormat value="URL: {0}">
115                        <f:param value="#{resultModelBean.url}" />
116                    </h:outputFormat>
117                    <br />
118                    <br />
119                    <h:outputText value="#{resultModelBean.feed}" />
120                </h:panelGroup>
121            </h:panelGroup>
122        </h:form>
123
124        <script>
125            <!-- Automatic launch of the search -->
126            document.getElementById('#{resultBackingBean.launchSearch.clientId}').click();
127        </script>
128    </h:body>
129</f:view>


Managed bean that has the listener function:
  1/**
  2 *
  3 */
  4package cg.portal.search.bean;
  5
  6import java.io.IOException;
  7import java.io.Serializable;
  8import java.net.MalformedURLException;
  9import java.net.URISyntaxException;
 10import java.util.ArrayList;
 11import java.util.Iterator;
 12import java.util.List;
 13
 14import javax.annotation.PostConstruct;
 15import javax.annotation.PreDestroy;
 16import javax.faces.bean.ManagedBean;
 17import javax.faces.bean.ManagedProperty;
 18import javax.faces.bean.ViewScoped;
 19import javax.faces.component.UIComponent;
 20import javax.faces.context.ExternalContext;
 21import javax.faces.context.FacesContext;
 22import javax.faces.event.AjaxBehaviorEvent;
 23import javax.faces.event.ComponentSystemEvent;
 24import javax.portlet.PortletPreferences;
 25import javax.portlet.PortletRequest;
 26
 27import org.apache.log4j.Logger;
 28
 29import com.sun.syndication.feed.synd.SyndCategory;
 30import com.sun.syndication.feed.synd.SyndEntry;
 31import com.sun.syndication.feed.synd.SyndFeed;
 32import com.sun.syndication.io.FeedException;
 33
 34import cg.common.exception.ApplicativeException;
 35import cg.portal.search.dto.LoginData;
 36import cg.portal.search.dto.SearchCriteria;
 37import cg.portal.search.dto.WebApplicationConfig;
 38import cg.portal.search.service.ISearchService;
 39
 40/**
 41 * Class used to call the search and retrieve the result.
 42 *
 43 */
 44@ManagedBean(name = "resultBackingBean")
 45@ViewScoped
 46public class ResultBackingBean implements Serializable {
 47
 48    /**
 49     * ID
 50     */
 51    private static final long serialVersionUID = -350181546053439898L;
 52
 53    private static final Logger LOG = Logger.getLogger(ResultBackingBean.class);
 54
 55    // Injections
 56    @ManagedProperty(name = "searchDataModelBean", value = "#{searchDataModelBean}")
 57    private SearchDataModelBean searchDataModelBean;
 58
 59    // Injections
 60    @ManagedProperty(name = "resultModelBean", value = "#{resultModelBean}")
 61    private ResultModelBean resultModelBean;
 62
 63    // Injections
 64    @ManagedProperty(name = "webApplicationModelBean", value = "#{webApplicationModelBean}")
 65    private WebApplicationModelBean webApplicationModelBean;
 66
 67    // Injections
 68    @ManagedProperty(name = "searchService", value = "#{searchService}")
 69    private ISearchService searchService;
 70
 71    /** the link to activate.
 72     */
 73    private UIComponent launchSearch;
 74
 75    public void doSearch(AjaxBehaviorEvent event) {
 76        LOG.debug("doSearch called");
 77    }
 78
 79    @PostConstruct
 80    public void postConstruct() {
 81        LOG.trace("@PostConstruct annotation worked");
 82    }
 83
 84    @PreDestroy
 85    public void preDestroy() {
 86        LOG.trace("@PreDestroy annotation worked");
 87    }
 88
 89    /**
 90     * Setter for injecting the model bean
 91     *
 92     * @param searchModelBean
 93     */
 94    public void setSearchDataModelBean(SearchDataModelBean searchDataModelBean) {
 95
 96        // Injected via ManagedProperty annotation
 97        this.searchDataModelBean = searchDataModelBean;
 98    }
 99
100    /**
101     * Setter for injecting the model bean
102     *
103     * @param ResultModelBean
104     */
105    public void setResultModelBean(ResultModelBean resultModelBean) {
106
107        // Injected via ManagedProperty annotation
108        this.resultModelBean = resultModelBean;
109    }
110
111    /**
112     * Setter for injecting the web application bean
113     *
114     * @param webApplicationBean
115     */
116    public void setWebApplicationModelBean(WebApplicationModelBean webApplicationModelBean) {
117
118        // Injected via ManagedProperty annotation
119        this.webApplicationModelBean = webApplicationModelBean;
120    }
121
122    /**
123     * Setter for injecting the service
124     *
125     * @param searchService
126     */
127    public void setSearchService(ISearchService searchService) {
128
129        // Injected via ManagedProperty annotation
130        this.searchService = searchService;
131    }
132
133    /**
134     * @return the launchSearch
135     */
136    public UIComponent getLaunchSearch() {
137        return launchSearch;
138    }
139
140    /**
141     * @param launchSearch the launchSearch to set
142     */
143    public void setLaunchSearch(UIComponent launchSearch) {
144        this.launchSearch = launchSearch;
145    }
146}


faces-config.xml:
 1<?xml version="1.0"?>
 2
 3<faces-config
 4    version="2.0"
 5    xmlns="http://java.sun.com/xml/ns/javaee"
 6    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 7    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
 8>
 9    <navigation-rule>
10        <navigation-case>
11            <from-outcome>ipc.searchLaunched</from-outcome>
12            <to-view-id>/views/search_result.xhtml</to-view-id>
13        </navigation-case>
14    </navigation-rule>
15    <lifecycle>
16        <phase-listener>com.liferay.faces.util.lifecycle.DebugPhaseListener</phase-listener>
17    </lifecycle>
18</faces-config>
Juan Gonzalez
RE: Problem with f:ajax listener sometimes not called in a portlet
June 11, 2013 2:18 AM
Answer

Juan Gonzalez

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2848

Join Date: October 28, 2008

Recent Posts

Hi Benjamin,

Guess you're hitting this issue:

http://java.net/jira/browse/JAVASERVERFACES-1492

by your #{resultBackingBean.launchSearch} binding value. I wouldn't recommend to use binding, if it can be avoided.

To solve it you have these options:

* Change your managed bean to be @RequestScope (and solve all problems that could arise).
* Change javax.faces.PARTIAL_STATE_SAVING to false
* Get the JSF 2.2 jars and overwrite previous ones from your portlet. Don't know if this have been solved in 2.1.x. If you're using JSF 2.2 remember to use the proper Liferay Faces version as you can read here http://www.liferay.com/community/wiki/-/wiki/Main/Liferay+Faces+Version+Scheme
Neil Griffin
RE: Problem with f:ajax listener sometimes not called in a portlet
June 11, 2013 3:44 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2349

Join Date: July 26, 2005

Recent Posts

I agree with Juan. If possible, avoid the binding attribute, backing beans should be @RequestScoped, and @ViewScoped should be limited to model beans. If the backing bean needs to access model data, then model beans can be injected into the backing bean with @ManagedProperty (JSF) or with @Inject (CDI).

We haven't released a version of Liferay Faces that is compatible with JSF 2.2 yet, so upgrading to JSF 2.2 isn't an option at this time.
Benjamin Cassan
RE: Problem with f:ajax listener sometimes not called in a portlet
June 11, 2013 5:11 AM
Answer

Benjamin Cassan

Rank: New Member

Posts: 15

Join Date: January 2, 2013

Recent Posts

I changed to request scope, but the problem is still there. It was request scope before, and I changed it due to the binding, mostly for accessing the ID with javascript.

I'm not sure for this issue. According to the description, the effect of the bug is to lose the binding value. I use the binding only to retrieve the ID of the link for the javascript side, for clicking the link. The fact is that I don't have problem with that, it works all the time, the link is activated, and the ajax is activated. So it seems that I don't lose the binding.

I will try to find another solution for the binding, even if it does not seem to this issue. Maybe there are other side effects.
Benjamin Cassan
RE: Problem with f:ajax listener sometimes not called in a portlet
June 11, 2013 5:42 AM
Answer

Benjamin Cassan

Rank: New Member

Posts: 15

Join Date: January 2, 2013

Recent Posts

I also tried to put the function in a session scope managed bean, with the same behavior: the click was ok, ajax was processed, but sometimes my function is not called.
Neil Griffin
RE: Problem with f:ajax listener sometimes not called in a portlet
June 11, 2013 8:44 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2349

Join Date: July 26, 2005

Recent Posts

I see that you have the DebugPhaseListener registered in faces-config.xml which is good. Do you have the level set to debug in your log4j.properties file? If yes, then what phases of the JSF lifecycle execute when you click the button when it works, and when it does not work?
Benjamin Cassan
RE: Problem with f:ajax listener sometimes not called in a portlet
June 12, 2013 12:21 AM
Answer

Benjamin Cassan

Rank: New Member

Posts: 15

Join Date: January 2, 2013

Recent Posts

The level is set to DEBUG. Maybe my post was not clear enough, I see the same phases in both situation:

When working, I can see my own debug trace set in the listener method:
 1DEBUG AFTER phaseId=[RESTORE_VIEW 1] viewId=[/views/search_result.xhtml]
 2DEBUG BEFORE phaseId=[APPLY_REQUEST_VALUES 2] viewId=[/views/search_result.xhtml]
 3DEBUG AFTER phaseId=[APPLY_REQUEST_VALUES 2] viewId=[/views/search_result.xhtml]
 4DEBUG BEFORE phaseId=[PROCESS_VALIDATIONS 3] viewId=[/views/search_result.xhtml]
 5DEBUG AFTER phaseId=[PROCESS_VALIDATIONS 3] viewId=[/views/search_result.xhtml]
 6DEBUG BEFORE phaseId=[UPDATE_MODEL_VALUES 4] viewId=[/views/search_result.xhtml]
 7DEBUG AFTER phaseId=[UPDATE_MODEL_VALUES 4] viewId=[/views/search_result.xhtml]
 8DEBUG BEFORE phaseId=[INVOKE_APPLICATION 5] viewId=[/views/search_result.xhtml]
 9DEBUG doSearch called
10DEBUG AFTER phaseId=[INVOKE_APPLICATION 5] viewId=[/views/search_result.xhtml]
11DEBUG BEFORE phaseId=[RENDER_RESPONSE 6] viewId=[/views/search_result.xhtml]
12DEBUG AFTER phaseId=[RENDER_RESPONSE 6] viewId=[/views/search_result.xhtml]


When not working, I have the same phases, but without my log (and without any processing that could be in the method):
 1DEBUG AFTER phaseId=[RESTORE_VIEW 1] viewId=[/views/search_result.xhtml]
 2DEBUG BEFORE phaseId=[APPLY_REQUEST_VALUES 2] viewId=[/views/search_result.xhtml]
 3DEBUG AFTER phaseId=[APPLY_REQUEST_VALUES 2] viewId=[/views/search_result.xhtml]
 4DEBUG BEFORE phaseId=[PROCESS_VALIDATIONS 3] viewId=[/views/search_result.xhtml]
 5DEBUG AFTER phaseId=[PROCESS_VALIDATIONS 3] viewId=[/views/search_result.xhtml]
 6DEBUG BEFORE phaseId=[UPDATE_MODEL_VALUES 4] viewId=[/views/search_result.xhtml]
 7DEBUG AFTER phaseId=[UPDATE_MODEL_VALUES 4] viewId=[/views/search_result.xhtml]
 8DEBUG BEFORE phaseId=[INVOKE_APPLICATION 5] viewId=[/views/search_result.xhtml]
 9DEBUG AFTER phaseId=[INVOKE_APPLICATION 5] viewId=[/views/search_result.xhtml]
10DEBUG BEFORE phaseId=[RENDER_RESPONSE 6] viewId=[/views/search_result.xhtml]
11DEBUG AFTER phaseId=[RENDER_RESPONSE 6] viewId=[/views/search_result.xhtml]


Except the fact that the method is not called, I see no difference in logs, so I really don't have a clue, no error or warning, or trace that could indicate why the behavior is different sometimes.
Neil Griffin
RE: Problem with f:ajax listener sometimes not called in a portlet
June 11, 2013 9:40 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2349

Join Date: July 26, 2005

Recent Posts

When you get a chance, please try your test as a plain webapp outside of Liferay Portal. If it works as a webapp, but not as a portlet then that might indicate that we have a bug in the bridge.
Vernon Singleton
RE: Problem with f:ajax listener sometimes not called in a portlet
June 11, 2013 3:32 PM
Answer

Vernon Singleton

LIFERAY STAFF

Rank: Expert

Posts: 278

Join Date: January 14, 2013

Recent Posts

Hi Benjamin,

I notice that you keep saying that _sometimes_ it does not work. Could your issue be session related? Could it be that it does not work after _say_ 30 minutes when your session times out? But then it works again when you have a new session? How would you measure the intermittent nature of this bug?

Other than those questions, I agree with Neil and Juan, please test your webapp outside of the liferay portal, to help us determine if the bug is related to the bridge.
Benjamin Cassan
RE: Problem with f:ajax listener sometimes not called in a portlet
June 12, 2013 12:24 AM
Answer

Benjamin Cassan

Rank: New Member

Posts: 15

Join Date: January 2, 2013

Recent Posts

No, the "sometimes" is not time dependent or session related. It can happen very quickly after logging in, and when it is not working, refreshing the page can make it work again. And the page with ajax is loaded only after verification of some data in session.
Benjamin Cassan
RE: Problem with f:ajax listener sometimes not called in a portlet
June 13, 2013 2:44 AM
Answer

Benjamin Cassan

Rank: New Member

Posts: 15

Join Date: January 2, 2013

Recent Posts

I followed your advice, to avoid using bindings. I removed it, using another way for getting the client ID of the link (looking all the UIComponents until I find the good one, not very nice comparing to bindings, but it works). And for the moment, I cannot reproduce the issue. Maybe it is the bug you were talking about, or something else that could be broken by the binding.

So I don't know if it is this bug, but thank for the advice to avoid bindings emoticon
Neil Griffin
RE: Problem with f:ajax listener sometimes not called in a portlet
June 13, 2013 4:08 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2349

Join Date: July 26, 2005

Recent Posts

Glad to hear that it is working. Juan's advice about avoiding the binding attribute is very good. The [url=https://javaserverfaces.java.net/nonav/docs/2.1/javadocs/javax/faces/component/UIComponent.html#findComponent(java.lang.String)]UIComponent.findComponent(String) method is an efficient way to get the reference to a component in the tree, so that you don't have to search the tree yourself. There is an example of how to do this at line 150 of ApplicantBackingBean.postalCodeListener(ValueChangeEvent) in the icefaces3-compat-portlet. If you want to search the tree from the top, then you can call [url=http://docs.oracle.com/javaee/6/api/javax/faces/context/FacesContext.html#getViewRoot()]FacesContext.getViewRoot() and then call uiViewRoot.findComponent(String).
Juan Gonzalez
RE: Problem with f:ajax listener sometimes not called in a portlet
June 13, 2013 4:10 AM
Answer

Juan Gonzalez

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2848

Join Date: October 28, 2008

Recent Posts

Great it worked.

Probably that binding clientId get lost during GET or after postback (that's why you said it worked sometimes). So probably is the same issue we were talking about.

Yep, bindings need to be used with care. I don't like it at all, and I didn't find any case which I really need it (and don't have any other alternative). I prefer more "stateless" apps, and binding doesn't help much. But that's another story.. emoticon
Benjamin Cassan
RE: Problem with f:ajax listener sometimes not called in a portlet
June 13, 2013 5:26 AM
Answer

Benjamin Cassan

Rank: New Member

Posts: 15

Join Date: January 2, 2013

Recent Posts

Thanks a lot, this is a better solution than the one I found (that was implementing a recursive search from the UIViewRoot). It is better to use the existing findComponent emoticon

From an external point of view, it seemed cleaner to bind to the component than searching in the tree, this is why I choose the binding. Now I know it is better to avoid it ;)
Neil Griffin
RE: Problem with f:ajax listener sometimes not called in a portlet
June 13, 2013 5:30 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2349

Join Date: July 26, 2005

Recent Posts

I agree with you -- the binding attribute is a nice dependency-injection type of mechanism, whereas findComponent is more of a dependency-pull. But historically there have been technical challenges with using the binding attribute in JSF applications, so I'm sad to say that it should be avoided.