Getting warning "getClientId should not be called while the view is being constructed." - jsf

In my JSF application I have one JSP page which keeps generating a warning which sometimes gets rendered. In the log files I can see something like this:
WARNING: getClientId should not be called while the view is being constructed.
Component-ID: j_id18
The component which generates the warning looks like this:
<tr:panelCaptionGroup captionText="Jobs">
<tr:poll pollListener="#{jobBean.update}" id="poll" interval="#{msg.cfg_pollingInterval}" />
<tr:table allDetailsEnabled="true" partialTriggers="::poll ::groupFilter">
<f:facet name="detailStamp" >
<tr:table var="trg" value="#{subbean}" >
...stuff...
</tr:table>
</f:facet>
<tr:column>
<h:panelGroup>
<tr:commandLink />
</h:panelGroup>
</tr:column>
<tr:column />
</tr:table>
Could it be an issue with polling in the table?
I'm using Trinidad 2.0.0.
I've tried the option org.apache.myfaces.trinidad.CLIENT_ID_CACHING in web.xml and I observe the behavior with all options ON, OFF and DEBUG.

As it seems, there was a NPE occurring somewhere while creating a dropdown in the screen.
The code has been fixed, and the warning doesn't appear any more.

My solution was to refresh any parent programatically in a backing bean prior to ending up in this state.
Note, it looks like this message was added to java/org/apache/myfaces/trinidad/component/UIXComponentBase.java in May 2010 at revision 942933 to prevent and NPE when clientId is null.

Related

JSF 2.3 on open liberty. Immediate javax.faces.application.ViewExpiredException

I am experimenting with Open Liberty and wanted to try out JSF-2.3 support. I must be doing something silly because when trying implicit navigation I immediately get the exception:
javax.faces.application.ViewExpiredException: View "/view/index.xhtml" could not be restored.
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:181)
I can render an initial Facelets-page using the following server.xml features:
<featureManager>
<feature>servlet-4.0</feature>
<feature>jsf-2.3</feature>
<feature>el-3.0</feature>
<feature>cdi-2.0</feature>
<feature>jsp-2.3</feature>
</featureManager>
My page is really simple and looks like this:
<h:body>
<h:outputText value="It works!"/>
<br/>
<h:form>
<h:commandLink value="NAvigate" action="view/page2" />
<h:commandButton value="NAvigate 2" action="view/page2" />
</h:form>
</h:body>
I have a corresponding page2.xhtml.
When clicking on either the commandLink or commandButton I get the exception:
javax.faces.application.ViewExpiredException: View "/view/index.xhtml" could not be restored.
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:181)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:195)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:142)
Have I mis-configured something in Open Liberty or are my JSF-mojo just lacking severely?
Ugh.. after testing in another browser (Safari) it worked. Hard-resetting Chrome site storage then fixed the original problem.
This problem must have surfaced somewhere in between automatic restarts.

f:convertNumber failing when currencySymbol is obtained from bean via EL

Hi in my project I need to visualize currency value, as far in my f:convertNumber
I use a fixed currencySymbol; everything is ok, but when I try to get the symbol with an expression language like this:
<h:outputText value="#{rowItem.value}">
<f:convertNumber currencySymbol="#{rowItem.getCurrencySymbol()}" groupingUsed="true" maxFractionDigits="2" type="currency" />
</h:outputText>
it is like the method getCurrencySymbol is not called, I am sure there is something I am missing.
That will happen if #{rowItem} is only available during view render time, such as when it's specified by <h:dataTable var="rowItem">, as the variable name itself already suggests. It can also happen if #{rowItem} gets changed between building the view and rendering the view, such as when it's coming from a dropdown component in the same form. The <f:convertNumber> is namely a taghandler, not an UI component. It gets executed during view build time, not during view render time. The desired #{rowItem} value is not per definition available during view build time.
This all is explained in JSTL in JSF2 Facelets... makes sense? In that answer, you can substitute "JSTL" with <f:convertNumber> as they both are taghandlers and thus have exactly the same lifecycle.
There's no solution in standard JSF API without creating a custom converter and changing the view or model. You can find possible solutions in this answer: How to set converter properties for each row/item of h:dataTable/ui:repeat?
The JSF utility library OmniFaces offers <o:converter> out the box for exactly this problem. Use it as follows:
<h:outputText value="#{rowItem.value}">
<o:converter converterId="javax.faces.Number" currencySymbol="#{rowItem.getCurrencySymbol()}" type="currency" />
</h:outputText>
(note that I omitted the other two properties as those are the default already when type="currency" is used)

JSF Combine ui:param with composite component

you have saved me many times ago with this forum, but now I am really stuck and don't now where to search any longer...
I always get the following error message (warning level, but method is also not executed correctly):
javax.el.PropertyNotFoundException: Target Unreachable, identifier 'editor' resolved to null: javax.faces.FacesException: #{cc.attrs.selectionListener}
I have isolated the problem to a few lines of code:
This is my main file:
<c:forEach items="#{myBean.getEditors()}" var="currentEditor" >
<ui:include src="#{currentEditor.getPanel()} >
<ui:param name="editor" value="#{currentEditor} />
</ui:include>
</c:forEach>
The bean.getEditors() (session scoped) just returns a list with one single entry at the moment. The 'editor' is a POJO with some simple attributes and two listener methods. The listener method does only write a log entry. (Should of course do more in future)
The file which is included looks like this:
<h:selectOneMenu value="#{editor.menuValue}>
<f:selectItem itemValue="Value 1" />
<f:selectItem itemValue="Value 2" />
<a4j:ajax event="change" listener="#{editor.menutListener()}" />
</h:selectOneMenu>
<myComponent:treeComponent id="tree" selectionListener="#{editor.treeListener()} />
The component I created consists of a richfaces tree and when clicking on a node the following method is called:
<a4j:jsFunction name="performSelection" action="#{cc.attrs.selectionListener} />
I am quite confident that the composition itself is ok because I use it also at different places. When I remove the action from the a4j:jsFunction it also works perfect.
For me it smells a bit like the bug JSF 1223
The workaround does not work for me - probably because I create the param in the forEach.
I had similar problems (ui:param + component) before, but was able to solve them with giving the full path as attribute instead of a parameter. But this does not work here because it is used in too many different places.
Please help, I cannot be the only one with this problem, but I simply do not find any other threads for this.
Edit:
Today with a fresh mind I came even closer to the problem. You can forget the whole include/ forEach stuff...
<myComponent:treeComponent id="tree" selectionListener="#{myBean.getSingleEditor().treeListener()} />
Does work, while
<ui:param name="editor" value="#{myBean.getSingleEditor()} />
<myComponent:treeComponent id="tree" selectionListener="#{editor.treeListener()} />
does not work.
Well the JAVA code is performed, but the error is written to the log and the render and oncomplete method of the jsFunction do not work.
I also tried to use "data" instead of "action" for testing. No error is written to log, but JAVA method is not even called.
After many days of try&error I found a solution that is working for me:
I splitted up the listener method to one parameter with the JAVA class and one parameter with the the method name (as simple String)
The action method now looks like:
<a4j:jsFunction name="performSelection" action="#{cc.attrs.listenerClass[cc.attrs.listenerMethodName]}" />
Not nice but working... Perhaps it helps someone - or anybody can explain more...
By the way, the following was not working for me:
<a4j:jsFunction name="performSelection" action="#{cc.attrs.listenerClass[staticMethodName]}" />
While this was ok...
<a4j:jsFunction name="performSelection" action="#{cc.attrs.listenerClass.staticMethodName()}" />
Don't know - perhaps my head is running agains the same wall again and again...

RichFaces a4j:poll not working

My code in RichFaces 3.3.3:
<a:region>
<h:form>
<a:poll id="feed" enabled="true" reRender="feedReader" interval="100"/>
</h:form>
</a:region>
<h:form>
<h:outputText value="#{feedReader2.title}" id="feedReader" />
</h:form>
This is close to the example here: http://www.mastertheboss.com/richfaces/using-ajax-with-jboss-richfaces
What it should do is poll the server which reads an rss feed and gives back the title.
However, this is not working. In Chrome developer tools I can't see any AJAX requests made to the server. Instead, I see an error Uncaught TypeError: Cannot read property action of null on framework.pack.js. The line in which the error occurs is:
this._actionUrl=(this._form.action)?this._form.action:this._form
I can only guess that this is releated to the <h:form> which doesn't have an action attribute. But I don't see why I need this here, as it is not included in all of the examples you can find.
Moreover, I do not want the <h:outputText> to query the bean on page load. My aim is to use AJAX to read the feed after the page is done rendering.
If this is an issue related to my RichFaces version, could someone please give me an example on how to do this in 3.3.3?
I found the issue. It was an error outside the above markup i've included. Had two <h:form> nested, which caused the second one to malfunction.

Primefaces editable dataTable and hibernate validator

I have an editable dataTable in PrimeFaces and am using the Hibernate Validator for bean validation. This works fine with a <p:inputText /> element. Now I want to have validation on a dataTable which is editable.
This is what is happening:
If I enter valid values, the page updates as expected
If I enter invalid values, when I click the little "save" check mark nothing happens - the cell remains editable, database write is not attempted, no error message is displayed.
There is an <h:messages /> tag on the page, so why doesn't an error message show up? The component appears to be aware there was a problem since the row remains in the editable state.
EDIT: I enabled logging and saw this:
21:20:43,874 FINE [javax.enterprise.resource.webcontainer.jsf.context] (http-localhost-127.0.0.1-8080-2) Adding Message[sourceId=demoTable:j_idt11:2:j_idt15,summary=Testing Hibernate Validator Error Message)
So it looks like the context is being correctly updated. It seems like I need to do something to trigger the message it render.
Use the belowfollowing statement in your jsf file and it should work:
<p:messages id="messages" showDetail="true" autoUpdate="true"
closable="true" showSummary="false"/>

Resources