• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Christian Nicoll
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>.


 
reply
    Bookmark Topic Watch Topic
  • New Topic