JSF2 component throws PropertyNotFoundException property for action

I have a component component:

<composite:interface> <composite:attribute name="actionMethod" method-signature="java.lang.String action()" required="true" /> </composite:interface> <composite:implementation> <h:form> <h:commandButton id="captureButton" value="#{msgs.capture}" action="#{cc.attrs.actionMethod}" /> </h:form> </composite:implementation> 

and the page that invokes this composite component:

 <ezcomp:captureTitle actionMethod="#{saveDecisionsBean.captureTitle}" /> 

and a bean that contains the action:

 @Named(value="saveDecisionsBean") @SessionScoped public class SaveDecisionsBean extends BackingBeanBase { ... public String captureTitle() { ... } } 

Now here is my problem. When I try to run this, it says that SaveDecisionsBean does not have a captureTitle property. Therefore, I have to add the SaveDecisionsBean#getCaptureTitle() method. When I do this, everything works fine. Why should I define this method? <composite:attribute /> says it is a method, and it was used as an action.

Here is the exact error message I get:

 javax.el.PropertyNotFoundException: /index.xhtml @54,86 actionMethod="#{saveDecisionsBean.captureTitle}": The class 'com.example.persistence.SaveDecisionsBean_$$_javassist_209' does not have the property 'captureTitle'. 

(For SEO reasons: in other implementations, the class name WeldClientProxy may be displayed.)

+4
source share
2 answers

I had the same problem and found out that this is because my action method actually threw IllegalArgumentException. In the meantime, this was reported as an error: The composite action method throws a PropertyNotFoundException when the method throws any exception .

The hard part (at least for me) was that my application worked fine until I moved part of the code to a composite component (CC). Before my application caught the IAE and displayed a good error message, but when using CC, a JSF check (or something else ...) will catch this first and create this rather confusing error message.

I checked this using a modified version of the test code provided by BalusC (see below). The test page shows two components of the enter and submit buttons. If you enter something into the text field (except for "panic" (without quotes)), both the CC version and the "built-in" version work (see the output of std). If you introduce a “panic” into the “embedded” version, you will see the IAE as expected, but if you introduce the same thing into the upper “CC version”, you will see a PropertyNotFoundException instead. It seems that the JSF is confused by the IAE and decides that the attribute should be a property, not an action method ... Not sure if this is an error or function. This is according to Spec, does anyone know?

So, the conclusion here is that you cannot use action methods in CC with beans that throw exceptions. For me, this means that I cannot use composite components. Sad

Hope this helps ...

 /resources/components/test.xhtml <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:cc="http://java.sun.com/jsf/composite"> <cc:interface> <cc:attribute name="text"/> <cc:attribute name="action" method-signature="java.lang.String action()" required="true" /> </cc:interface> <cc:implementation> <h:form> <h:inputText value="#{cc.attrs.text}"/> <h:commandButton value="submit" action="#{cc.attrs.action}" /> </h:form> </cc:implementation> 

 /test.xhtml <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:cc="http://java.sun.com/jsf/composite/components"> <h:head> <title>Test</title> </h:head> <h:body> <!-- text and cmd-button as cc --> <cc:test text="#{bean.text}" action="#{bean.submit}" /> <hr/> <!-- text and cmd-buuton inline --> <h:form id="inline"> <h:inputText value="#{bean.text}"/> <h:commandButton value="submit2" action="#{bean.submit}" /> </h:form> </h:body> </html> 

And the last Bean:

 @ManagedBean @RequestScoped public class Bean { private String text; public String getText() { return text; } public void setText(String text) { this.text = text; } public String submit() { if (text.equalsIgnoreCase("panic")){ throw new IllegalArgumentException("Panic!"); } System.out.println(text); return null; } } 
+9
source

Odd, I can't reproduce this using Mojarra 2.0.2. Maybe there is something else in the code that comes across this or that? Or are you not using code that you think works?

For completeness, I will include test fragments that I used to try to reproduce this problem:

/resources/components/test.xhtml

 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:cc="http://java.sun.com/jsf/composite"> <cc:interface> <cc:attribute name="action" method-signature="java.lang.String action()" required="true" /> </cc:interface> <cc:implementation> <h:form> <h:commandButton value="submit" action="#{cc.attrs.action}" /> </h:form> </cc:implementation> </html> 

/test.xhtml

 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:cc="http://java.sun.com/jsf/composite/components"> <h:head> <title>Test</title> </h:head> <h:body> <cc:test action="#{bean.submit}" /> </h:body> </html> 

com.example.Bean

 package com.example; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; @ManagedBean @RequestScoped public class Bean { public String submit() { System.out.println("submit"); return null; } } 

Does this fit the above for you?

+1
source

Source: https://habr.com/ru/post/900326/


All Articles