Discussion:
Validating JSP EL
Ross Bleakney
2014-01-13 20:01:18 UTC
Permalink
Hello SeaJug,
It has been a while since I've done JSP, and I'm doing some now. I'm hoping someone knows of a tool (ideally a plugin) which can be used to help validate the expression language calls inside the JSP. Here is an example:

My Java Code:

public class HappyBean {
private boolean good;

public boolean isGood() {
return good;
}

public void setGood(boolean good) {
this.good = good;
}
}

My JSP:

<c:if test="${happyBean.good}">
<c:out value="${happyBean.notThere}" />
</c:if>

If happyBean.good is false, then everything works just fine. But when happyBean.good is true, I get a run time error. I don't like run time errors. So, I was hoping there would be some validation code I could run on the JSP which would tell me

"Hey, you don't have a method called 'getNotThere', are you sure you know what you are doing"

Any other tips are appreciated (please don't tell me to use anything besides JSP).

Thanks,
Ross
dev danke
2014-01-13 21:24:59 UTC
Permalink
JSPs can be validated by compiling them into Java. The links below show
how to pre-compile JSPs with Maven or Ant.

https://tomcat.apache.org/tomcat-6.0-doc/jasper-howto.html#Web_Application_Compilation

http://blog.cliffano.com/2006/08/16/jsp-precompilation-for-maven2-project/
Post by Ross Bleakney
Hello SeaJug,
It has been a while since I've done JSP, and I'm doing some now. I'm
hoping someone knows of a tool (ideally a plugin) which can be used to help
public class HappyBean {
private boolean good;
public boolean isGood() {
return good;
}
public void setGood(boolean good) {
this.good = good;
}
}
<c:if test="${happyBean.good}">
<c:out value="${happyBean.notThere}" />
</c:if>
If happyBean.good is false, then everything works just fine. But when
happyBean.good is true, I get a run time error. I don't like run time
errors. So, I was hoping there would be some validation code I could run on
the JSP which would tell me
"Hey, you don't have a method called 'getNotThere', are you sure you
know what you are doing"
Any other tips are appreciated (please don't tell me to use anything besides JSP).
Thanks,
Ross
Ross Bleakney
2014-01-14 03:24:19 UTC
Permalink
Thanks, but that's not the problem. The code compiles just fine either way. This is a run time error that only occurs if the code enters (and executes) that block. That is why changing one JSP value from "false" to "true" causes the problem. The Java code is something like this:

_jspx_th_c_005fout_005f0.setValue((java.lang.Object) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${happyBean.notThere}", ...

This value is evaluated and executed dynamically (I assume using reflection). What I want is for it to do that evaluation ahead of time, in each line that contains EL JSP. I could write my own EL interpreter which calculates the bean values from the Java or the JSP code but I assume there is some utility out there that does that. Again, it would not have to be 100% (EL is fairly dynamic, so it might be difficult to be 100%) but something that would warn me would be very good. I have to assume there is something out there, but unfortunately when I search, I often find references to Eclipse being too stringent about the JSP (a problem that apparently occurred a while ago when JSTL was switching versions). I've tried having Eclipse validate the JSP files and it has no problem with them (probably because they all compile, the HTML is OK, etc.).

Thanks,
Ross


To: seajug-***@public.gmane.org
From: devdanke-***@public.gmane.org
Date: Mon, 13 Jan 2014 13:24:59 -0800
Subject: Re: [seajug] Validating JSP EL


























JSPs can be validated by compiling them into Java. The links below show how to pre-compile JSPs with Maven or Ant.

https://tomcat.apache.org/tomcat-6.0-doc/jasper-howto.html#Web_Application_Compilation


http://blog.cliffano.com/2006/08/16/jsp-precompilation-for-maven2-project/





On Mon, Jan 13, 2014 at 12:01 PM, Ross Bleakney <rossbleakney-***@public.gmane.org> wrote:





























Hello SeaJug,
It has been a while since I've done JSP, and I'm doing some now. I'm hoping someone knows of a tool (ideally a plugin) which can be used to help validate the expression language calls inside the JSP. Here is an example:


My Java Code:

public class HappyBean {
private boolean good;

public boolean isGood() {
return good;
}

public void setGood(boolean good) {
this.good = good;

}
}

My JSP:

<c:if test="${happyBean.good}">
<c:out value="${happyBean.notThere}" />
</c:if>

If happyBean.good is false, then everything works just fine. But when happyBean.good is true, I get a run time error. I don't like run time errors. So, I was hoping there would be some validation code I could run on the JSP which would tell me


"Hey, you don't have a method called 'getNotThere', are you sure you know what you are doing"

Any other tips are appreciated (please don't tell me to use anything besides JSP).


Thanks,
Ross
Konstantin Ignatyev
2014-01-14 05:46:14 UTC
Permalink
If you were using good ol' scriplet like <%=happyBean.notThere() %> then
JSP would not compile.

I personally never liked EL/Taglibs in JSP - much slower and half-baked.
IMO: To make really dynamic page it is better to use something like
Velocity or another templating solution, but if correctness is more
important then Play or Wicket more suitable.
Post by Ross Bleakney
Thanks, but that's not the problem. The code compiles just fine either
way. This is a run time error that only occurs if the code enters (and
executes) that block. That is why changing one JSP value from "false" to
_jspx_th_c_005fout_005f0.setValue((java.lang.Object)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${happyBean.notThere}",
...
This value is evaluated and executed dynamically (I assume using
reflection). What I want is for it to do that evaluation ahead of time, in
each line that contains EL JSP. I could write my own EL interpreter which
calculates the bean values from the Java or the JSP code but I assume there
is some utility out there that does that. Again, it would not have to be
100% (EL is fairly dynamic, so it might be difficult to be 100%) but
something that would warn me would be very good. I have to assume there is
something out there, but unfortunately when I search, I often find
references to Eclipse being too stringent about the JSP (a problem that
apparently occurred a while ago when JSTL was switching versions). I've
tried having Eclipse validate the JSP files and it has no problem with them
(probably because they all compile, the HTML is OK, etc.).
Thanks,
Ross
------------------------------
Date: Mon, 13 Jan 2014 13:24:59 -0800
Subject: Re: [seajug] Validating JSP EL
JSPs can be validated by compiling them into Java. The links below show
how to pre-compile JSPs with Maven or Ant.
https://tomcat.apache.org/tomcat-6.0-doc/jasper-howto.html#Web_Application_Compilation
http://blog.cliffano.com/2006/08/16/jsp-precompilation-for-maven2-project/
Hello SeaJug,
It has been a while since I've done JSP, and I'm doing some now. I'm
hoping someone knows of a tool (ideally a plugin) which can be used to help
public class HappyBean {
private boolean good;
public boolean isGood() {
return good;
}
public void setGood(boolean good) {
this.good = good;
}
}
<c:if test="${happyBean.good}">
<c:out value="${happyBean.notThere}" />
</c:if>
If happyBean.good is false, then everything works just fine. But when
happyBean.good is true, I get a run time error. I don't like run time
errors. So, I was hoping there would be some validation code I could run on
the JSP which would tell me
"Hey, you don't have a method called 'getNotThere', are you sure you
know what you are doing"
Any other tips are appreciated (please don't tell me to use anything besides JSP).
Thanks,
Ross
--
Konstantin Ignatyev

PS: If this is a typical day on planet Earth, humans will add fifteen
million tons of carbon to the atmosphere, destroy 115 square miles of
tropical rainforest, create seventy-two miles of desert, eliminate between
forty to one hundred species, erode seventy-one million tons of topsoil,
add 2,700 tons of CFCs to the stratosphere, and increase their population
by 263,000

Bowers, C.A. The Culture of Denial: Why the Environmental Movement Needs a
Strategy for Reforming Universities and Public Schools. New York: State
University of New York Press, 1997: (4) (5) (p.206)
Stone Zhong
2014-01-14 07:09:01 UTC
Permalink
By using ${happyBean.good}, you have agreed happyBean does not bound to any type, with a customized ELResolver, you do not necessary to get a runtime error.

- Stone




On Monday, January 13, 2014 9:46 PM, Konstantin Ignatyev <***@gmail.com> wrote:

 
If you were using good ol' scriplet like <%=happyBean.notThere() %> then JSP would not compile. 

I personally never liked EL/Taglibs in JSP - much slower and half-baked.  IMO: To make really dynamic page it is better to use something like Velocity or another templating solution, but if correctness is more important then Play or Wicket more suitable.
Post by Ross Bleakney
 
_jspx_th_c_005fout_005f0.setValue((java.lang.Object) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${happyBean.notThere}", ...
This value is evaluated and executed dynamically (I assume using reflection). What I want is for it to do that evaluation ahead of time, in each line that contains EL JSP. I could write my own EL interpreter which calculates the bean values from the Java or the JSP code but I assume there is some utility out there that does that. Again, it would not have to be 100% (EL is fairly dynamic, so it might be difficult to be 100%) but something that would warn me would be very good. I have to assume there is something out there, but unfortunately when I search, I often find references to Eclipse being too stringent about the JSP (a problem that apparently occurred a while ago when JSTL was switching versions). I've tried having Eclipse validate the JSP files and it has no problem with them (probably because they all compile, the HTML is OK, etc.).
Thanks,
Ross
________________________________
Date: Mon, 13 Jan 2014 13:24:59 -0800
Subject: Re: [seajug] Validating JSP EL
JSPs can be validated by compiling them into Java.   The links below show how to pre-compile JSPs with Maven or Ant.
https://tomcat.apache.org/tomcat-6.0-doc/jasper-howto.html#Web_Application_Compilation
http://blog.cliffano.com/2006/08/16/jsp-precompilation-for-maven2-project/
Post by Ross Bleakney
 
Hello SeaJug,
public class HappyBean {
   private boolean good;
  
   public boolean isGood() {
        return good;
    }
    public void setGood(boolean good) {
        this.good = good;
    }
}
  
<c:if test="${happyBean.good}">
     <c:out value="${happyBean.notThere}" />
</c:if>
If happyBean.good is false, then everything works just fine. But when happyBean.good is true, I get a run time error. I don't like run time errors. So, I was hoping there would be some validation code I could run on the JSP which would tell me
   "Hey, you don't have a method called 'getNotThere', are you sure you know what you are doing"
Any other tips are appreciated (please don't tell me to use anything besides JSP).
Thanks,
Ross
--
Konstantin Ignatyev
 
PS: If this is a typical day on planet Earth, humans will add fifteen million tons of carbon to the atmosphere, destroy 115 square miles of tropical rainforest, create seventy-two miles of desert, eliminate between forty to one hundred species, erode seventy-one million tons of topsoil, add 2,700 tons of CFCs to the stratosphere, and increase their population by 263,000
 
Bowers, C.A. The Culture of Denial: Why the Environmental Movement Needs a Strategy for Reforming Universities and Public Schools. New York: State University of New York Press, 1997: (4) (5) (p.206)
k***@u.washington.edu
2014-01-14 11:20:39 UTC
Permalink
It would be nice to have static analysis of the useBean JavaBeans available as a plugin
in the IDEs that validates the properties of the bean using reflection.
It would be nice if that were available in the org/apache/jasper/compiler/ package too.
I've not seen it if someone has written one for jsp.


For testing of jsp pages (runtime checking before your production deployment),
I tend to inject QUnit with tests into the jsp file using a template framework and
then I deploy that to run the tests in the browser.
Konstantin Ignatyev
2014-01-14 15:56:02 UTC
Permalink
Why bother? JSP is far from being good as page templating solution, the
only advantage/difference JSP had from PHP was its use of scriptlets <%=
c.someMethodOrField %> to allow static analysis of correctness.

Wicket allows for way more effective page composition from components if
you want to compose page on server. It has Models which can be implemented
with using compiled code rather than dotted strings, and those ensure that
all properties do indeed exist.

for example widely used property model use in Wicket looks like this
new Label("user-name-1", new PropertyModel[String](this,
"session.user.fullName"))

and this has the same problem of checking if user has method or field
fullName

but with language like Scala it looks

new Label("user-name-2", ROModel(() => { DemoSession().user.fullName }))

but one could write

class FullNameModel implements IModel<String> {
..... full Java ceremony code
}

That would ensure correctness of whole system but slows down development
quite a bit, if however used with JRebel on fast machine it feels almost
like PHP in terms of development feedback speed.


BUT:
I have been doing this for quite some time and liked it, but I mastered
AngularJS a bit as of recently and there is no turning back. Yes, AngularJS
is dynamic, no static checks, etc. but overall it is way more productive
and convenient way of creating pages with dynamic behavior. Since there are
no (almost) global things in AngularJS it all feels quite controllable.
Post by k***@u.washington.edu
It would be nice to have static analysis of the useBean JavaBeans available as a plugin
in the IDEs that validates the properties of the bean using reflection.
It would be nice if that were available in the org/apache/jasper/compiler/ package too.
I've not seen it if someone has written one for jsp.
For testing of jsp pages (runtime checking before your production deployment),
I tend to inject QUnit with tests into the jsp file using a template framework and
then I deploy that to run the tests in the browser.
--
Konstantin Ignatyev

PS: If this is a typical day on planet Earth, humans will add fifteen
million tons of carbon to the atmosphere, destroy 115 square miles of
tropical rainforest, create seventy-two miles of desert, eliminate between
forty to one hundred species, erode seventy-one million tons of topsoil,
add 2,700 tons of CFCs to the stratosphere, and increase their population
by 263,000

Bowers, C.A. The Culture of Denial: Why the Environmental Movement Needs a
Strategy for Reforming Universities and Public Schools. New York: State
University of New York Press, 1997: (4) (5) (p.206)
Ross Bleakney
2014-01-14 17:17:41 UTC
Permalink
Any other tips are appreciated (please don't tell me to use anything besides JSP).

Anyway, thanks kingn for the useful tip. It looks like there may not be anything that does the static analysis I want (or it may be too hard to find). It doesn't sound too hard to build, either. A static analysis would only get me so far, of course, so a more robust solution is probably in order anyway (I just wanted to do something quick to find the obvious mistakes).

Thanks,
Ross

To: seajug-***@public.gmane.org
From: kgignatyev-***@public.gmane.org
Date: Tue, 14 Jan 2014 07:56:02 -0800
Subject: Re: [seajug] Validating JSP EL


























Why bother? JSP is far from being good as page templating solution, the only advantage/difference JSP had from PHP was its use of scriptlets <%= c.someMethodOrField %> to allow static analysis of correctness.

Wicket allows for way more effective page composition from components if you want to compose page on server. It has Models which can be implemented with using compiled code rather than dotted strings, and those ensure that all properties do indeed exist.

for example widely used property model use in Wicket looks like thisnew Label("user-name-1", new PropertyModel[String](this, "session.user.fullName"))

and this has the same problem of checking if user has method or field fullName
but with language like Scala it looks
new Label("user-name-2", ROModel(() => { DemoSession().user.fullName }))

but one could write
class FullNameModel implements IModel<String> { ..... full Java ceremony code}
That would ensure correctness of whole system but slows down development quite a bit, if however used with JRebel on fast machine it feels almost like PHP in terms of development feedback speed.


BUT:I have been doing this for quite some time and liked it, but I mastered AngularJS a bit as of recently and there is no turning back. Yes, AngularJS is dynamic, no static checks, etc. but overall it is way more productive and convenient way of creating pages with dynamic behavior. Since there are no (almost) global things in AngularJS it all feels quite controllable.



On Tue, Jan 14, 2014 at 3:20 AM, <***@u.washington.edu> wrote:




























It would be nice to have static analysis of the useBean JavaBeans available as a plugin
in the IDEs that validates the properties of the bean using reflection.
It would be nice if that were available in the org/apache/jasper/compiler/ package too.

I've not seen it if someone has written one for jsp.


For testing of jsp pages (runtime checking before your production deployment), I tend to inject QUnit with tests into the jsp file using a template framework and
then I deploy that to run the tests in the browser.
--
Konstantin Ignatyev

PS: If this is a typical day on planet Earth, humans will add fifteen million tons of carbon to the atmosphere, destroy 115 square miles of tropical rainforest, create seventy-two miles of desert, eliminate between forty to one hundred species, erode seventy-one million tons of topsoil, add 2,700 tons of CFCs to the stratosphere, and increase their population by 263,000


Bowers, C.A. The Culture of Denial: Why the Environmental Movement Needs a Strategy for Reforming Universities and Public Schools. New York: State University of New York Press, 1997: (4) (5) (p.206)
Konstantin Ignatyev
2014-01-14 17:45:37 UTC
Permalink
Sorry about confusion Ross, I should of made it clear that I am responding
*Any other tips are appreciated (please don't tell me to use anything
besides JSP).*
Anyway, thanks kingn for the useful tip. It looks like there may not be
anything that does the static analysis I want (or it may be too hard to
find). It doesn't sound too hard to build, either. A static analysis would
only get me so far, of course, so a more robust solution is probably in
order anyway (I just wanted to do something quick to find the obvious
mistakes).
Thanks,
Ross
------------------------------
Date: Tue, 14 Jan 2014 07:56:02 -0800
Subject: Re: [seajug] Validating JSP EL
Why bother? JSP is far from being good as page templating solution, the
only advantage/difference JSP had from PHP was its use of scriptlets <%=
c.someMethodOrField %> to allow static analysis of correctness.
Wicket allows for way more effective page composition from components if
you want to compose page on server. It has Models which can be implemented
with using compiled code rather than dotted strings, and those ensure that
all properties do indeed exist.
for example widely used property model use in Wicket looks like this
new Label("user-name-1", new PropertyModel[String](this,
"session.user.fullName"))
and this has the same problem of checking if user has method or field fullName
but with language like Scala it looks
new Label("user-name-2", ROModel(() => { DemoSession().user.fullName }))
but one could write
class FullNameModel implements IModel<String> {
..... full Java ceremony code
}
That would ensure correctness of whole system but slows down development
quite a bit, if however used with JRebel on fast machine it feels almost
like PHP in terms of development feedback speed.
I have been doing this for quite some time and liked it, but I mastered
AngularJS a bit as of recently and there is no turning back. Yes, AngularJS
is dynamic, no static checks, etc. but overall it is way more productive
and convenient way of creating pages with dynamic behavior. Since there are
no (almost) global things in AngularJS it all feels quite controllable.
It would be nice to have static analysis of the useBean JavaBeans available as a plugin
in the IDEs that validates the properties of the bean using reflection.
It would be nice if that were available in the org/apache/jasper/compiler/ package too.
I've not seen it if someone has written one for jsp.
For testing of jsp pages (runtime checking before your production deployment),
I tend to inject QUnit with tests into the jsp file using a template framework and
then I deploy that to run the tests in the browser.
--
Konstantin Ignatyev
PS: If this is a typical day on planet Earth, humans will add fifteen
million tons of carbon to the atmosphere, destroy 115 square miles of
tropical rainforest, create seventy-two miles of desert, eliminate between
forty to one hundred species, erode seventy-one million tons of topsoil,
add 2,700 tons of CFCs to the stratosphere, and increase their population
by 263,000
Bowers, C.A. The Culture of Denial: Why the Environmental Movement Needs a
Strategy for Reforming Universities and Public Schools. New York: State
University of New York Press, 1997: (4) (5) (p.206)
--
Konstantin Ignatyev

PS: If this is a typical day on planet Earth, humans will add fifteen
million tons of carbon to the atmosphere, destroy 115 square miles of
tropical rainforest, create seventy-two miles of desert, eliminate between
forty to one hundred species, erode seventy-one million tons of topsoil,
add 2,700 tons of CFCs to the stratosphere, and increase their population
by 263,000

Bowers, C.A. The Culture of Denial: Why the Environmental Movement Needs a
Strategy for Reforming Universities and Public Schools. New York: State
University of New York Press, 1997: (4) (5) (p.206)
Ross Bleakney
2014-01-14 18:38:51 UTC
Permalink
That's cool. In my case, I can't change to a different template engine. I'm a bit surprised that JSP doesn't have more cool tools, especially since one of the advantages is that it has been around a long time. It is also frustrating that (as mentioned) you will see a compile error when using scriptlets (ugly old scriptlets) but don't have a warning when writing bad EL code.

Thanks,
Ross

To: seajug-***@public.gmane.org
From: kgignatyev-***@public.gmane.org
Date: Tue, 14 Jan 2014 09:45:37 -0800
Subject: Re: [seajug] Validating JSP EL
Any other tips are appreciated (please don't tell me to use anything besides JSP).

Anyway, thanks kingn for the useful tip. It looks like there may not be anything that does the static analysis I want (or it may be too hard to find). It doesn't sound too hard to build, either. A static analysis would only get me so far, of course, so a more robust solution is probably in order anyway (I just wanted to do something quick to find the obvious mistakes).


Thanks,
Ross

To: seajug-***@public.gmane.org
From: kgignatyev-***@public.gmane.org
Date: Tue, 14 Jan 2014 07:56:02 -0800

Subject: Re: [seajug] Validating JSP EL


























Why bother? JSP is far from being good as page templating solution, the only advantage/difference JSP had from PHP was its use of scriptlets <%= c.someMethodOrField %> to allow static analysis of correctness.


Wicket allows for way more effective page composition from components if you want to compose page on server. It has Models which can be implemented with using compiled code rather than dotted strings, and those ensure that all properties do indeed exist.


for example widely used property model use in Wicket looks like thisnew Label("user-name-1", new PropertyModel[String](this, "session.user.fullName"))


and this has the same problem of checking if user has method or field fullName
but with language like Scala it looks
new Label("user-name-2", ROModel(() => { DemoSession().user.fullName }))


but one could write
class FullNameModel implements IModel<String> { ..... full Java ceremony code}
That would ensure correctness of whole system but slows down development quite a bit, if however used with JRebel on fast machine it feels almost like PHP in terms of development feedback speed.



BUT:I have been doing this for quite some time and liked it, but I mastered AngularJS a bit as of recently and there is no turning back. Yes, AngularJS is dynamic, no static checks, etc. but overall it is way more productive and convenient way of creating pages with dynamic behavior. Since there are no (almost) global things in AngularJS it all feels quite controllable.




On Tue, Jan 14, 2014 at 3:20 AM, <***@u.washington.edu> wrote:




























It would be nice to have static analysis of the useBean JavaBeans available as a plugin
in the IDEs that validates the properties of the bean using reflection.
It would be nice if that were available in the org/apache/jasper/compiler/ package too.


I've not seen it if someone has written one for jsp.




For testing of jsp pages (runtime checking before your production deployment), I tend to inject QUnit with tests into the jsp file using a template framework and

then I deploy that to run the tests in the browser.
--
Konstantin Ignatyev

PS: If this is a typical day on planet Earth, humans will add fifteen million tons of carbon to the atmosphere, destroy 115 square miles of tropical rainforest, create seventy-two miles of desert, eliminate between forty to one hundred species, erode seventy-one million tons of topsoil, add 2,700 tons of CFCs to the stratosphere, and increase their population by 263,000



Bowers, C.A. The Culture of Denial: Why the Environmental Movement Needs a Strategy for Reforming Universities and Public Schools. New York: State University of New York Press, 1997: (4) (5) (p.206)
--
Konstantin Ignatyev

PS: If this is a typical day on planet Earth, humans will add fifteen million tons of carbon to the atmosphere, destroy 115 square miles of tropical rainforest, create seventy-two miles of desert, eliminate between forty to one hundred species, erode seventy-one million tons of topsoil, add 2,700 tons of CFCs to the stratosphere, and increase their population by 263,000


Bowers, C.A. The Culture of Denial: Why the Environmental Movement Needs a Strategy for Reforming Universities and Public Schools. New York: State University of New York Press, 1997: (4) (5) (p.206)
Jason Osgood
2014-01-14 18:03:30 UTC
Permalink
Hi Ross.
Post by Ross Bleakney
Any other tips are appreciated (please don't tell me to use anything besides JSP).
Sorry, obvious dumb question:

What’s the bean property notThere method look like?

I’ve gotten sideways with beans so many times. There’s just no predicting which JavaBean implementation will recognize which bean accessors. And sometimes you need both setter and getter to find the getter.

Maybe implement methods setNotThere(…), getNotThere(), isNotThere(), notThere() and see which one is found (via reflection).


Cheers, Jason


PS- Rant: Annotations, lambdas, closures, try multi-catch, try with, weird partial type inference, auto boxing, etc. All weird or useless (or worse). But still no properties. The single biggest ROI for language evolution would be (have been), in order: PROPERTIES, non-null, type inference (no “var” keyword). Java 5’s foreach was good.
Ross Bleakney
2014-01-14 18:50:06 UTC
Permalink
I let Eclipse build the getters and setters. In the example, there is nothing there. That is my point. For example, let's say you build some Java code, then build a JSP that uses a bean and everything works great. But somewhere in the JSP, you misspelled the bean name. You put "happyBean.naame" instead of "happyBean.name". The bean has a name, and a getName(), so the second example works. But the first one, unfortunately, will cause an error that won't be discovered until you go into that block.

There are other examples of code (such as a null pointer exception) that aren't caught by the compiler, but quite often the IDE will warn me about it (and there are plenty of third party plugins that can go to town with regards to validation). I was hoping that someone knew about something like this for JSP EL.

Thanks,
Ross

To: seajug-***@public.gmane.org
From: zappini-***@public.gmane.org
Date: Tue, 14 Jan 2014 10:03:30 -0800
Subject: Re: [seajug] Validating JSP EL





















Hi Ross.

Any other tips are appreciated (please don't tell me to use anything besides JSP).
Sorry, obvious dumb question:
What’s the bean property notThere method look like?
I’ve gotten sideways with beans so many times. There’s just no predicting which JavaBean implementation will recognize which bean accessors. And sometimes you need both setter and getter to find the getter.
Maybe implement methods setNotThere(…), getNotThere(), isNotThere(), notThere() and see which one is found (via reflection).

Cheers, Jason

PS- Rant: Annotations, lambdas, closures, try multi-catch, try with, weird partial type inference, auto boxing, etc. All weird or useless (or worse). But still no properties. The single biggest ROI for language evolution would be (have been), in order: PROPERTIES, non-null, type inference (no “var” keyword). Java 5’s foreach was good.
k***@u.washington.edu
2014-01-14 20:26:00 UTC
Permalink
In the several previous messages, the topics seem to be:
why choose jsp over php
and best practices regarding using java language in jsp pages.


Usually jsp is chosen because you like testability of your pages AND
you like the advantages that the servlet engines provide in terms of
handling http requests and you prefer those to the php containers
(compare threading, application namespaces and more... fun topic
but more than you're asking maybe.).


The original design of MVC w.r.t. java web tools attempted to
partition the responsibilities of the roles of employees so that a
web designer and html developer could be handed components
from a java developer for use in the jsp page. Hence the existence
of beans.


Regarding best practices for jsp:
I like the pattern of using beans rather than scriptlets because
its more testable.
With the addition/injection of javascript tests, that's possible.


:)
k***@u.washington.edu
2014-01-14 20:38:26 UTC
Permalink
I'm using the yahoo groups web interface to respond to these and somehow
exclamation marks are added - they're not intentional and no, I haven't yet
followed up on how they got there.
dev danke
2014-01-14 20:58:53 UTC
Permalink
A way to test JSPs:
- http://jakarta.apache.org/cactus/writing/howto_jsp.html
Post by k***@u.washington.edu
I'm using the yahoo groups web interface to respond to these and somehow
exclamation marks are added - they're not intentional and no, I haven't yet
followed up on how they got there.
w***@public.gmane.org
2014-01-15 00:24:44 UTC
Permalink
Unfortunately, I don't think there is a magic button for what you are looking for (unless the JSP stuff in IntelliJ does it - there's a lot of magic syntax analysis in IntelliJ). If you want to test runtime behavior, that pretty much means you have to boot up the server and interact with it.


FWIW, you can add a Tomcat bootstrap to Maven pretty easily with a plugin (http://tomcat.apache.org/maven-plugin.html). Then you can add test cases (e.g. HTMLUnit: http://htmlunit.sourceforge.net/) to exercise the pages you are interested in. As a really basic safety check you can do a log in and then just touch the pages to make sure you get a 200 back.


Good luck,
-Will

Loading...