This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Declarated variable in EL  RSS feed

 
Tom Bart
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I'm just starting to write my JSF application. It is ment for a school project so it's supposed to stay as JSF-way as possible. So my problem is:



Compiler says that the value for a foo is eighter null or don't render the text. I know this is basic example but i really need to do something not harder than this.

I'd like to get months names from java.util.Calendar and put it into <select><option>MonthName</option></select> but i don't want to do it manually. If it is possible to do it JSF-way then i MUST do it this way. I alredy found a way to get months names and put it in a list or anything i need but then i don't know how to put it inside the <h:selectOneMenu> as a <f:selectItems value="#{monthsNames}" />




And the other question i have is what's the difference between #{} and ${} in expression language ?

Anyway please help me with this. I'm tryng to work this out for several hours now.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most important difference between "$" references and "#" references are that "#" indicates an lvalue. Meaning that you can not only read the value, but you can also write a value there.

That said, if you're expecting to gain academic credibility using JSP scriptlets on a JSF page, think again. Scriptlets on JSF are discouraged even in the so-called Real World where we routinely cheat when deadlines loom and the "proper" solution eludes us. In a classroom assignment, I wouldn't even think of it.
 
Tom Bart
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. I found a way around it in a more JSF way but now i'm just curious how to answer my orginal question about how to put a variable in EL.
Now it's just for the meaning of pure knowledge that this is or isn't possible and if is then how.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Bart wrote:Ok. I found a way around it in a more JSF way but now i'm just curious how to answer my orginal question about how to put a variable in EL.
Now it's just for the meaning of pure knowledge that this is or isn't possible and if is then how.


I think you actually meant "set" a variable (shorthand for set variable's value). To tell the truth, I'd have to RTFM, since the closest I've ever done was using JSTL, and the JSTL set tag did the actual work. But, as I said, JSTL in JSF is not a good idea in general.

JSF's EL variable handling is managed by attaching "variable resolvers" to the context so that when the framework parses an EL expression and attempts to interpret it, the system will know where to find the names and values of referenced variables. One of the most important elements of the faces-config file in most of my JSF projects is a plugin resolver that brings the Spring Framework bean factory into the context so that EL references can also be made to Spring-managed beans - both in JSF pages and in faces-config.xml itself.

If you're really interested in the sordid details, I think Sun has some docs and the actual EL framework used in many systems is (I believe) an apache.org project. Certainly the BeanUtils are, though they're just the core variable resolver, and they not only are used by more than just the EL system, they also predate it - BeanUtils was used in the Struts system.

It's very much worth learning about BeanUtils. Even if you never use it directly, since it's at the heart of so many other systems, knowing how it works is very useful when you need to code up complex bean property references.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!