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){
}
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 want to get bean from producer method in order to read its properties. In some scenarios the bean is a EJB Singleton bean.
I've simplified my code to focus on the problem.
My simple qualifier:
#Qualifier
#Retention(RUNTIME)
#Target({TYPE, METHOD, FIELD, PARAMETER})
public #interface InjectMe {}
Simple producer:
#Dependent
public class SimpleProducer {
#Produces
#InjectMe
public String getInjectMe(InjectionPoint ip) {
// ip.getBean() returns null for some reason
return "ip=" + ip + ", bean=" + ip.getBean();
}
}
EJB (Singleton):
#Singleton
#Startup
public class SimpleSingleton {
#Inject
#InjectMe
private String injectMe;
#PostConstruct
public void init() {
System.out.println(injectMe);
}
}
Console output:
Info: ip=[BackedAnnotatedField] #Inject #InjectMe private com.test.ejb.SimpleSingleton.injectMe, bean=null
When I change Singleton bean to CDI bean everything works fine (ip.getBean() returns not null). It also worked in Java EE 6 even with Singleton bean but it does not in Java EE 7. I am using Glassfish 4 application server.
Is this behavior specified somewhere?
Using
injectionPoint.getMember().getDeclaringClass()
works for me in WildFly 10.1.0 and I also quickly tested it in Payara Server 4.1.1.162 #badassfish (build 116). I also did a test on brand new Payara Server 4.1.1.164 #badassfish (build 28). However,I had to change the scope of the producer bean to #ApplicationScoped. Default scope did not work. In my case, it even makes sense :)
The
injectionPoint.getBean().getBeanClass()
method worked for me in the old Payara, but not in the new WildFly 10.1.0.Final and new Payara Server 4.1.1.164 #badassfish (build 28).
If you have a look at Payara, the current new version 164 contains Weld 2.4.0.Final and WildFly 10.1.0Final uses version 2.3.5.Final. In both versions, the classical code does not work !
The conclusion is, on older CDI implementations (Weld), it works. In some newer Weld (introduced in Payara 161), the behavior changed. I do not know if this is intentional or not.
However, the solution is to use
injectionPoint.getMember().getDeclaringClass()
and annotate the producer bean with
#javax.enterprise.context.ApplicationScoped
annotation.
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.
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
I've found the instanceof operator in JSF EL, but it throws an exception when used. It's obviously reserved but not implemented? When will it (probably) be available, if not already in a newer version than JSF 1.2, which I'm currently using?
The keyword instanceof is indeed reserved in the EL (see here), but it is still not used in the latest version of EL (2.2), used in JSF 2.x.