Tim Withers
Tim Withers

Reputation: 12059

Struts Tiles - Get attributes

To preface this, I do not work with Java or Struts, but I understand what is going on in the code. When it comes to writing the code, I am clueless. I am working with KonaKart, and they use struts tiles to display layouts.

Here is the jsp snippet:

<div class="siderBox noMargin">
    <div class="siderBoxTop"></div>
    <div class="siderBoxContent">
        <tiles:insert attribute="leftTile1" />
    </div>
    <div class="siderBoxBottom"></div>
 </div>

Depending on the current page, leftTile1 may have a value of Empty.jsp which is just an empty page (this is leftTile5 and leftTile6 for example):

<put name="leftTile5" value="/WEB-INF/jsp/InformationTile.jsp"/>
<put name="leftTile6" value="/WEB-INF/jsp/Empty.jsp"/>

If the tile has an empty page, then the box still appears and I am left with all these blank boxes. Is there any way to get the attribute value and not display the tile (ie. if(leftTile1.attribute!="/WEB-INF/jsp/Empty.jsp"){ //show the content; })?

Worst case scenario, I can just go through all 30 jsp files and wrap the content with the header and footer for the tile.

Screenshot of the current output and what I want to get rid of: Blank tiles

Upvotes: 3

Views: 5645

Answers (2)

Tim Withers
Tim Withers

Reputation: 12059

Ultimately this ended up working:

<tiles:importAttribute name="leftTile1" scope="request" />
<logic:notEqual name="leftTile1" value="/WEB-INF/jsp/Empty.jsp">
    <div class="siderBox noMargin">
         <div class="siderBoxTop"></div>
         <div class="siderBoxContent">
              <tiles:insert attribute="leftTile1" />
         </div>
         <div class="siderBoxBottom"></div>
     </div>
</logic:notEqual>

Thanks for your help JB, it got me pointed in the right direction.

Upvotes: 2

JB Nizet
JB Nizet

Reputation: 691765

Not tested, but you could probably define the attribute as an empty string rather than /WEB-INF/jsp/Empty.jsp if nothing must be displayed, and use the following code in your layout:

<tiles:useAttribute name="leftTile1" id="leftTile1"/>
<c:if test="${!empty leftTile1}">
    <div class="siderBoxContent">
        <tiles:insert attribute="leftTile1" />
    </div>
</c:if>

Upvotes: 7

Related Questions