aspose file tools*
The moose likes JSF and the fly likes Why can't I access the value of this Map in JSF? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Why can Watch "Why can New topic
Author

Why can't I access the value of this Map in JSF?

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Hi,

I'm using MyFaces 1.1.6. On a certain JSF page, I have



Then, on the same page, I try to access the value I put in the Map, like so



but nothing prints out when my page renders. I'm sure this is simple -- what am I doing wrong? - Dave
Christian Nicoll
Ranch Hand

Joined: Mar 09, 2008
Posts: 106
Hello Dave,

I don't use MyFaces, but tried the same with RI. I don't receive any output, because the map can't be found by the EL. I think that the EL-statement is evaluted and Faces tries to look for an attribute myMap in the scopes request -> session -> application, but no attribut is found.

To solve this problem, you can save your map in the request-scope and everything should work as you had expected it:


SCJP 5, SCJD 5, SCWCD 5, SCBCD 5, SCJDWS 5
My SCBCD-Notes - My Hello World Webservice
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Thanks for this creative work-around, but is the lesson here, that in JSF, it is impossible to directly access values of instance variables defined on the JSF page?

- Dave
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15662
    
  15

Dave Alvarado wrote:Thanks for this creative work-around, but is the lesson here, that in JSF, it is impossible to directly access values of instance variables defined on the JSF page?

- Dave


Instance variables of what?. You listed the property named "mymap", but you didn't say which bean it was contained in.

JSF isn't intended to be composed of JSPs with scriptlets in them. That's a violation of the MVC architectural standard, putting a Model object directly inside the View.

Customer surveys are for companies who didn't pay proper attention to begin with.
Christian Nicoll
Ranch Hand

Joined: Mar 09, 2008
Posts: 106
I think it is possible to directly access values of instance variables in a JSF/JSP page, but for that use the scriptlet <%= expression %>. This code will be inserted directly in the service()-method of your servlet and so is able to access the instance variable. I don't say that this look pretty...

With an faces-tag like <h: outputText> I don't see a possbility to access the instance variable, because the "page-scope" misses. I think in Faces 2.0 exists a page scope, and so perhaps it is then also possible with tags like <h: outputText>.


 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why can't I access the value of this Map in JSF?
 
Similar Threads
Error in c:set tag
jsp:useBean
Scriplet
Map within a Map in JSF-EL ?
obtain the key of a map