Friday, October 1, 2010

Using EMF to detect loops within a JSP

After my post explaining how to create EMF models from JSP pages, someone posted a comment on TheServerSide to know if the EMF model could be used to detect loops in the JSP (http://www.theserverside.com/news/thread.tss?thread_id=60980).

In fact, you can integrate loops in a JSP with several ways. The EMF model will represent these ways differently.

If you write a scriptlet containing a loop in Java (for, while, ...):

the EMF model created from this JSP will contain a JSPScriptlet object which contains the text of the scriptlet.
The discoverer currently provided by MoDisco does not parse the content of the scriptlet. It will be provided in a future version (after Indigo) by using the Java metamodel to represent the Java fragments contained in a scriptlet.

Another way for looping in a JSP can be achieved by using the "forEach" tag:

In this case, the EMF model will contain a JSPAction object whith the name of the tag ("c:forEach" here):

This EMF object contains children which are the attributes of the tag (var, items, varStatus, ...) and the sub elements of the tag (a JSPAction "c:choose" and an Element "tr"):


2 comments: