views:

35

answers:

2

I have a jsp "template" view in which I am including content from several other jsp's. The content from the other jsp's is being included into a <div> in the template file.

Inside the included jsp's I want to have a hyperlink called "popup" (or whatever). When this link is clicked, then the content of this included jsp is "popped out" of the template jsp and opened into its own window.

e.g.:

template.jsp:

<body>
   <div>
      //include jsp-1.jsp
   </div>
   <div>
      //include jsp-2.jsp
   </div>
</body>

jsp-1.jsp:

<p>
  ...
  <a href="">Pop out</a> //Clicking this will open a new window
                         //containing only the contents of jsp-1.jsp
</p>
A: 

This shouldn't be too hard. I'm not sure if you have it set up so that the browser requests JSP files directly, but if so, something like this should work for you:

jsp-1.jsp:

<p>
  ...
  <a href="/jsp-1.jsp" target="_blank">Pop out</a>
</p>

Edit: re: your comment about losing the CSS and JS files, here's how I've solved this server-side. It's a little ugly, but it works just fine.

template.jsp:

<html>
<head>
...
</head>
<body>
   <c:set var="ContentOnly" value="true" scope="request"/>
   <div>
      <jsp:include page="jsp-1.jsp" />
   </div>
   <div>
      <jsp:include page="jsp-2.jsp" />
   </div>
   <c:remove var="ContentOnly" scope="request"/>
</body>
</html>

jsp-1.jsp:

<c:if test="${(empty ContentOnly) or (not ContentOnly)}">
    <html>
    <head>
    ...
    <!-- jsp-1 required CSS and JS here -->
    <!-- these will only be included when the page is requested as "standalone" -->
    ...
    </head>
    <body>
</c:if>
    ...
    <!-- jsp-1 content here -->
    ...
<c:if test="${(empty ContentOnly) or (not ContentOnly)}">
    </body>
    </html>
</c:if>
Matt Ball
haha..this probably would work..ill try it out. thanks
aeq
the problem is that it looses all of the styles, scripts etc. since its just an html snippet. When displayed inside the template jsp, jsp-1.jsp would grap all this from the template's header. Gotta come up with something around this.
aeq
@aeq: you can fix that either client-side (with some JavaScript) or server-side (with JSTL). If you go for the client side option, you just need a snippet of JS that fetches the missing CSS and JS files from the server, depending on the value of `window.location` or similar. Server-side, I've solved the problem a bit more hackishly (see my answer edit [pending]).
Matt Ball
@aeq: edit's done.
Matt Ball
A: 

use javascript window.open

zod