Forums Register Login

Declarated variable in EL

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.
This tiny ad is wafer thin:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3649 times.
Similar Threads
Setting select items programatically
need to render tooltip with <f:selectItems> used with <h:selectOneMenu>
using ajax4jsf with dropdawn list
Birth Date nightmare - passing variable between beans and java objects
h:selectOneMenu - setting the correct value
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:11:30.