Is it possible to use Tiles within Springmvc tags?

Asked

Viewed 24 times

1

Hello, I am creating a generic form so that I can parameterize some attributes. I want to do the following :

<sf:form cssClass="form" modelAttribute="<tiles:getAsString name="modelAttribute"/>" action="<tiles:getAsString name="action"/>" />

When I do this however, when loading the screen I get the following exception:

org.apache.jasper.JasperException: /forma-page.jsp (line: 4, column: 81) equal symbol expected

when I don’t use the spring-specific tag, the code works. I would like to use this way to be able to make validations using Beanvalidation.

1 answer

1


You can’t do that.

Of course, sometimes we mix a JSP tag with an HTML tag, but we can’t put a JSP tag inside another JSP tag.

One way to resolve this is to make template attributes available as attributes within JSP and then use them normally in Spring taglib or any other.

An example of how to do this (extracted from the documentation):

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles-extras" prefix="tilesx" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<tilesx:useAttribute id="list" name="items" classname="java.util.List" />
<c:forEach var="item" items="${list}">
  ...
</c:forEach>

In the example above, the tag tilesx:useAttribute causes the name attribute items is made available in the JSP scope as list. The list is then used in the loop using Expression language.

  • Great reply. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.