I have JSF page that is trying to call a method in my managed bean, but is throwing an error that I am calling an ambiguous method:
<div class="Container100 MarTop5 #{surveyBean.getBackGroundStyleClass(cc.attrs.multiChoiceItem.answer)}">
The error is:
SEVERE: /resources/component/checkMany2.xhtml: Unable to find unambiguous method: class org.beans.questionnaire.SurveyBean.getBackGroundStyleClass(null)
javax.el.ELException: /resources/component/checkMany2.xhtml: Unable to find unambiguous method: class org.beans.questionnaire.SurveyBean.getBackGroundStyleClass(null)
The problem is that my SurveyBean class has overloaded getBackGroundStyleClass() methods. Consequently, when the cc.attrs.multiChoiceItem.answer is null, it does not know which method to call.
In standard Java, I would be able to cast the answer to the type I want to ensure that Java can find the correct method.
How can I do this in EL? Is it feasible? I've tried:
but that failed miserably:
Failed to parse the expression [#{surveyBean.getBackGroundStyleClass((Answer)cc.attrs.multiChoiceItem.answer)}]
I also tried:
#{surveyBean.getBackGroundStyleClass(Answer.class.cast(cc.attrs.multiChoiceItem.answer))}
but that too failed with:
javax.el.ELException: The identifier [class] is not a valid Java identifier as required by section 1.19 of the EL specification (Identifier ::= Java language identifier). This check can be disabled by setting the system property org.apache.el.parser.SKIP_IDENTIFIER_CHECK to true.
Is there some way in EL to cast the argument type?
Related
We are using a model with name Process in graphql api. while building the manifest, we are getting ambiguity error like below.
QueryResolver.java:[12,20] reference to Process is ambiguous from both classes com..Process and java.lang.Process.*
How can I explicitly mention the QueryResolver to use the java.lang.Process in the below methods ?
'''
#javax.validation.constraints.NotNull
java.util.List Process(ProcessInput input,graphql.schema.DataFetchingEnvironment env) throws Exception;
'''
The following customTypeMapping tag solved my issue, We need to specify what type compiler need to use in runtime.
<customTypesMapping>
<Process>com..schema.model.Process</Process>
</customTypesMapping>
You can find more details here
https://github.com/kobylynskyi/graphql-java-codegen/tree/master/plugins/maven
I am trying to initialize an JexlEngine object, but the constructor does not let me do so (although the documentation states it should).
Here's the documentation for the JexlEngine class (in jexl3):
https://people.apache.org/~henrib/jexl-3.0/apidocs/org/apache/commons/jexl3/JexlEngine.html
Originally the code worked with the jexl2 import, but I have recently converted the project to Maven, and had to swap out to jexl3 instead. Now the constructor no longer works.
Am I missing anything?
I am running this project in Netbeans, on Java 1.8 - it's a Maven project with included dependancies for jexl3 (used to work with jexl2 however)
My code:
public static final JexlEngine jexl = new JexlEngine(null, new MyArithmetic(), null, null){};
static {
jexl.setCache(512);
jexl.setLenient(false); // null shouldnt be treated as 0
jexl.setSilent(false); // Instead of logging throw an exception
jexl.setStrict(true);
}
Based off the documentation, there should be a constructor with 4 parameters, as I am trying to run it, but for some strange reason, it wont let me run it. Any ideas why? (again - it used to work with Jexl2)
Error log:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project bilbon-core: Compilation failure: Compilation failure:
si/smth/project/bean/CUtil.java:[333,43] constructor JexlEngine in class org.apache.commons.jexl3.JexlEngine cannot be applied to given types;
required: no arguments
found: <nulltype>,si.smth.project.bean.CUtil.MyArithmetic,<nulltype>,<nulltype>
reason: actual and formal argument lists differ in length
si/smth/project/bean/CUtil.java:[333,99] <anonymous si.smth.project.bean.CUtil$1> is not abstract and does not override abstract method newInstance(java.lang.String,java.lang.Object...) in org.apache.commons.jexl3.JexlEngine
si/smth/project/bean/CUtil.java:[336,13] cannot find symbol
symbol: method setCache(int)
location: variable jexl of type org.apache.commons.jexl3.JexlEngine
si/smth/project/bean/CUtil.java:[337,13] cannot find symbol
Use the empty constructor, which is the only constructor in latest java docs
JexlEngine jexl = new JexlEngine();
Or use JexlBuilder as describe in jexl:
JexlEngine jexl = new JexlBuilder().create();
You can call builder methods for your setters:
JexlEngine jexl = strict(true).silent(false).cache(512) .create();
Instead of Lenient flag you have setSilent and setStrict combinations:
The setSilent and setStrict methods allow to fine-tune an engine instance behavior according to various error control needs. The strict flag tells the engine when and if null as operand is considered an error, the silent flag tells the engine what to do with the error (log as warning or throw exception).
When "silent" & "not-strict":
0 & null should be indicators of "default" values so that even in an case of error, something meaningful can still be inferred; may be convenient for configurations.
When "silent" & "strict":
One should probably consider using null as an error case - ie, every object manipulated by JEXL should be valued; the ternary operator, especially the '?:' form can be used to workaround exceptional cases. Use case could be configuration with no implicit values or defaults.
My Xpages app has a cacheBean for application wide settings. I have a managed Bean for a PC document, which has field status of type integer.
In the cacheBean I have a method getPCStatus(Integer status) that when given the number will return the string text of the status.
On my Xpage I have a text field which I want to bind to the result of
cacheBean.getPCStatus(PCBean.status)
so it will return "In Inventory" for a 1 and something else for a 2 etc.
However, the code is throwing an error.
Here is the code:
readonly="true">
<xp:this.value><![CDATA[#{CacheBean.getPCStatus(PCModelBean.status)}]]></xp:this.value>
</xp:inputText>
The error is
Error in EL syntax, property 'value': CacheBean.getPCStatus(PCModelBean.status)
I know I read something about this long ago but cannot remember how to handle this, but cannot find it.
I was wondering if the method getPCStatus should be in the PCBean or in the cacheBean?
The version of EL used n XPages doesn't have support for calling methods with parameters. If getPCStatus() were a zero-argument method, you could call it with #{CacheBean.pCStatus}, presumably, but as it is it's the parameter that's in your way.
There are a few common workarounds: if CacheBean itself implements Map or DataObject, then EL will call the get or getValue method, respectively, with whatever you put after the "." - you could use that to sort of fake method calls.
Alternatively, you could keep CacheBean a POJO (not implementing one of those interfaces) but have the return value from getPCStatus itself be a Map or DataObject, which would take whatever value you pass in (in this case, PCModelBean.status) and do the lookup, with a binding like #{CacheBean.pCStatus[PCModelBean.status]}. DataObjects aren't too bad to write: https://frostillic.us/blog/posts/FE0AE00B7CEC4F8885257D46006CAB68
Or, as an complete alternative to all of this, if you don't need your binding to be read+write, you could use SSJS to call the method.
I’ve been following the e-commerce tutorial located here: http://netbeans.org/kb/docs/javaee/ecommerce/intro.html
Code repo of project here.
I have ran into a few problems that I believe are related:
1: Trying to view the customers’ orders on the Admin page results in:
**WARNING**: EJB5184:A system exception occurred during an invocation on EJB OrderManager, method: public java.util.Map session.OrderManager.getOrderDetails(int)
**WARNING**: javax.ejb.EJBTransactionRolledbackException
**WARNING**: EJB5184:A system exception occurred during an invocation on EJB OrderedproductFacade, method: public java.util.List session.OrderedproductFacade.findByOrderId(java.lang.Object)
**WARNING**: javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean
Caused by: java.lang.IllegalArgumentException: You have attempted to set a parameter value using a name of customerOrderId that does not exist in the query string SELECT o FROM Orderedproduct o WHERE o.orderedproductPK.custOrderid = :custOrderid.
2: Trying to view details for a particular order in the admin page results in:
WARNING: StandardWrapperValve[AdminServlet]: PWC1406: Servlet.service() for servlet AdminServlet threw exception
Caused by: java.lang.IllegalArgumentException: You have attempted to set a parameter value using a name of customerOrderId that does not exist in the query string SELECT o FROM Orderedproduct o WHERE o.orderedproductPK.custOrderid = :custOrderid.
Both problems have the ‘findByOrderId’ method in common and I am at a loss as to what is wrong with it.
The offending method is located in the following directory: src/jsf_crud/src/java/session/OrderedProductFacade.java
(I would link it as a hyperlink but spam prevention measures prevent me)
Not sure what the best course of action is, any recommendations?
Your query needs a parameter called "custOrderid" and not "customerOrderId"
Either change the query or change the called parameter.
The query in the OrderedProduct class uses "customerOrderId"
http://netbeans.org/projects/samples/sources/samples-source-code/content/samples/javaee/AffableBean/src/java/entity/OrderedProduct.java
This is regarding Spring property editors.
I have a Interface A that is being implemented to Class B and C.
I have a command class Doc in which in which i have a list of A
class Doc{
List<A> list ;
}
list may contain either object of B or C. In this situation how could i use property editor. i wrote two property editor for the two classes and register them in initBinder method as
binder.registerCustomEditor(C.class,new CPropertyEditor());
binder.registerCustomEditor(B.class,new BPropertyEditor());
but it does not seems to be working. Please help.
i am getting the following exception:
Request processing failed; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.test.A] for property list: no matching editors or conversion strategy found
This is my first post so please sorry if i made any mistake.
One approach is to implement a single property editor for A. The implementation can look at the string and then create an instance of B or C.