Re: What is it mean that "Java code does not belong in well designed JSP pages"?
> Debugging code in JSPs is very painful. Debugging tag libraries is the same > as debugging any ordinary Java object. > I pretty much agree with everything Harry says and I do so "in spades" as they say. You can, as a tip, make debugging JSP easier by putting the whole page in a try/catch exception trap. Jack -- -- "You can lead a horse to water but you cannot make it float on its back." ~Dakota Jack~ "You can't wake a person who is pretending to be asleep." ~Native Proverb~ "Each man is good in His sight. It is not necessary for eagles to be crows." ~Hunkesni (Sitting Bull), Hunkpapa Sioux~ --- "This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation." - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: What is it mean that "Java code does not belong in well designed JSP pages"?
> I just read this thread and didn't quite understand > it. If it means what it seems to mean on the surface, > I'm doing everything wrong. I belong to the camp that thinks Java code in JSPs is evil. I happen to think that tag libraries are wonderful. JSPs are HTML documents that are empowered to retrieve information from Java objects. At least that's how I think of them. The focus in a JSP is HTML/CSS presentation and design - all the data should be retrieved, validated and prepared for presentation before you call the JSP. If you work on a large, complex project, you must approach it that way. If you're working on something simple, quick and dirty, then by all means do all your coding in JSPs - that's what makes them cool. Debugging code in JSPs is very painful. Debugging tag libraries is the same as debugging any ordinary Java object. HTH Harry Mantheakis - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: What is it mean that "Java code does not belong in well designed JSP pages"?
On Sun, 23 Jan 2005 12:09:39 -0800 (PST), Dola Woolfe <[EMAIL PROTECTED]> wrote: > On the subject of your hope that "this engenders a > long" can the English be fixed in the subject before > this is archived? It's embarrassing. Too late. Don't worry about it. What we type in here rarely has much to do with our real understanding of English. I don't bother to change a lot and assume the regular corrections for others as well. Jack -- -- "You can lead a horse to water but you cannot make it float on its back." ~Dakota Jack~ "You can't wake a person who is pretending to be asleep." ~Native Proverb~ "Each man is good in His sight. It is not necessary for eagles to be crows." ~Hunkesni (Sitting Bull), Hunkpapa Sioux~ --- "This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation." - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: What is it mean that "Java code does not belong in well designed JSP pages"?
provides. Some logic does belong in JSP. However, the logic that appears within pages should be limited to display logic. I've found that Struts and JSTL are a great combination to accomplish such separation. IMHO this is basically the essence of "Java code does no belong in well designed JSP pages" Keep the MVC separation in order not to clutter your view (e.g. JSP) with business logic. That can be achieved with various frameworks like Struts. Whenever you "need" code, think of Struts Taglibs or JSTL first. Usually this is sufficient for all the "legal code" in JSPs. That is "display logic" like reformating values for displayment that were calculated in your business logic elsewhere. E.g. iteration over lists, colorize things, whatever. This will reduce your JSP's Java code to "snippets" of just a few lines. Of course, with custom taglibs even that could be reduced to zero, but that's usually not worth the effort (if not reusable). Or don't use JSP at all (but if so, bundle with Struts)... Tapestry is also good to separate view and business logic, at least if you don't put to much OGNL in your html templates ;-) That's as worse as too much Java code and EL in JSPs. Cheers, Michael - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: What is it mean that "Java code does not belong in well designed JSP pages"?
I work in a shop similar to the one you describe where individuals are forced to fill multiple roles. I'm called upon to implement everything from domain models to navigation menus. However, I find that keeping the Java code that appears in JSP to a minimum helps in this situation as well. Although I am completely capable of wearing multiple hats, I do feel that we all benefit from practices that limit the amount of time we have to wear all those hats at once. I would also argue the quality of our work benefits from the increased level of focus such discipline provides. Some logic does belong in JSP. However, the logic that appears within pages should be limited to display logic. I've found that Struts and JSTL are a great combination to accomplish such separation. -Sean On Sun, 2005-01-23 at 10:45 -0500, Frank W. Zammetti wrote: > I certainly wouldn't presume to speak for Craig, so this is just my own > answer... > > Scriplets, that is, code in JSPs inside <% %>, is generally considered a > Bad Thing(tm) because it's too easy for business logic to sneak into the > presentation. > > Now, there is I think room for debate about how far to push that idea. > Some people think that a JSP should be absolutely nothing more than a > template for display, so you should wind up with nothing but things like > <$=someVar%>, or more "correctly", something like name="myBean" property="myVar" />. > > However, where there is room for debate is whether using any sort of > logic whatsoever in a JSP is bad or not. Taking the "JSP as a template > only" idea to it's fullest extent seems to me to imply that logic in ANY > form is to be avoided, and should not be done in a JSP, whether it's > using taglibs or not to do it (i.e., shouldn't even be > used because it's logic). I think this is too extreme and limits the > types of applications you can do... try doing the kinds of apps I do for > a living for example, which are webapps that look, feel and work like > fat clients, and you'll be hard-pressed to pull off the kinds of things > I do without some level of logic in JSPs. > > That being said, good design dictates that you need to be careful what > gets put in your JSPs, whether you use custom tags or not (I'm not a fan > of custom tags myself in most cases). Business logic does NOT belong in > JSPs, and indeed anything other than trivial bits of code probably > shouldn't be there either. > > I'm not entirely sure what the code you posted is doing, but my gut > feeling is that it's too much for a JSP. I do things like this all the > time; > > <% >boolean altRow = false; >String rowStyle = ""; >for (Iterator it = form.getTOAList().iterator(); it.hasNext(); ) { > if (altRow) { >rowStyle = "cssListboxAltRow"; >altRow = false; > } else { >rowStyle = ""; >altRow = true; > } > HashMap nextItem = (HashMap)it.next(); > BigDecimal toaID = (BigDecimal)nextItem.get("toaID"); > String status = (String)nextItem.get("status"); > %> > ><%=status%> ><%=toaID%> > > <% >} > %> > > ...and some will say that's way too much... let's skip the "this should > be a custom tag!" argument for the time being... This kind of code I see > no problem with being in a JSP. It's strictly presentation-oriented, > and isn't extensive. > > That being said, NOW we can get to the "this shouldn't be there at all" > argument... it is a perfectly reasonable argument. In an environment > where you have page authors and Java coders, you don't want your page > authors to have to see code like that. In fact, in the "perfect" > environment where it's split exactly right, they wouldn't even know what > this code meant. But, if you had a custom tag that encapsulated that > functionality, they could just put and be done with it. > That's the argument for taglibs (the main one anyway). > > However, you have to ask yourself what kind of environment your in... I > dare say most environments are NOT set up that way... maybe they should > be, but I don't think the majority are... most places, your page authors > are your Java coders are your database developers are your business > analysts, etc. In that case, I think the argument doesn't carry as much > weight. > > Eh, I guess I'm off on a bit of a tangent. Most people will tell you > that code in JSPs is to be avoided, and I'm not going out of my way to > debate that. But, I think it's fair to say that if you do have code in > JSPs, it should be (a) trivial and (b) strictly presentation-related. > Breaking THOSE rules, which by extension breaks the higher rules, is to > be avoided at all costs. Just my opinions. > > -- > Frank W. Zammetti > Founder and Chief Software Architect > Omnytex Technologies > http://www.omnytex.com > > Dola Woolfe wrote: > > I just read this thread and didn't quite understand > > it. If it means what it seems to mean on t
Re: What is it mean that "Java code does not belong in well designed JSP pages"?
I'm quite late to this thread, so I'll stick to answering the one technical question: On Sun, Jan 23, 2005 at 12:03:36PM -0800, Dola Woolfe wrote: : the code changes, the app needs to be restarted. The : project I work with takes 2 min to start up so this is : prohibitive There's a "reloadable" attr on the Tomcat config's tag. Set this to "true" while you're in development mode to make the container periodically check for changes in WEB-INF/classes and reload accordingly. It may also check under WEB-INF/lib, I don't recall... : Sometimes for development purposes I dumb : it down so it takes 10 sec to start up but it is still : a pain. Am I saying anything that indicates that I'm : .doing things wrong? "Wrong" is too strong a term here; but some would argue that you may not have to tweak the servlets so much if you were to formally separate calls to business logic (servlets, which require a container restart) and formatting/presentation (JSPs, which are automatically rebuilt when changed). In my experience, the servlet layer is pretty thin and simple; it's getting the final content *just right* that can require several edits to a file. I don't mean for this to sound flippant. A lot of the good ideas and best practices are based on starting an app from scratch. When you're migrating an existing app -- and in your case, across two servlet spec revisions -- it can be tough. You sometimes have to decide whether it's worth a hefty refactoring effort or starting over from scratch. -QM -- software -- http://www.brandxdev.net tech news -- http://www.RoarNetworX.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: What is it mean that "Java code does not belong in well designed JSP pages"?
On the subject of your hope that "this engenders a long" can the English be fixed in the subject before this is archived? It's embarrassing. --- Dakota Jack <[EMAIL PROTECTED]> wrote: > There are lots of reasons why this is not the way to > code JSPs, Dola. > Let's start with one: REUSABILITY. > > If I can read "between the lines" in your code, you > are essentially > using these classes to write HTML in sort of a Tiles > way. This is > clearly a good thing and your ideas might be really > worthwhile. That > is not at issue in what I have to say. I am also > not, at the moment, > talking about the <%= whatever %> expression code, > but rather only > the <% whatever %> scriptlet code. You don't use > <%! whatever %. > declaration code. > > The only way to reuse the code you wrote is to copy > and paste. (Often > this is called "cut and paste" which makes no > sense.) If you > consolidated and generalized the code off the page > in some, say, > Process class, then you could have something like > <%= > Process().process([whatever]) %> where "whatever" > represents what is > peculiar to this page alone and what is common to > all like pages is > included in the off-JSP-page Process process method > code. > > If you only made this change, then your page person, > which might be > the same person, would only have to write > > <%= Process.process([whatever]) %> > > on each page and would not have to write the code > elsewhere either > because that would already have been abstracted and > done. > > If we cannot all agree this is progress, then we > probably cannot agree > on the whole idea of getting code off the page at > all. > > I also like what Tim had to say because he > recognizes that sometimes > we have to write the particular code and abstract > later as a business > decision. However, he does it in a way that > recognizes that adhering > as close to the principles of OOP as possible will > make the later > transition easy when duplicating code becomes an > issue. > > I hope this helps. Let me say that I find that the > principles of OOP > can be defended and need not be adhered to out of > blind faith. It is > better to find out what is up than to just follow > the dictates of > whomever. Once again, good question. I hope this > engenders a long > and useful thread. If it did, we could save a lot > of "ink" on the > list. > > Jack > > > On Sun, 23 Jan 2005 07:07:21 -0800 (PST), Dola > Woolfe > <[EMAIL PROTECTED]> wrote: > > I just read this thread and didn't quite > understand > > it. If it means what it seems to mean on the > surface, > > I'm doing everything wrong. > > > > Schematically, my typical JSP page looks like the > > following (basically 100% code). Is this what > Craig is > > advising against? > > > > <%@ page errorPage="ErrorPage.jsp" > import="html.*"%> > > <[EMAIL PROTECTED] file="InitializePage.jsp"%> > > <% > > Table table = new Table() > > .pAddH("#").pAddH("Action").pLN() > > .pAddC("1").pAddL(new Anchor("HelloPage.jsp", > "Say > > hello to my friend.")).pLN() > > .pAddC("2").pAddL(new > Anchor("GoodByePage.jsp", > > "Say good bye to my friend")).pLN() > > ; > > > > MyTemplate template = new MyTemplate ("Main > > Actions", table); > > Page pAgE = new Page(new MyHead("Data Tools"), > new > > Body(template)); > > %> > > > > <%= pAgE %> > > > > __ > > Do you Yahoo!? > > Read only the mail you want - Yahoo! Mail > SpamGuard. > > http://promotions.yahoo.com/new_mail > > > > > - > > To unsubscribe, e-mail: > [EMAIL PROTECTED] > > For additional commands, e-mail: > [EMAIL PROTECTED] > > > > > > > -- > -- > > "You can lead a horse to water but you cannot make > it float on its back." > > ~Dakota Jack~ > > "You can't wake a person who is pretending to be > asleep." > > ~Native Proverb~ > > "Each man is good in His sight. It is not necessary > for eagles to be crows." > > ~Hunkesni (Sitting Bull), Hunkpapa Sioux~ > > --- > > "This message may contain confidential and/or > privileged information. > If you are not the addressee or authorized to > receive this for the > addressee, you must not use, copy, disclose, or take > any action based > on this message or any information herein. If you > have received this > message in error, please advise the sender > immediately by reply e-mail > and delete this message. Thank you for your > cooperation." > > - > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > > __ Do you Yahoo!? Yahoo! Mail - You care about security. So do we. http://promotions.yahoo.com/new_mail - T
Re: What is it mean that "Java code does not belong in well designed JSP pages"?
Thank you for the useful responses. I agree with the person (sorry, tough to both type and look up names...) who said that I wrote enough code for it to be a servlet. In fact, I would rather write a servlet! This is because I prefer to work with JBuilder and JBuilder does an OK job aligning and code completing .java files (about 80% of what Emacs' performance) and an outright lousy working with .jsp pages. But there are such tremendous barriers to entry with a servlet. You need (or maybe things got better) to modify web.xml and restart the app. Then every time the code changes, the app needs to be restarted. The project I work with takes 2 min to start up so this is prohibitive. Sometimes for development purposes I dumb it down so it takes 10 sec to start up but it is still a pain. Am I saying anything that indicates that I'm doing things wrong? The one thing that I can't imagine being the right thing to do (for me) is writing html code. Just switching 2 rows in a table is enough to send me into a panic. And you don't find out that you made a mistake until you view the page. That's why I use an html library with classes like Table, Page, Body, Form.Button, Anchor, etc. Again any comments? I truly enjoy reading the dicussion that I started. --- Parsons Technical Services <[EMAIL PROTECTED]> wrote: > Don't ask to see my code. All I know is it works > most of the time. > > Really, I think it is a matter of circumstance. Each > case is different and > allows for sway from one extreme to the other. > > One word of caution to people just learning, is that > as you move from > company to company expect to see a wide variety of > philosophy about how > something is done. So it is wise to understand each > approach and it's pros > and cons. I work for myself and I am still trying to > understand the approach > here. > > So what you will most likely find is that people > will take the most direct > path that the environment and knowledge will allow. > Of course there are > always the exceptions. > > Dola don't get too tied up in "proper" approaches as > much as understanding > the whys and why not to do it that way. As you code > things you will always > see a different or better way after you are almost > done. > > Doug > > > - Original Message ----- > From: "Frank W. Zammetti" <[EMAIL PROTECTED]> > To: "Tomcat Users List" > > Sent: Sunday, January 23, 2005 1:22 PM > Subject: Re: What is it mean that "Java code does > not belong in well > designed JSP pages"? > > > > That's a good point Tim... I have to admit I've > only used methods a couple > > of times in JSPs, generally preferring all the > code be inline (except > > where there would be a lot of duplication, then I > tend to make utility > > classes). You make a good point though, I may > start getting into that > > habit myself :) > > > > -- > > Frank W. Zammetti > > Founder and Chief Software Architect > > Omnytex Technologies > > http://www.omnytex.com > > > > Tim Funk wrote: > >> Essentially you have written a servlet but > packaged it as a JSP. Anytime > >> it becomes a trivial effort to hand transform a > JSP into a servlet > >> usually means some refactoring is in order. > >> > >> Personally I do not mind java code in JSP's but > only if its structured. I > >> try not to rely on in-line java code - but I try > to use methods or inner > >> classes for most java coding in a JSP. By doing > that - it becomes easier > >> to rip the methods and inner classes from the JPS > page and into an > >> independent object. By doing this - I get rapid > turnaround - but don't > >> code myself in a hole for when new functionality > might be needed that > >> might overlap existing pages. > >> > >> -Tim > >> > >> Dola Woolfe wrote: > >> > >>> I just read this thread and didn't quite > understand > >>> it. If it means what it seems to mean on the > surface, > >>> I'm doing everything wrong. > >>> > >>> Schematically, my typical JSP page looks like > the > >>> following (basically 100% code). Is this what > Craig is > >>> advising against? > >>> > >>> <%@ page errorPage="ErrorPage.jsp" > import="html.*"%> > >>> <[EMAIL PROTECTED] file="InitializePage.jsp"%> > >>> <% > >>> Table table = new Table() > >
Re: What is it mean that "Java code does not belong in well designed JSP pages"?
There are lots of reasons why this is not the way to code JSPs, Dola. Let's start with one: REUSABILITY. If I can read "between the lines" in your code, you are essentially using these classes to write HTML in sort of a Tiles way. This is clearly a good thing and your ideas might be really worthwhile. That is not at issue in what I have to say. I am also not, at the moment, talking about the <%= whatever %> expression code, but rather only the <% whatever %> scriptlet code. You don't use <%! whatever %. declaration code. The only way to reuse the code you wrote is to copy and paste. (Often this is called "cut and paste" which makes no sense.) If you consolidated and generalized the code off the page in some, say, Process class, then you could have something like <%= Process().process([whatever]) %> where "whatever" represents what is peculiar to this page alone and what is common to all like pages is included in the off-JSP-page Process process method code. If you only made this change, then your page person, which might be the same person, would only have to write <%= Process.process([whatever]) %> on each page and would not have to write the code elsewhere either because that would already have been abstracted and done. If we cannot all agree this is progress, then we probably cannot agree on the whole idea of getting code off the page at all. I also like what Tim had to say because he recognizes that sometimes we have to write the particular code and abstract later as a business decision. However, he does it in a way that recognizes that adhering as close to the principles of OOP as possible will make the later transition easy when duplicating code becomes an issue. I hope this helps. Let me say that I find that the principles of OOP can be defended and need not be adhered to out of blind faith. It is better to find out what is up than to just follow the dictates of whomever. Once again, good question. I hope this engenders a long and useful thread. If it did, we could save a lot of "ink" on the list. Jack On Sun, 23 Jan 2005 07:07:21 -0800 (PST), Dola Woolfe <[EMAIL PROTECTED]> wrote: > I just read this thread and didn't quite understand > it. If it means what it seems to mean on the surface, > I'm doing everything wrong. > > Schematically, my typical JSP page looks like the > following (basically 100% code). Is this what Craig is > advising against? > > <%@ page errorPage="ErrorPage.jsp" import="html.*"%> > <[EMAIL PROTECTED] file="InitializePage.jsp"%> > <% > Table table = new Table() > .pAddH("#").pAddH("Action").pLN() > .pAddC("1").pAddL(new Anchor("HelloPage.jsp", "Say > hello to my friend.")).pLN() > .pAddC("2").pAddL(new Anchor("GoodByePage.jsp", > "Say good bye to my friend")).pLN() > ; > > MyTemplate template = new MyTemplate ("Main > Actions", table); > Page pAgE = new Page(new MyHead("Data Tools"), new > Body(template)); > %> > > <%= pAgE %> > > __ > Do you Yahoo!? > Read only the mail you want - Yahoo! Mail SpamGuard. > http://promotions.yahoo.com/new_mail > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- -- "You can lead a horse to water but you cannot make it float on its back." ~Dakota Jack~ "You can't wake a person who is pretending to be asleep." ~Native Proverb~ "Each man is good in His sight. It is not necessary for eagles to be crows." ~Hunkesni (Sitting Bull), Hunkpapa Sioux~ --- "This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation." - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: What is it mean that "Java code does not belong in well designed JSP pages"?
Don't ask to see my code. All I know is it works most of the time. Really, I think it is a matter of circumstance. Each case is different and allows for sway from one extreme to the other. One word of caution to people just learning, is that as you move from company to company expect to see a wide variety of philosophy about how something is done. So it is wise to understand each approach and it's pros and cons. I work for myself and I am still trying to understand the approach here. So what you will most likely find is that people will take the most direct path that the environment and knowledge will allow. Of course there are always the exceptions. Dola don't get too tied up in "proper" approaches as much as understanding the whys and why not to do it that way. As you code things you will always see a different or better way after you are almost done. Doug - Original Message - From: "Frank W. Zammetti" <[EMAIL PROTECTED]> To: "Tomcat Users List" Sent: Sunday, January 23, 2005 1:22 PM Subject: Re: What is it mean that "Java code does not belong in well designed JSP pages"? That's a good point Tim... I have to admit I've only used methods a couple of times in JSPs, generally preferring all the code be inline (except where there would be a lot of duplication, then I tend to make utility classes). You make a good point though, I may start getting into that habit myself :) -- Frank W. Zammetti Founder and Chief Software Architect Omnytex Technologies http://www.omnytex.com Tim Funk wrote: Essentially you have written a servlet but packaged it as a JSP. Anytime it becomes a trivial effort to hand transform a JSP into a servlet usually means some refactoring is in order. Personally I do not mind java code in JSP's but only if its structured. I try not to rely on in-line java code - but I try to use methods or inner classes for most java coding in a JSP. By doing that - it becomes easier to rip the methods and inner classes from the JPS page and into an independent object. By doing this - I get rapid turnaround - but don't code myself in a hole for when new functionality might be needed that might overlap existing pages. -Tim Dola Woolfe wrote: I just read this thread and didn't quite understand it. If it means what it seems to mean on the surface, I'm doing everything wrong. Schematically, my typical JSP page looks like the following (basically 100% code). Is this what Craig is advising against? <%@ page errorPage="ErrorPage.jsp" import="html.*"%> <[EMAIL PROTECTED] file="InitializePage.jsp"%> <% Table table = new Table() .pAddH("#").pAddH("Action").pLN() .pAddC("1").pAddL(new Anchor("HelloPage.jsp", "Say hello to my friend.")).pLN() .pAddC("2").pAddL(new Anchor("GoodByePage.jsp", "Say good bye to my friend")).pLN() ; MyTemplate template = new MyTemplate ("Main Actions", table); Page pAgE = new Page(new MyHead("Data Tools"), new Body(template)); %> <%= pAgE %> __ Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. http://promotions.yahoo.com/new_mail - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: What is it mean that "Java code does not belong in well designed JSP pages"?
That's a good point Tim... I have to admit I've only used methods a couple of times in JSPs, generally preferring all the code be inline (except where there would be a lot of duplication, then I tend to make utility classes). You make a good point though, I may start getting into that habit myself :) -- Frank W. Zammetti Founder and Chief Software Architect Omnytex Technologies http://www.omnytex.com Tim Funk wrote: Essentially you have written a servlet but packaged it as a JSP. Anytime it becomes a trivial effort to hand transform a JSP into a servlet usually means some refactoring is in order. Personally I do not mind java code in JSP's but only if its structured. I try not to rely on in-line java code - but I try to use methods or inner classes for most java coding in a JSP. By doing that - it becomes easier to rip the methods and inner classes from the JPS page and into an independent object. By doing this - I get rapid turnaround - but don't code myself in a hole for when new functionality might be needed that might overlap existing pages. -Tim Dola Woolfe wrote: I just read this thread and didn't quite understand it. If it means what it seems to mean on the surface, I'm doing everything wrong. Schematically, my typical JSP page looks like the following (basically 100% code). Is this what Craig is advising against? <%@ page errorPage="ErrorPage.jsp" import="html.*"%> <[EMAIL PROTECTED] file="InitializePage.jsp"%> <% Table table = new Table() .pAddH("#").pAddH("Action").pLN() .pAddC("1").pAddL(new Anchor("HelloPage.jsp", "Say hello to my friend.")).pLN() .pAddC("2").pAddL(new Anchor("GoodByePage.jsp", "Say good bye to my friend")).pLN() ; MyTemplate template = new MyTemplate ("Main Actions", table); Page pAgE = new Page(new MyHead("Data Tools"), new Body(template)); %> <%= pAgE %> __ Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. http://promotions.yahoo.com/new_mail - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: What is it mean that "Java code does not belong in well designed JSP pages"?
Essentially you have written a servlet but packaged it as a JSP. Anytime it becomes a trivial effort to hand transform a JSP into a servlet usually means some refactoring is in order. Personally I do not mind java code in JSP's but only if its structured. I try not to rely on in-line java code - but I try to use methods or inner classes for most java coding in a JSP. By doing that - it becomes easier to rip the methods and inner classes from the JPS page and into an independent object. By doing this - I get rapid turnaround - but don't code myself in a hole for when new functionality might be needed that might overlap existing pages. -Tim Dola Woolfe wrote: I just read this thread and didn't quite understand it. If it means what it seems to mean on the surface, I'm doing everything wrong. Schematically, my typical JSP page looks like the following (basically 100% code). Is this what Craig is advising against? <%@ page errorPage="ErrorPage.jsp" import="html.*"%> <[EMAIL PROTECTED] file="InitializePage.jsp"%> <% Table table = new Table() .pAddH("#").pAddH("Action").pLN() .pAddC("1").pAddL(new Anchor("HelloPage.jsp", "Say hello to my friend.")).pLN() .pAddC("2").pAddL(new Anchor("GoodByePage.jsp", "Say good bye to my friend")).pLN() ; MyTemplate template = new MyTemplate ("Main Actions", table); Page pAgE = new Page(new MyHead("Data Tools"), new Body(template)); %> <%= pAgE %> __ Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. http://promotions.yahoo.com/new_mail - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: What is it mean that "Java code does not belong in well designed JSP pages"?
David Johnson wrote: Using taglibs instead of code adds a level of obfuscation that, IMHO, makes it difficult to get work done. I always end up taking the servlet that was generated from the JSP and rewriting it so it works correctly, performs adequately, and generates no side effects. This has always been my biggest problems with taglibs too, that and the fact that it's yet something else a new developer coming on to a project has to learn before they can be effective (or at least optimally effective). I prefer all the code being right there in front of me, not having to go hunt down source somewhere. Additionally, I don't like having to recompile a class to make a change and then redeploy the class (or worse yet, the whole app). If it's just in a JSP, I can update the app on-the-fly (assuming JSP compilation is still active). That being said, I actually like the idea of Tag Files. It's not quite as bad, it's no worse than a JSP include, although the point about more to learn still stands. But, then it's just usual JSP code, which they would already know, so it's still not quite as bad in that regard either. It's kind of amazing that a lot of people don't even know about that capability. Like you said though, what works in one environment may not work in another, and taking a hard stand either way is a bad idea. Heck, I've used taglibs on plenty of occasions and it's worked out beautifully. Right tool for the job and all that jazz, right?!? -- Frank W. Zammetti Founder and Chief Software Architect Omnytex Technologies http://www.omnytex.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: What is it mean that "Java code does not belong in well designed JSP pages"?
The intent of JSP is that it is primarily HTML with just enough Java to make things work. Ideally, you can hand a JSP to a web designer who is not a programmer and they can make a pretty web page that works. In some shops this works. As a productivity booster, this works in some shops. But in others it is a miserable failure. With that being said, my _personal_ experience is that programming in HTML tags is a pain in the <%taglib/>. I don't have a problem learning another language to do a job - I regularly use COBOL, Pascal, Java, and SQL in any single project. Adding a JSP front end adds JavaScript, a couple of XML namespaces, and HTML to the mix. Using taglibs instead of code adds a level of obfuscation that, IMHO, makes it difficult to get work done. I always end up taking the servlet that was generated from the JSP and rewriting it so it works correctly, performs adequately, and generates no side effects. This is a battle that will never be resolved because both sides are right, depending on the circumstances. JSP purists will shoot me, but I'll take plain old Java code over HTML taglibs any day. Write JSP's in accordance with your shop's standards and make them work in the time allotted to the task. Ultimately, your company pays the bills, so whatever gives your shop the best productivity is the "right" choice. On Sun, 2005-01-23 at 09:07, Dola Woolfe wrote: > > I just read this thread and didn't quite understand > it. If it means what it seems to mean on the surface, > I'm doing everything wrong. > > Schematically, my typical JSP page looks like the > following (basically 100% code). Is this what Craig is > advising against? > > <%@ page errorPage="ErrorPage.jsp" import="html.*"%> > <[EMAIL PROTECTED] file="InitializePage.jsp"%> > <% > Table table = new Table() > .pAddH("#").pAddH("Action").pLN() > .pAddC("1").pAddL(new Anchor("HelloPage.jsp", "Say > hello to my friend.")).pLN() > .pAddC("2").pAddL(new Anchor("GoodByePage.jsp", > "Say good bye to my friend")).pLN() > ; > > MyTemplate template = new MyTemplate ("Main > Actions", table); > Page pAgE = new Page(new MyHead("Data Tools"), new > Body(template)); > %> > > <%= pAgE %> > > > > __ > Do you Yahoo!? > Read only the mail you want - Yahoo! Mail SpamGuard. > http://promotions.yahoo.com/new_mail > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: What is it mean that "Java code does not belong in well designed JSP pages"?
I certainly wouldn't presume to speak for Craig, so this is just my own answer... Scriplets, that is, code in JSPs inside <% %>, is generally considered a Bad Thing(tm) because it's too easy for business logic to sneak into the presentation. Now, there is I think room for debate about how far to push that idea. Some people think that a JSP should be absolutely nothing more than a template for display, so you should wind up with nothing but things like <$=someVar%>, or more "correctly", something like . However, where there is room for debate is whether using any sort of logic whatsoever in a JSP is bad or not. Taking the "JSP as a template only" idea to it's fullest extent seems to me to imply that logic in ANY form is to be avoided, and should not be done in a JSP, whether it's using taglibs or not to do it (i.e., shouldn't even be used because it's logic). I think this is too extreme and limits the types of applications you can do... try doing the kinds of apps I do for a living for example, which are webapps that look, feel and work like fat clients, and you'll be hard-pressed to pull off the kinds of things I do without some level of logic in JSPs. That being said, good design dictates that you need to be careful what gets put in your JSPs, whether you use custom tags or not (I'm not a fan of custom tags myself in most cases). Business logic does NOT belong in JSPs, and indeed anything other than trivial bits of code probably shouldn't be there either. I'm not entirely sure what the code you posted is doing, but my gut feeling is that it's too much for a JSP. I do things like this all the time; <% boolean altRow = false; String rowStyle = ""; for (Iterator it = form.getTOAList().iterator(); it.hasNext(); ) { if (altRow) { rowStyle = "cssListboxAltRow"; altRow = false; } else { rowStyle = ""; altRow = true; } HashMap nextItem = (HashMap)it.next(); BigDecimal toaID = (BigDecimal)nextItem.get("toaID"); String status = (String)nextItem.get("status"); %> <%=status%> <%=toaID%> <% } %> ...and some will say that's way too much... let's skip the "this should be a custom tag!" argument for the time being... This kind of code I see no problem with being in a JSP. It's strictly presentation-oriented, and isn't extensive. That being said, NOW we can get to the "this shouldn't be there at all" argument... it is a perfectly reasonable argument. In an environment where you have page authors and Java coders, you don't want your page authors to have to see code like that. In fact, in the "perfect" environment where it's split exactly right, they wouldn't even know what this code meant. But, if you had a custom tag that encapsulated that functionality, they could just put and be done with it. That's the argument for taglibs (the main one anyway). However, you have to ask yourself what kind of environment your in... I dare say most environments are NOT set up that way... maybe they should be, but I don't think the majority are... most places, your page authors are your Java coders are your database developers are your business analysts, etc. In that case, I think the argument doesn't carry as much weight. Eh, I guess I'm off on a bit of a tangent. Most people will tell you that code in JSPs is to be avoided, and I'm not going out of my way to debate that. But, I think it's fair to say that if you do have code in JSPs, it should be (a) trivial and (b) strictly presentation-related. Breaking THOSE rules, which by extension breaks the higher rules, is to be avoided at all costs. Just my opinions. -- Frank W. Zammetti Founder and Chief Software Architect Omnytex Technologies http://www.omnytex.com Dola Woolfe wrote: I just read this thread and didn't quite understand it. If it means what it seems to mean on the surface, I'm doing everything wrong. Schematically, my typical JSP page looks like the following (basically 100% code). Is this what Craig is advising against? <%@ page errorPage="ErrorPage.jsp" import="html.*"%> <[EMAIL PROTECTED] file="InitializePage.jsp"%> <% Table table = new Table() .pAddH("#").pAddH("Action").pLN() .pAddC("1").pAddL(new Anchor("HelloPage.jsp", "Say hello to my friend.")).pLN() .pAddC("2").pAddL(new Anchor("GoodByePage.jsp", "Say good bye to my friend")).pLN() ; MyTemplate template = new MyTemplate ("Main Actions", table); Page pAgE = new Page(new MyHead("Data Tools"), new Body(template)); %> <%= pAgE %> __ Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. http://promotions.yahoo.com/new_mail - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] . - To unsubscribe, e-mail: [EMAIL PROTECTED] For add
What is it mean that "Java code does not belong in well designed JSP pages"?
I just read this thread and didn't quite understand it. If it means what it seems to mean on the surface, I'm doing everything wrong. Schematically, my typical JSP page looks like the following (basically 100% code). Is this what Craig is advising against? <%@ page errorPage="ErrorPage.jsp" import="html.*"%> <[EMAIL PROTECTED] file="InitializePage.jsp"%> <% Table table = new Table() .pAddH("#").pAddH("Action").pLN() .pAddC("1").pAddL(new Anchor("HelloPage.jsp", "Say hello to my friend.")).pLN() .pAddC("2").pAddL(new Anchor("GoodByePage.jsp", "Say good bye to my friend")).pLN() ; MyTemplate template = new MyTemplate ("Main Actions", table); Page pAgE = new Page(new MyHead("Data Tools"), new Body(template)); %> <%= pAgE %> __ Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. http://promotions.yahoo.com/new_mail - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]