Exceptions in actionMethods are packed inside PropertyNotFoundException - jsf

We are currently using the OmniFaces FullAjaxExceptionHandlerFactory to redirect any exceptions in the application to a general error page. This page then examines the exception and determines its type so that we can display a particular (and hopefully more helpful) message for certain known error cases.
However, under certain circumstances all we get is a PropertyNotFoundException with no attached causes or details instead of the actual exception that the program throws. This thwarts my attempt to recognize known error cases.
I figured out the circumstances under which this happens: I wrote a composite component that encapsulates an h:commandLink. To pass in the action method I used retargeting like so:
<cc:attribute name="action" targets="link" required="true" />
and, accordingly,
<h:commandLink id="link" value="test" />
This works fine, but as said above: If the action stumbles upon an exception during execution, this original exception will not be handed to the error page. Only a PropertyNotFoundException shows up and tells me, the action method could not be found - without any info about the actual problem.
I tried to pass in the method in a different way, for example as
<cc:attribute name="bean" required="true" />
<cc:attribute name="method" required="true" />
<cc:attribute name="param" />
and
<h:commandLink id="link"
value="test"
action="#{cc.attrs.bean[cc.attrs.method](cc.attrs.param)}" />
In this case I get the right exceptions handed over, but the method fails for cases where the using page does not pass a param. A method like doSomething() will then not be found (IllegalArgumentException). However, I'd rather like to use one component throughout the application with or without parameters instead of forcing some workaround here for the different usages.
Are there other ways to avoid the retargeting approach or can we change something, so that a retargeted method does not result in the unhelpful PropertyNotFoundExecption?
EDIT: If possible, I'd prefer the retargeting, as it's less of an limitation to the use of the component. The above alternative for example would only allow for actions with one parameter. :/

As per comments, this is a known Mojarra issue. We upgraded to Mojarra 2.1.21 and I can confirm that the issue is fixed in this version and exceptions end up in the interface pure and unaltered as the code intended ;)
Thanks for the help!

Related

Alternative c:if in JSF

Does someone know a alternative to <c:if> for view render time, or even if that is possible. For what I have search until now it doesn't exist, or the alternative would be using the rendered attribute, but for me doesn't really work.
<af:listView value="#{bindings.date.collectionModel}" var="item" id="lv1">
<af:listItem id="li2">
<af:iterator id="i1" value="#{bindings.list.collectionModel}" var="row">
<c:if test="#{item.bindings.attrid.inputValue eq row.attrid}">
<ui:param name="varUI" value="true" />
<c:set var="varC" value="true" />
</c:if>
</af:iterator>
<af:outputText value="#{varUI}" id="otqaswq"/>
<!--<af:outputText value="#{varC}" id="otqawq"/>-->
<af:selectBooleanCheckbox text="Activated" id="sbc2" value="#{varUI}"/>
</af:listItem>
</af:listView>
So in the code above I know that c: they run in different time, view build time and not on the render time.
What I needed was that the af:selectBooleanCheckbox would appear true or false depending if there are values with the same value.
My question is, someone know a alternative way of doing this?
rendered should 100% work, your expression may be incorrect.
Switching to another alternative where you will use exactly the same expression will lead you in the very same place.
You cannot use an <af:iterator> to conditionally set a value using <ui:param> or <c:set>, because they are both tag handlers which are evaluated before <af:iterator>. You might use <c:forEach> instead, but that requires some collection to iterate over. A javax.faces.model.DataModel like #{bindings.list.collectionModel} will most likely not work.
But to be honest, you should implement some Java method which will give you the desired value (true or false) instead of trying to implement this logic in terms of JSF tags.

jsf methods expression valuechanged event don't work or work different in inputtext and selectOneMenu

i'm new with jsf technology and use of managed bean.
I'm reading the Java Platform, Enterprise Edition The Java EE Tutorial release 7 but it seems to be not clear, i have different problem how in example below :
<h:selectOneMenu value="#{user.age}" onchange="submit()" valueChangeListener="#{user.ageChanged}">
<f:selectItems value="#{user.ages}" />
<f:converter converterId="javax.faces.Integer"/>
</h:selectOneMenu>
<h:inputText id="name" value="#{user.name}" required="true" validator="#{user.validateName}" valueChangeListener="#{user.nameChanged}" onchange ="submit()" />
the first one do the job, but the second not it displays:
'managedBean.User' does not have the property nameChanged.
but ageChanged is not a property but the first example do the job
but i'm using method expression to refers method nameChanged that it's present on the bean user,
i'm confusing, too with use or not of the bracket on methods expression:
valueChangeListener="#{user.nameChanged}" or valueChangeListener="#{user.nameChanged()}" what is the properly way to use methods expression?
i say this cause in another example having method with no parameters, the two approaches had different behave, first the same error about property missing, the second Apparently worked.
any help? a speak about method expressions it's appreciated to. thank you.

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.

Resources