I'm trying to learn JSF and EL and I am facing the following error:
/index.xhtml #20,120 actionListener="#{contatosController.adicionar(actionEvent)}" Q
What does that mean and how can I solve it?
It means that your environment does not support the EL 2.2 feature of invoking methods with arguments. The EL syntax #{bean.method(argument)} is unsupported in EL 2.1 and older and therefore unparsable. Just get rid of that argument. JSF fills it in by itself anyway.
actionListener="#{contatosController.adicionar}"
Please note that even if you upgraded to EL 2.2, it would still end up in trouble as you're essentially passing null to it (you don't have a managed bean #{actionEvent}, right?). You should actually never need to specify the default argument of a JSF (action)listener method yourself.
See also:
How to call a method with a parameter in JSF
Differences between action and actionListener
Related
Jsf page with myFaces trinidad 1.2.15 ver JSF 1.2-20 could not be parsed due to expression evaluation error over ELContext. here is the stack
Caused by: java.lang.NullPointerException
at com.sun.el.ValueExpressionLiteral.getValue(ValueExpressionLiteral.java:79)
at org.apache.myfaces.trinidad.webapp.UIXComponentELTag.setProperty(UIXComponentELTag.java:135)
at org.apache.myfaces.trinidadinternal.taglib.html.HtmlHeadTag.setProperties(HtmlHeadTag.java:70)
at org.apache.myfaces.trinidad.webapp.UIXComponentELTag.setProperties(UIXComponentELTag.java:122)
at javax.faces.webapp.UIComponentELTag.createComponent(UIComponentELTag.java:230)
at javax.faces.webapp.UIComponentClassicTagBase.createChild(UIComponentClassicTagBase.java:513)
at javax.faces.webapp.UIComponentClassicTagBase.findComponent(UIComponentClassicTagBase.java:782)
at javax.faces.webapp.UIComponentClassicTagBase.doStartTag(UIComponentClassicTagBase.java:1354)
at org.apache.myfaces.trinidad.webapp.UIXComponentELTag.doStartTag(UIXComponentELTag.java:71)
at jsp_servlet._jsp._btwizard.__btwizardmain._jsp__tag2(__btwizardmain.java:648) ....
The problem was that the setProperty method of UIXComponentELTag by default passes a null argument for ElContext as this:
bean.setProperty(key, expression.getValue(null));
This is not supported on the version of elcontext that weblogic12 uses. We were not allowed to change the version of trinidad being used so we had to patch the library changing all the calls of getValue with
bean.setProperty(key, expression.getValue(FacesContext.getCurrentInstance().getELContext()));
We also found this problem on some clases that were generated from XML files like Color.xml, DateTime.xml and Number.xml, so we had to prevent them from being generated and provide our own implementation.
I replaced all of my JNDI lookups with JNDI.lookup() method because it seemed convenient, dealt with dynamic return types, etc. All was great...but now I just noticed that the checked exceptions that I had to catch before are no longer there.
I assumed this was because it would have just returned null if the JNDI variable didn't exist but it doesn't. It now just throws an unchecked exception.
Any idea why? Is there a way of just returning null for non-existant variables instead?
I created a bug for this on the omnifaces website: https://github.com/omnifaces/omnifaces/issues/141
Not sure if this is intended behavior or not.
Is there a way of just returning null for non-existant variables instead?
It does that for NameNotFoundException. The problem was here not in OmniFaces, but in the environment, which was GlassFish 4.1 in your specific case. It unexpectedly wrapped the NameNotFoundException in another NamingException, hereby causing the underlying NameNotFoundException to slip through and bypass the return null condition.
This has been fixed with help of Exceptions#is() utility method as per this comment. It will be available in OmniFaces 2.2.
How to use omnifaces CDNResourceHandler with versioned resources?
Original url:
javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=5.0
Desired url:
//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js
How to map this to a specific url, omitting the version query parameter?
Mapping:
Using following mapping appends the version query parameter to the final url resulting in 404 HTTP error.
primefaces:jquery/jquery.js=//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js
Results in:
//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js&v=5.0
System:
Glassfish 4
Mojarra 2.24
Primefaces 5.0
Rewrite 2.11
I reproduced it. This will happen when the PrimeFaces PrimeResourceHandler is initialized after OmniFaces CDNResourceHandler.
If you've declared the CDNResourceHandler inside /WEB-INF/faces-config.xml, then this is quite unexpected and likely a bug in GlassFish4.
But if you've declared the CDNResourceHandler inside /META-INF/faces-config.xml of a JAR which you in turn placed inside /WEB-INF/lib, then this can indeed happen if GlassFish initializes that JAR before the PrimeFaces JAR. In order to solve the problem, you need to explicitly declare your JAR's /META-INF/faces-config.xml to be initialized after the PrimeFaces one by adding the following entry to your JAR's /META-INF/faces-config.xml:
<ordering>
<after>
<name>primefaces</name>
</after>
</ordering>
Alternatively, move the CDNResourceHandler declaration to webapp's /WEB-INF/faces-config.xml.
How can I pass an arugument to listener method?
I have tried like this:
<p:poll interval="3" listener="#{vehicleController.onPoll('12')}"
update="vehicleDataList"/>
and
<p:poll interval="3" listener="#{vehicleController.onPoll(vehicle.vehicleLicense)}"
update="vehicleDataList"/>
But it throws the following exception:
javax.servlet.ServletException: /monitorVehicles/vehiclesList.xhtml
Failed to parse the expression [#{vehicleController.onPoll('12')}]
How can I achive this?
getting this exception "Failed to parse the expression [#{vehicleController.onPoll('12')}]"
Your environment doesn't support the new EL 2.2 feature of invoking methods with arguments.
EL 2.2 is part of Servlet 3.0, thus in order to utilize it, you need to deploy to a Servlet 3.0 compatible container (e.g. Tomcat 7, Glassfish 3, JBoss AS 6, etc) with a Servlet 3.0 compatible web.xml file. If you don't deploy to a Servlet 3.0 compatible container, or don't have a Servlet 3.0 compatible web.xml, then you aren't using EL 2.2 at all and you will get this kind of exception.
If you're actually targeting/deploying to a Servlet 2.5 compatible container (and thus using EL 2.1), then you can use JBoss EL to have the new EL 2.2-like features in EL 2.1.
See also:
How to call a method with a parameter in JSF
Invoke direct methods or methods with arguments / variables / parameters in EL
In JSF 2:
If your listener is expecting a string:
"#{vehicleController.onPoll('11')}"
public void onPOll(String s){
}
If your listener is expecting an int:
"#{vehicleController.onPoll(11)}"
public void onPoll(int i){
}
I have created a simple bean using this example from Per
http://per.lausten.dk/blog/2012/02/creating-your-first-managed-bean-for-xpages.html
And I can access the bean using
helloWorld.setSomeVariable("test") and
get the value using helloWorld.getSomeVariable()
But when I try it using EL language it doesn't work
helloWorld.SomeVariable
I get an error that SomeVariable doesn't exists in helloWorld
I'm probably doing some simple error, but I can't see what.
I believe the problem is that EL is likely case-sensitive the bean-style name of the property is "someVariable". Beans assume that you're using camel-case for the method names, so EL downcases the first letter after "set" and "get" for their translation.
EL seems to be case sensitive in my regards and your property is defined as someVariable and not SomeVariable. have you tried helloWorld.someVariable.