Pregunta

I would like to use displaytag in an included page but I have difficulties. I have got a main page which includes a header jspf, a menu jspf and an other jspf depending on the selected menu (on menu.jspf)

main.jspf

<html><body>
<table border="0">
  <tr>
     <td colspan="2"><s:include value="header.jspf"/></td>
  </tr>
  <tr>
     <td><s:include value="menu.jspf"/></td>
     <td><s:include value="%{page}"/></td>
  </tr>
</table>
</body></html>

the "other" jspf (I change the value of 'page' variable in a Struts2 action)

<%@ taglib prefix="display" uri="http://displaytag.sf.net" %>
<%@ taglib prefix="s" uri="/struts-tags" %> 
<html>
<link rel="stylesheet" href="./css/screen.css" type="text/css"/>
<link rel="stylesheet" href="./css/displaytag.css" type="text/css"/>
<body>

   <display:table name="${usageList}" pagesize="2" requestURI="menu_admin_freq.action" sort="list" class="mars">
      <display:column property="nameBackendService" title="BackendService" sortable="true"/>
      <display:column property="frequency" title="Frequency" sortable="true"/>
   </display:table>

</body></html>

As you can see I include a full JSP page which I think is not a good idea... However when I tried to include only a fragment (without the <html> and <body> elements) and put the taglib elements into the main.jsp the displaytag table did not appear... When I removed the <html> and <body> elements and left the taglib one then I could see a text on the webpage : "<%@ taglib prefix="display" uri="http://displaytag.sf.net" %>"

At the moment I have got a working solution (by using <html>, <body> a <%@ taglib> elements in the page that must be included) but I think mine is quite a bad design pattern. How should I sort out this? Thanks, Viktor

¿Fue útil?

Solución

Struts2 <s:include> tag includes a result of servlet or a JSP page. If you want to include JSP fragments use JSP include directive <%@ include file="..." %>.

For using <s:include> tag rename your pages to .jsp and put only taglib directive (w/o <html>, <body>) along with your table to the included pages.

Otros consejos

You should use

<jsp:include page="mySnippet.jsp"/>

where mySnippet.jsp is a partial Jsp, with no DTD, no head, no body, and only the HTML fragment you need.

When needed, declare in it the tag-libraries (struts-tags, etc)...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top