• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Where should the logic be?

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a couple of JSP's that I will be including on several pages via the jsp:include tag. Both of these pages depends on the user being logged in, in order for them to be visible.
So my question is should the logic of whether to include these pages be in the page that is doing the include, ie:
MAJOR PSUEDO CODE HERE
if user logged in
include page
endif
or should the logic be in the pages to be included. ie
if user logged in
<table>
.....
</table>
endif
Where the entire content of the page is in the logic block?
Thanks.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming that the parent page does not require login (since I'd say that you should never get to the includes if the including page requires authentication) I'd say.... it depends.
What a useless answer! Sort of like "cook it until it's done"
Seriously, here's the criteria I'd use to come to the decision:
If the sub-pages can be included in other places (I'm assuming that they are includes because they are modular) where login is not required, then the logged-in-or-not decision is clearly with the parent page since that's where the decision-making context lies.
If these sub-pages must always be authorized, it'd be safest to put the logic in the includes since they might accidentally get included in a parent page that didn't enforce the "rules".
But my own personal choice would probably be to abstract the include into custom tags so that all decision making isn't done on-page at all. (But I know not everyone is comfortable with whipping out tags).
Does this help?
bear
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear. Well, I am using STRUTS logic tag to determine whether or not to display the contents of the page. Is this similar to what you are suggesting along the lines of:
But my own personal choice would probably be to abstract the include into custom tags so that all decision making isn't done on-page at all.
Or is your custome tag doing a bit more?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Similar, expect that 'rolling your own' can give you a higher level of abstraction.
For example:

would be more like

which would do the appropriate thing depending upon context. The distinction is that from the page-point-of-view, the do-I-include-it-or-not decision is completely abstracted away.
I tend to prefer the custom tag route -- but I'm at the point where I can whip out tags pretty fast. Custom tag writing is a great skill to have under your belt, but the learning curve can be a bit daunting. (Though should get easier in JSP2).
Nothing at all wrong with your approach either, imho. Just depends on where you are more comfortable putting the logic.
bear
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Man, I like your approach much better. Of couse, I have 0 experience writing custom tags. I should probably look into that. Thanks for the info Bear.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No prob. Anything to promote better living through abstraction!

bear
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,

I know the post is old...but I have a question. You wrote:

... would be more like



which would do the appropriate thing depending upon context. The distinction is that from the page-point-of-view, the do-I-include-it-or-not decision is completely abstracted away.



I like abstracting things ...but then where is the jsp to include this page? Do you actually write out the html/jsp from within your custom tags using out.print statements? That doesn't seem right...
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Scott Maclary:
but then where is the jsp to include this page?



Theere is no JSP code involved. The custom tag code would include the appropriate file(s) using the RequestDisptacher.include() method.
 
Scott Maclary
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So is it considered bad practice to include HTML in your custom tag?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not necessarily. But building up markup in Java is always rather messy. Under JSP 1.2 it was somehwat unavoidable (though I did write up a little utility that helped). Under JSP 2.0, tag files can take a good deal of that pain away.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic