Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JSP Design -- looking for best approach

 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Your mind is under my control .... your will is now mine .... read this tiny ad
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic