Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSTL or JSP 2.0 EL for getter with argument

How can I access a getter that has a parameter using JSTL or JSP 2.0 EL?

I want to access something like this:

public FieldInfo getFieldInfo(String fieldName) {
 ....
}

I could access this in Struts by using mapped properties but don't know if it is possible in JSTL or JSP 2.0.

I tried everything but is not working.

like image 483
user82164783 Avatar asked Apr 25 '11 16:04

user82164783


People also ask

What is the difference when using JSTL and JSP?

JSP lets you even define your own tags (you must write the code that actually implement the logic of those tags in Java). JSTL is just a standard tag library provided by Sun (well, now Oracle) to carry out common tasks (such as looping, formatting, etc.).

How check value is null or not in JSTL?

Solution 1 - Use empty Operator The empty operator return true if the operand is null, an empty String, empty array, empty Map, or empty List; false, otherwise. You can learn more about the empty operator and if the tag of JSTL in the class Head First Servlet and JSP book.

How check string is null or not in JSP?

To check if a string is null or empty in Java, use the == operator.

Which of the following is equivalent to out print () method in JSP?

out. print(“Out Implicit Object in jSP - BeginnersBook”); void println(): This method is similar to the print() method, the only difference between print and println is that the println() method adds a new line character at the end.


1 Answers

Passing method arguments in EL is only by EL spec supported in EL 2.2. EL 2.2 is by default shipped in Servlet 3.0 / JSP 2.2 containers. So if you're using a Servlet 3.0 container (Tomcat 7, Glassfish 3, JBoss 6, etc) and your web.xml is declared conform Servlet 3.0 spec, then you should be able to access it as follows

${bean.getFieldInfo('fieldName')}

Since you explicitly mentioned JSP 2.0, which is part of the old Servlet 2.4 spec, I assume that there's no room for upgrading. Your best bet is to replace the method by

public Map<String, FieldInfo> getFieldInfo() {
    // ...
}

so that you can access it as follows

${bean.fieldInfo.fieldName}

or

${bean.fieldInfo['fieldName']}

or

${bean.fieldInfo[otherBean.fieldName]}
like image 160
BalusC Avatar answered Sep 30 '22 12:09

BalusC