Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dealing with Java Expression Language on a page

I am working on the frontend of a project that gives me Java Expression Language tags to work with. In one instance I need to see if it is returning an array or just one bit of data and I don't know how to work with it.

Example:

The page has

<p>${WebAppContext.buildings[0].location.name}</p>

which will output something like:

<p>Acme</p>

Problem is I need to output more if there is more in that buildings bit:

Something like (in pseudocode):

if isArray(${WebAppContext.buildings}){
 foreach(${WebAppContext.buildings} as foo){
    //iterate over whatever is in the array
}
}

so I can output something like:

<p>${WebAppContext.buildings[0].location.name}</p>
<p>${WebAppContext.buildings[1].location.name}</p>

I asked the Java people responsible for generating this code and they said "Dunnokindofbusyrightnowbuhbye." so I'm hoping you folks will have some insight.

Beyond sticking the code in the page I don't have a clue how to work with this Java Expression Language (I even had to look it up to see what the heck it is called). So any advice/resources would be helpful.


EDIT:

I've tried the following and am not getting any results:

<c:forEach var='building' items='${WebAppContext.buildings}'>
  <p>${building.location.name}</p>
</c:forEach>

In the source of the page it just shows:

<c:forEach var='meeting' items='[Lorg.foo.bar.baz.bat.serviceapi.webserviceobject.xsd.BuildingsWSO;@3823ff8'>
  <p></p>
</c:forEach>

I'll admit that, not knowing anything about Java Expression Language, I don't understand why the items='' gets translated like it does though I can see that it follows a path in the setup we use. Now when I use:

<p>${WebAppContext.buildings[0].location.name}</p>
<p>${WebAppContext.buildings[1].location.name}</p>

I get:

<p>Krustylu Studios</p>
<p>Springfield Nuclear Power Plant</p>
like image 559
rg88 Avatar asked Nov 23 '10 22:11

rg88


People also ask

What is Java expression language explain with example?

An expression language makes it possible to easily access application data stored in JavaBeans components. For example, the JSP expression language allows a page author to access a bean using simple syntax such as ${name} for a simple variable or ${name. foo.

What is the syntax of expression language in a JSP page?

Simple SyntaxThe most common operators in JSP EL are . and []. These two operators allow you to access various attributes of Java Beans and built-in JSP objects. When the JSP compiler sees the ${} form in an attribute, it generates code to evaluate the expression and substitues the value of expresson.

What is JSP expression language and what are it's benefits?

The Expression Language (EL) simplifies the accessibility of data stored in the Java Bean component, and other objects like request, session, application etc. There are many implicit objects, operators and reserve words in EL. It is the newly added feature in JSP technology version 2.0.


1 Answers

I don't think that kind of advanced functionality is supported by EL; you can try using the JSTL c:forEach tag to iterate over your list.

like image 109
Jon Onstott Avatar answered Sep 20 '22 05:09

Jon Onstott