File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes evaluate dynamic expression language Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "evaluate dynamic expression language" Watch "evaluate dynamic expression language" New topic
Author

evaluate dynamic expression language

Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161
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 ]

Error: Keyboard not attached. Press F1 to continue.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: evaluate dynamic expression language