javax.el.ELException: Could not find property actionMethod in class com.example.Bean - jsf

While deploying GAE + primefaces application, I got following error:
com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException: Error Rendering View[/CreateEmployee.xhtml]
javax.el.ELException: /CreateEmployee.xhtml: Could not find property saveEmployee in class com.fetchinglife.domain.data.dao.EmployeeRepositoryImpl
at com.sun.faces.facelets.compiler.AttributeInstruction.write(AttributeInstruction.java:94)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:302)
at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
Even saveEmployee is already in EmployeeRepositoryImpl class. How is this caused and how can I solve it? Are there any annotations which I have to put extra?

Let's rephrase the exception in a general format in order to better understand the cause:
javax.el.ELException: Could not find property doSomething in class com.example.Bean
This exception is literally trying to tell you that the Bean class doesn't have the following method:
public SomeObject getDoSomething() {
return someObject;
}
(where SomeObject is the type of the doSomething property)
There are several causes for this.
Action method expression is incorrectly interpreted as property value expression
Given the fact that the property name is in your case actually a combination of a verb and noun, a resonable cause is you incorrectly bound an action method to an attribute of some JSF component which actually takes a value expression, not a method expression. E.g. when you accidentally do
<h:commandButton value="#{bean.doSomething}">Save</h:commandButton>
or even
<h:button value="Save" outcome="#{bean.doSomething}" />
instead of
<h:commandButton value="Save" action="#{bean.doSomething}" />
The latter would then expect the following method, which you probably actually have:
public String doSomething() {
// ...
return "nextpage";
}
(which can also be declared to return void by the way)
Component is not resolved at all
Another probable cause is that the component is not interpreted as a real component at all, but as "plain text". In other words, when you remove the action attribute and then try to open the JSF page in browser, it'll now load fine, but you will see the whole component unparsed in the generated HTML output (which you can see via rightclick, View Source in browser).
This can have several causes:
The XML namespace of the component is wrong or missing. E.g. in case of PrimeFaces you accidentally used the old PrimeFaces 2.x URI while you're actually using PrimeFaces 3+.
<html ... xmlns:p="http://primefaces.prime.com.tr/ui">
The XML namespace URI contains a typo.
<html ... xmlns:p="http://primefaecs.org/ui">
The XML namespace prefix does not match.
<html ... xmlns:pf="http://primefaces.org/ui">
The XML namespace is totally missing.
<html ...>
The component library is not installed at all. In other words, the JARs containing component library's tag definitions is missing in webapp's /WEB-INF/lib folder.
Either way, all <p:xxx> tag won't be parsed and be considered as template text. But, all EL expressions will still be evaluated (as if you're using <p>#{bean.text}</p>), and they will all behave as ValueExpressions instead of MethodExpressions.
An easy way to recognize the root cause is looking at stack trace. If you're seeing com.sun.faces.facelets.compiler.AttributeInstruction in the stack trace, then it means that the component is interpreted as "plain text". Otherwise you would have seen e.g. org.primefaces.component.commandbutton.CommandButton in the specific case of <p:commandButton>.

Related

Property 'addListener' not found on type com.chat.viewbeans.ClientBean [duplicate]

While deploying GAE + primefaces application, I got following error:
com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException: Error Rendering View[/CreateEmployee.xhtml]
javax.el.ELException: /CreateEmployee.xhtml: Could not find property saveEmployee in class com.fetchinglife.domain.data.dao.EmployeeRepositoryImpl
at com.sun.faces.facelets.compiler.AttributeInstruction.write(AttributeInstruction.java:94)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:302)
at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
Even saveEmployee is already in EmployeeRepositoryImpl class. How is this caused and how can I solve it? Are there any annotations which I have to put extra?
Let's rephrase the exception in a general format in order to better understand the cause:
javax.el.ELException: Could not find property doSomething in class com.example.Bean
This exception is literally trying to tell you that the Bean class doesn't have the following method:
public SomeObject getDoSomething() {
return someObject;
}
(where SomeObject is the type of the doSomething property)
There are several causes for this.
Action method expression is incorrectly interpreted as property value expression
Given the fact that the property name is in your case actually a combination of a verb and noun, a resonable cause is you incorrectly bound an action method to an attribute of some JSF component which actually takes a value expression, not a method expression. E.g. when you accidentally do
<h:commandButton value="#{bean.doSomething}">Save</h:commandButton>
or even
<h:button value="Save" outcome="#{bean.doSomething}" />
instead of
<h:commandButton value="Save" action="#{bean.doSomething}" />
The latter would then expect the following method, which you probably actually have:
public String doSomething() {
// ...
return "nextpage";
}
(which can also be declared to return void by the way)
Component is not resolved at all
Another probable cause is that the component is not interpreted as a real component at all, but as "plain text". In other words, when you remove the action attribute and then try to open the JSF page in browser, it'll now load fine, but you will see the whole component unparsed in the generated HTML output (which you can see via rightclick, View Source in browser).
This can have several causes:
The XML namespace of the component is wrong or missing. E.g. in case of PrimeFaces you accidentally used the old PrimeFaces 2.x URI while you're actually using PrimeFaces 3+.
<html ... xmlns:p="http://primefaces.prime.com.tr/ui">
The XML namespace URI contains a typo.
<html ... xmlns:p="http://primefaecs.org/ui">
The XML namespace prefix does not match.
<html ... xmlns:pf="http://primefaces.org/ui">
The XML namespace is totally missing.
<html ...>
The component library is not installed at all. In other words, the JARs containing component library's tag definitions is missing in webapp's /WEB-INF/lib folder.
Either way, all <p:xxx> tag won't be parsed and be considered as template text. But, all EL expressions will still be evaluated (as if you're using <p>#{bean.text}</p>), and they will all behave as ValueExpressions instead of MethodExpressions.
An easy way to recognize the root cause is looking at stack trace. If you're seeing com.sun.faces.facelets.compiler.AttributeInstruction in the stack trace, then it means that the component is interpreted as "plain text". Otherwise you would have seen e.g. org.primefaces.component.commandbutton.CommandButton in the specific case of <p:commandButton>.

What exactly is #{component} in EL?

According to https://code.google.com/p/primefaces/issues/detail?id=4720, The ComponentUtils.resolveWidgetVar(String expression, UIComponent component) function is available in Primefaces since 2013. It can be used in EL by the "#{p:widgetVarFromContext(searchExpression, component)}" function.
This is useful in case of several components have the same id in different NamingContainer, but are still present in the same view. In this case,
the #{p:widgetVar(searchExpression)} function only returns the last one found.
I don't understand however how to reference the UIComponent that must be passed as the second argument from EL. The above mentioned bug report suggests we can refer to it using #{component}. Can anyone provide me with an example?
The #{component} is an implicit EL variable referring the current UIComponent in EL scope (see also implicit EL objects). You can usually only refer it in component's HTML attribute or in template text children.
E.g. in case of <h:inputText> it will reference an instance of UIInput class which has among others an isValid() method.
<h:inputText id="foo" required="true"
style="background: #{component.valid ? '' : 'pink'}"
onclick="alert('Client ID of this component is #{component.clientId}');" />
You can also use binding attribute to let JSF during view build time put a reference to a component instance in the Facelet scope. This way the component reference will be available anywhere in the Facelet during view render time.
<script>alert('Client ID of foo component is #{foo.clientId}');</script>
<h:inputText binding="#{foo}" />
See also:
Difference between client id generated by component.clientId and p:component()
JSF component binding without bean property
How does the 'binding' attribute work in JSF? When and how should it be used?
The p:widgetVarFromContext is useful when referring to a PrimeFaces widget inside a composite component. There could be more than one instance of your component on the same page. So writing widgetVar="expression" and PF('expression') is out of the question. There would be multiple widgets with the same name. It is then better to omit the widgetVar attribute and use the generated one which is unique because it is based on the clientId.
You can't use #{p:widgetVar('expression')} within your <cc:implementation> because it leads to a Cannot find component for expression "expression" referenced from "j_id1" error instead of the expected PF('widget_expression').
But you can use #{p:widgetVarFromContext('expression', cc)} which will return something like PF('widget_wrapperform_compositecomponent1_expression'). The cc refers to the root of the composite component instance.

Why is InputHidden readonly attribute not in JSF documentation?

I have recently encountered a case where I wanted to set the index value from ui:repeat varStatus="v" using <h:inputHidden="#{v.index}/>. If you try this and execute the component using AJAX you will get an exception that the property is not writeable. While looking around I found that inputHidden supports a readonly="true" attribute that does just that making the error go away.
Is there a reason why this is not in documentation? (i.e. special, passthrough, other)
Is it safe to use?
After doing some digging Core JavaServer Faces 3e had this to say :
The h:inputHidden tag has the same attributes as the other input tags, except that it does not support the standard HTML and DHTML tags
So, the reason why readonly is not in the docs for inputHidden and also why it's not being rendered in your HTML is because inputHidden does not support it. This was also confirmed by Netbeans when I tried to add readonly as an attribute to inputHidden'(red squiggly lines with an error message). I was able to get that exception when I submitted a form with no setter defined for my bean property that was placed in inputHidden. Since inputHidden calls the setter when a form is submitted (for my case) and since none is defined in my code, it will of course throw that exception, namely:
javax.el.PropertyNotWritableException: /index.xhtml #14,56 value="#{bean.x}": The class 'Bean' does not have a writable property 'x'.
As for why it works when you do that I have no idea. Since you're worried about safety, I would suggest you do as BalusC says and simply use <input type="hidden"> or you define a setter for that property. Don't use it like that.
So long time since this question started, however just FYI, this works:
<h:inputHidden id="compId" readonly="#{true}" value="#{myBean.attribute}" />

Primefaces and tag value from bean method

I want to set the value of a primefaces tag from a bean method using arguments but this doesn't work.
On the Facelets page:
<p:outputLabel id="userLabel" value="#{languageBean.retrieveLanguage(1)}" />
<p:commandButton value="#{languageBean.retrieveLanguage(2)}"
action="#{loginBean.logIn()}"
update="loginForm"/>
On the bean:
public String retrieveLanguage(int key) {
return (String) getPageMap(pagePath, pageName).get(key);
}
I get the following exception:
javax.faces.view.facelets.FaceletException: Error Parsing /components/login.xhtml: Error Traced[line: 24] Element type "p:outputLabel" must be followed by either attribute specifications, ">" or "/>".
Could you give me any idea, please?
Regards,
Roberto
You shouldn't be passing in the language value from the front page - this is moving actual login from the app into the graphical frontend. Rather, store the language value in the bean and simply call retrieveLanguage.
If you are trying to handle translations, have a look at resource bundles instead.

JSF 2.0 Validator Wrapping

I ran into a problem when I tried to apply a custom validator to an input field:
I want to use a custom validator that is generated by a bean and bound to a f:validator tag:
<f:validator binding="#{bean.myValidator}">
The corresponding bean method looks like this:
public Validator getMyValidator(){
return new Validator(){...};
}
If I'm using the tag inside an input tag like this:
<h:input value="...">
<f:validator binding="#{bean.myValidator}" />
</h:input>
then everything works as expected.
However, if I'm using the tags the other way around like this:
<f:validator binding="#{bean.myValidator}">
<h:input value="...">
</f:validator>
then I get a ServletException ("validatorID is null").
What is the reason for this Exception?
Also, I don't understand the corresponding f:validator tag spec:
If this element is nested within a UIComponent tag that has other UIComponent children, the validator will be automatically added to all the child components as well as this one.
I guess my f:validator tag is nested within f:view, correct?
What does "to all the child components" mean? Whose child components?
What is the reason for this Exception?
I'm not sure. Both Mojarra 2.1.3 and MyFaces 2.1.1 exposes the same problem. It works when the validator is a standalone #FacesValidator("myValidator") class which is been specified by <f:validator validatorId="myValidator">. The spec nor the vdl describes this behaviour. You might want to post an issue report to the JSF spec guys to clarify this more in the spec or vdl.
Also, I don't understand the corresponding f:validator tag spec:
If this element is nested within a UIComponent tag that has other UIComponent children, the validator will be automatically added to all the child components as well as this one.
I guess my f:validator tag is nested within f:view, correct? What does "to all the child components" mean? Whose child components?
It's just a terrible wording of whatever you're trying to achieve is just supported: wrapping a common validator over a set of components. You might want to ask the JSF spec guys to clarify this more as well.

Resources