This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

managed-property and query string

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you access a query string with a managed property? Something like



And then from a URL like

http://localhost:8080/app/view.jsf?foo=bar
 
Dave Wood
bronco
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have not tried it, but you SHOULD be able to because you're supposed to be able to use any value-binding expression. It should look like this:



(param is the implicit variable you want for query params, not requestScope)
[ January 12, 2005: Message edited by: Dave Wood ]
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you access a query string with a managed property? Something like

Dave's solutions seems cool.

Wonder if that will work if the bean's scope is session.
(<managed-bean-scope>session</managed-bean-scope>
Shouldn't right?
[ January 12, 2005: Message edited by: K Varun ]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why wouldn't it work? wouldn't it just get an instance of that bean from memory and call that getXXX method? It just doesn't have to create a new object at the same time.
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okey, it's just for initializing the bean, that's it.
Thereafter, it won't.
 
Dave Wood
bronco
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought those properies were only set when the bean was created. So if you tried to do this with a session-scoped bean, it would only be set the one time the bean was created for the session.

...hmm, but if it was created at a time when that param was available, I would think it would work.
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gregg Bolinger:
Why wouldn't it work? wouldn't it just get an instance of that bean from memory and call that getXXX method? It just doesn't have to create a new object at the same time.


I looked at the specification, and it says

Such elements describe the characteristics
of a bean to be created, and properties to be initialized,


about <managed-property>,
so I guess it's just for initialization. :roll:
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that's good to know. Really, how many beans should you really be putting in the sessio anyway. I only have 1.
 
Dave Wood
bronco
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gregg Bolinger:
Well, that's good to know. Really, how many beans should you really be putting in the sessio anyway. I only have 1.

This brings up an interesting point that I've been struggling with. I'm finding that I have to put things in the session because I may want them to live for more than a single request.

For example, I have a screen where you can add things to a list. You add one, and I take you back to the same screen and your list is longer now. The bean that holds this list isn't LOGICALLY a session-scoped thing, but I have to treat it as one to be able to keep it around between requests. Then I have this (ugly) "newBean" method on it that I can call when it's time to clear it out for a new request.

Am I missing a cleaner way to deal with this sort of thing?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I tend to do is keep objects I need in the session in a single session object. For example, I working on some issue tracking software for the Help Desk I work on. I have a single "Visit" object. I store that visit object in the session. I have an Issue object and in my Visit class I store the current issue being worked on. So when I go from page to page I just have to do a getVisit().getCurrentIssue() to get the current issue in the session.

This seems to work ok for me and I don't have to put my managed bean for the new issue page in the session.
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gregg Bolinger:
Well, that's good to know. Really, how many beans should you really be putting in the sessio anyway. I only have 1.


I have 25
[ January 12, 2005: Message edited by: K Varun ]
 
Dave Wood
bronco
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good suggestion. That does seem a bit cleaner.
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My problem is bit different ->

I have a page in my application with around 15 tabs. Each tab is a functionality in its own, and hence has a managed bean associated with it. (Basically, each tab is an independent JSP page)

Most of the tabs has a table in it. I have used datatable for it. Now all the table needs sorting, hence I have used the managed bean(s) in session scope.
(since just for sorting, re-fetching the data from dB didnt make any sense)

Now all the tabs are independant, hence I dont want the backing beans to remain in session once the user is out from any tab.

Now I am not sure about how to going about it. I know I can remove the bean from session
(as: FacesContext ...blah blah.... getSessionMap().remove("beanName"))
but since user can go from any tab to other, I can't make out that among the avaiable beans in session, which bean is currently I am going to use and which others shall be removed.

I need certain call back event like onpageUnload() on h:form, which can call a method passng the bean's name once user goes away from page and in the method I will remove the bean from session

Can't really go with Gregg's approach and it wont really lessen the session data in my case.

Any suggestions?
[ January 12, 2005: Message edited by: K Varun ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic