Clean way for conditionally rendering HTML in view?

故事扮演 提交于 2019-12-06 04:15:37

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

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>

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

Without more information, it's hard to answer this, but I'd think instead of separate views: one for admin mode, one for normal mode. Extracting the parts of your pages into tiles will help you do this without a lot of pain; see: http://tiles.apache.org/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!