I’m writing a web page using Struts2.
My need is to show a row in a table only when an boolean attribute of an Action class (ie sectionHidden) is set to false. To do this, I’ve written the following code:
<s:if test="sectionHidden"><tr id="sectionTitle" style="display: none;"></s:if>
<s:else><tr id="sectionTitle"></s:else>
<td>This is the section title</td>
</tr>
I think this is not the best way, are there other better ways to do it? (I would like to avoid to write twice the html code related to the tr)
Basing on your needs,
if you want to crop it, use one
<s:if>to draw (or not) the row as in AleksandrM answer;if instead you want to hide it, but you want it to be in the page (for example for showing it later with javascript, or viewing it in the source), you can use an
<s:if>to apply (or not) the hidden state: