GeeCON Prague 2014*
The moose likes JSP and the fly likes c:set and accessing variables with EL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "c:set and accessing variables with EL" Watch "c:set and accessing variables with EL" New topic
Author

c:set and accessing variables with EL

Allen Williams
Ranch Hand

Joined: Sep 04, 2006
Posts: 136
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


-------<br />Thanks & regards,<br />anw
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61312
    
  66

Unless I miss my guess, mod is a reserved word for the modulo operator.
[ September 29, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61312
    
  66

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

Joined: Jan 10, 2002
Posts: 61312
    
  66

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

Joined: Sep 04, 2006
Posts: 136
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
 
GeeCON Prague 2014
 
subject: c:set and accessing variables with EL