• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP Design -- looking for best approach  RSS feed

 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am making a jsp project and i am not very much into jsp. Just learning it by now.

My project contains a side panel, which will display navigation depending upon the user status/user role. if there is no user it will display login form, if the user is of "user role" then some links and if it is of "administration" role then some more links.

I was first handling it using a class(htmlUtil), passing it the "user object from session" which checks the logic as described above. but for this i have to use the htmlUtil class on JSP page (mainnavigation.jsp) which was included in index.jsp.

Now, i have changed the logic and put everything that i was doing in htmlUtil class in mainnavigation.jsp.

I want to know which is best approach or there are some alternatives?
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Now, i have changed the logic and put everything that i was doing in htmlUtil class in mainnavigation.jsp.

I want to know which is best approach or there are some alternatives?


Now you ae putting business logic in jsp. This is not better than what you had before.

Depending on your project and how complex and flexible it should be you can adopt different strategies.

You like to dynamically change the side navigation links based on whether there is a user or not or user is an admin. Your login page don't have side navigation.

In the simplest way you can use dynamic includes or static includes to dynamically including the additional links. There could be two separate include files with links. One for regular user and another with extra links for the admin.

If you are not using custom tags, you may have to spit our the call to HtmlUtil as jsp scriplets. For ex:



[include regular user links]
<%
if(HTMLUtil.isUserAdmin(session))
{
%>
[include admin alone links]
<%
}
%>


If you use custom tags you can simply use the custom tags instead of the if statements.

ex:

[include regular user links]
<logic:equal name="User" property="role" value="admin">
[include admin alone links]
</logic:equal>


See how simple it has become. For better maintainability use

[include regular user links]
<logic:equal name="User" property="<%=Constants.ROLE%>" value="<%=Constants.ADMIN%>">
[include admin alone links]
</logic:equal>



Or if you have many pages which need to be fragmented and reused use tiles.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!