JSP Tag : include

JSP Tag : include

  • | Facebook
  • Twitter
  • Delicious
  • print

A jsp tag to extend the possibilities of a simple jsp:include to add contextual resolution.

Section(s): back office, front office, learning

apply  Read also

  • XMS plugin engine
  • XMS JSP page cache

Since the beginning, the engine Wedia XMS ( past named Noheto engine ) has been based on the tag noheto:include to render front and back-office pages by crossing default process and contextual process ( object, role) simply and easilly. The mean of this article it to try to show how this tool is powerfull and how we used it to built our architecture of developpement.

Common way to include JSPs : jsp:include

Let's observe the standart tag jsp:include first.

<jsp:include page="/account.jspz">
  <jsp:param name="username" value="jsmith" />
</jsp:include>


The tag will try to include the JSP with its relative url page /account.jsp with the parameter username=jsmith. So the called url will be /account.jspz?username=jsmith.

Now, if we want to call a field name renderer for a CTObject, we will write :

<jsp:include page="/renderer-name.jspz">
</jsp:include>


If we want to render it in a different way when it is an article :

<c:choose>
  <c:when test="${objectname eq 'article'}">
    <jsp:include page="/renderer-name-for-article.jspz"> 
    </jsp:include>
  </c:when>
  <c:otherwise>
    <jsp:include page="/renderer-name.jspz"> 
    </jsp:include>
  </c:otherwise>
</c:choose>


And if we have to do something different for other objects or other user role (a user won't see the same thing if he is a webmaster ), we will have to create a complex system to render it correctly with it's own bugs and rigidity.

XMS way : noheto:include


The common syntax for noheto:include is :

<noheto:incldude var="[var where the content will be flushed if precised]" 
                 page="[relative path]">
</noheto:include>
 
For example : 
<noheto:include page="/renderer-name.jspz" >
</noheto:include>


For a non contextual include, this tag may seems less powerfull than jsp:include because it does not accept the param tag. Instead of parameters, this tag execute it's body if the asked JSP has not been found (HTTP Error 404 on the requested JSP).

<noheto:include page="/renderer-name.jspz" >
 <%-- JSP Not found, we display the name of the current object without design --%>
 <c:out value="${activeObject.properties[8]}" />
</noheto:include>


An other feature is to look for the requested JSP in differents folders contextualized by :

  • a role with the current surfer roleId
  • an object name passed by a request parameter named form_object

The research of the JSP will be done in this way :

  1. [SAN]/__perso/roles/[surfer role id]/objects/[form_object]/[page path]
  2. [SAN]/__perso/roles/objects/[form_object]/[page path]
  3. [SAN]/__perso/roles/[surfer role id]/[page path]
  4. [SAN]/__perso/[page path]
  5. .. same process in the WebApp WAR but in the folder __default
  6. HTTP Error 404 so : tag's body if exists.

Example :

<noheto:include page="/renderer-name.jspz?form_object=${activeObject.type}" >
 <%-- JSP Not found, we display the name of the current object without design --%>
 <c:out value="${activeObject.properties[8]}" />
</noheto:include>
 
These 4 lines will take care of every case you will have to be comfront.
 
For a general rendering, you can create the JSP 
  [san]/__perso/renderer-name.jsp
 
To provide a specific rendering for article, you have to simply create this JSP :
  [san]/__perso/objects/article/renderer-name.jsp
 
And for a specific rendering for the webmaster, you have to implement these : 
  [san]/__perso/roles/21/renderer-name.jsp
  [san]/__perso/roles/21/objects/article/renderer-name.jsp (because it is also specific for article)

Key for funictionnalities

That's not all, this tag is used by other functionnalities in XMS.
It is used by :

  • as an entry point for plugins
  • as an engine for the JSP page cache

Due to all these points we strongly recommend to only use noheto:include and not jsp:include.