tags:

views:

88

answers:

2

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

<% if (SessionConfig.isAdminMode() ) { %>

... some HTML here ...

<% } %>

EDIT: 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"

EDIT 2: Actually, my problem is very similar to the question that was asked in : http://stackoverflow.com/questions/935666/conditionally-render-in-jsp-by-user

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

+1  A: 

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/

kdgregory
A: 

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>.

ChssPly76
currently, instead of sessionConfig is use MyFormIncludingConfigParametersIn the DynaForm I also have a property adminModeIt works, although the concepts are still a bit cloudy (what scope="application" means, how I coud trigger a non-DynaForm class)
poseid
scope="application" means Struts would look for a bean in ServletContext. It's a part of J2EE spec, you can read about it in Sun's tutorial. For non-DynaForm class, it either has to be defined as form in struts config (it will then automatically be bound to request or session as specified) or you have to manually bind it to request in your action; you can then use the above code replacing 'sessionConfig' with attribute name you've bound it to.
ChssPly76