Here is sample code that throws a Servlet Exception as invalid expression error.
data Types are thus:
boolean: bean1.isValid1
boolean: bean1.isValid2
boolean: bean1.isValidSubCondn
String: bean2.StringData1
String: bean2.StringData2
want to use this inside JSTL tag:
<x:div id="someID"
rendered='#{!bean1.isValid1 || bean1.isValid2 ? (bean1.isValidSubCondn ? bean2.StringData1.matches("^a|^b") : bean2.StringData2.matches("^c|^d") ) : "true"}'>
Now if this works, I would like to add a method call instead of doing the RegEx check within the JSP itself. That doesn't work either - probably has to do with the same syntax issue.
[ServletException in:/beanName.jsp]
Invalid expression:
'${!bean1.booleanProperty1 && bean1.booleanProperty2? (beanInstance.booleanProperty3 ? beanName.methodName1(bean2.stringProperty) : beanName.methodName1(bean3.stringProperty) ) :'true'}''
My JSP code is thus:
<x:div id="something" rendered="#{not bean1.booleanProperty1 or (bean1.booleanProperty2 ? (beanInstance.booleanProperty3 ? beanName.methodName1(bean2.stringProperty) : beanName.methodName1(bean3.stringProperty) )) :true}">
This doesn't work either:
<x:div id="something" rendered="#{!bean1.booleanProperty1 || bean1.booleanProperty2 ? (beanInstance.booleanProperty3 ? beanName.methodName1(bean2.stringProperty) : beanName.methodName1(bean3.stringProperty) ) :true}">
The beanName.methodName1 is thus:
public boolean methodName1(String stringValuex) {
if(stringValuex.matches("^A|^B"))
{ return true; }
return false;
}
alternatively, I tried using the getter/setter method approach in the bean class, to get and set the property. Doesn't work in the JSP either. Not sure how to resolve. I need to perform a validation using a bean data of another class to display certain results.
Here is the setter/getter approach, need to figure out how to use this, then, in the JSP validation.
<x:div id="something" rendered="#{!bean1.booleanProperty1 and bean1.booleanProperty2 ? (beanInstance.booleanProperty3 ? beanName.booleanFieldName(bean2.stringProperty) : beanName.booleanFieldName(bean3.stringProperty) ) : true}">
beanName.java class
private boolean booleanFieldName = false;
public boolean getbooleanFieldName() {
return this.booleanFieldName;
}
public void setbooleanFieldName(String valueToTest) {
if(valueToTest.matches("^a|^A"))
{ this.booleanFieldName= true;
}
this.booleanFieldName= false;
}
You can't mix types in a ternary, and you are mixing booleanwith
String"true"`.
Try this, replacing "true"
with true
:
rendered='#{!bean1.isValid1 || bean1.isValid2 ? (bean1.isValidSubCondn ? bean2.StringData1.matches("^a|^b") : bean2.StringData2 .matches("^c|^d") ) : true}'>