• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

evaluate dynamic expression language

 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a top level JSP that <jsp:include>'s a JSP which contains form fields. This second included JSP contains common fields that are reused among other top level JSP pages. The different jsp pages. are backed by different (Struts) form beans, and have different levels of nested beans.

What I did to make the form consistent was pass in a parameter for a "prefix", that is the notation of the nested beans up to the nested bean that contains these form fields.

so I have

on the first invocation, and

on the second top level form, which has different nested bean structure, but the same leaf bean instance the form is working with, an instance of a mailing address bean.

then in the included form JSP:



This part works nicely.

Now I am adding some conditional logic, like


where form is a page context attribute of the form bean instance.
This works in the first case, where the prefix represents the simple single bean name (address), but fails when it is a compound value (location.address).

I have been able to get around the expression language not working by using a scriptlet that calls the beanutils:


In other cases, I would also want to do something like this with indexed beans,
such as when prefix = "locations.item[1].locationModel".


I also tried writing the entire expression out.

I am also able to use the scriptlet calling beanutils like I did above to get around this, but it is not as elegant as I would like it to be,
and this really gets complicated when I would want to use the variable expression with <c:forEach items="${form[prefix].config.columns}" type of places.

So I was wondering if there was a better way to do this using the expression language syntax.
That is, it is possible for the expression language evaluate the value of a variable expression ?

I am using Servlet 2.4, JSP 1.2, JSTL 1.1
[ July 09, 2006: Message edited by: Travis Hein ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Travis Hein:

So I was wondering if there was a better way to do this using the expression language syntax.



Both EL and JSTL are best used in a true MVC environment.
In an MVC environment, all the HTTP flow issues are handled in a servlet and the real business functionality (model) is handled in beans. Only when all the processing is done does the context get passed to a JSP (view) for display. JSTL and EL allow the JSP developer to iterate over and do some simple scripting with the results in order to present it in the form of a web page.

If you find yourself needing to do the complex things you're asking about, you may want to rethink your architecture. Perhaps a lot of that logic could be worked out before forwarding to the JSP in the first place.

This next part is my opinion:
If you're going to use scriptlets in your JSPs, don't bother to use EL and JSTL. The only thing worse than seeing scriptlets in a JSP is seeing a combination of all of the available syntaxes (sp) in one page. Either go with scriptless pages and allow no scriptlets or stick to scriptlets alone.
 
Beware the other head of science - it bites! Nibble on this message:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic