使用Struts2更改页面的行为 [英] Change behavior of a page using Struts2

查看:56
本文介绍了使用Struts2更改页面的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Struts2编写网页.

I'm writing a web page using Struts2.

我需要的是仅在Action类的布尔属性(即sectionHidden)设置为false时才在表中显示一行.为此,我编写了以下代码:

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>

我认为这不是最好的方法,还有其他更好的方法吗? (我想避免重复编写与tr相关的html代码)

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)

推荐答案

根据您的需求,

如果要裁剪,请像在AleksandrM答案中一样使用一个<s:if>绘制(或不绘制)行;

if you want to crop it, use one <s:if> to draw (or not) the row as in AleksandrM answer;

如果您想隐藏它,但又希望它出现在页面中(例如,稍后使用javascript显示它,或在源代码中查看它),则可以使用<s:if>来应用(或不使用) )的隐藏状态:

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:

<tr id="sectionTitle" <s:if test="sectionHidden">style="display: none;"</s:if>>
   <td>This is the section title</td>
</tr>

这篇关于使用Struts2更改页面的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆