在视图中有条件地呈现HTML的干净方式?

问题描述:

在JSP / Struts1设置中有更简洁的方法吗?

Is there a cleaner way to do this in a JSP/Struts1 setup ?

...这里有一些HTML ...

... some HTML here ...

编辑:在管理模式下,我希望能够从表单元素访问其他参数,
例如来自表单元素:

In admin mode I would like to have access to additional parameters from a form element, e.g. from the form element:


input type="text" value="Test user" name="Owner"

编辑2:实际上,我的问题与提出的问题非常相似:按用户在JSP中有条件地渲染

EDIT 2: Actually, my problem is very similar to the question that was asked in : Conditionally Render In JSP By User

但我真的没有得到伪 - 代码来自可能的答案

But I don't really get the "pseudo-code" from the likely answer

SessionConfig 公开为bean在你的JSP中(作为request / session / Struts Form的一部分)?

Is SessionConfig exposed as a bean in your JSP (as part of request / session / Struts Form)?

如果不是,你可以公开它。如果它是一个包含全局设置的静态类(通过它看起来是可能的),你可以创建一个小包装器并将它放在servlet上下文中,然后你可以从Struts标签访问它code>范围= 应用。
一旦完成,您可以通过Struts标签检查您的情况:

If it's not, you can expose it. And if it's a static class containing global settings (which, by the looks of it, is a possibility), you can create a small wrapper and put it in the servlet context which you'd then be able to access from Struts tags as scope="application". Once that's done you can check your condition via Struts tags:

<logic:equal name="sessionConfig" property="adminMode" value="true">
 ... your HTML here
</logic:equal>

或者,如果您使用的是EL / JSTL,可以通过< core:if>

Or, if you're using EL / JSTL, same can be done via <core:if>.