Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

c:set and accessing variables with EL

 
Allen Williams
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a JSP, I'm trying to set then use a variable called "mod" thusly:





I have also tried access it with simply ${mod}. You can probably guess that I'm using this to determine what should be the initial value of the checkbox, and I want it to either be empty ("") or "checked" (w/o the quotes around the values).

I get the following error:


JasperException: /trbupdate.jsp(66,65) "${pageScope.mod}" contains invalid expression(s): javax.servlet.jsp.el.ELException: Encountered "mod", expected one of [<IDENTIFIER>]


What am I doing wrong?

TIA
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless I miss my guess, mod is a reserved word for the modulo operator.
[ September 29, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, if you are using JSP 2.0 (and if not, why not?) you can vastly simplify your code with:


[ September 29, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, if you will forgive a short trip to the soapbox:

<rant>
mod? mod? Even if it wasn't reserved, do you really think that's a good, readable name? This isn't FORTRAN; use readable variable names like isTribeModerated and improve the readability of your code.
</rant>
[ September 29, 2006: Message edited by: Bear Bibeault ]
 
Allen Williams
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot (well, for the first two posts, anyway;). I am using JSTL 2.0,
but hadn't come across the ? : expression. I have tried to use that in straight Java code, unsuccessfully (not sure what I was doing wrong, and didn't think the time was well spent figuring out a syntactic detail; I'm a throwback to the days of C and C++ programming, where I used it all the time).

I realize the accepted wisdom is to use extensive, long, multiply-capitalized, underscored, colored, and textured variables. I agree with that to the extent that any member variables, global variables, or major variables in a sizeable function are defined thusly (although I do shy away from global variables whenever possible, except in true "write one place, read many" type of uses). I confess, however, that for small, six or seven line functions, using what we in C called automatic variables, I will often use short "abbreviated" variables. However, I would take issue with the fact that the length is the determinate of the quality of name. Actually, I thought "mod" was pretty descriptive of "moderated". Unfortunately, whoever wrote the compiler also thought "mod" was pretty descriptive, just of a modulo function;-)

Anyway, no doubt my rationalizations are off-topic, and I do appreciate this (and all) the help I've received here.

Allen
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic