wood burning stoves 2.0*
The moose likes JSF and the fly likes managed-property and query string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "managed-property and query string" Watch "managed-property and query string" New topic
Author

managed-property and query string

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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


GenRocket - Experts at Building Test Data
Dave Wood
bronco
Ranch Hand

Joined: Aug 02, 2004
Posts: 161
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 ]

Co-Author of <a href="http://www.oreilly.com/catalog/jswing2" target="_blank" rel="nofollow">Java Swing</a><br />Co-Creator of <a href="http://www.sun.com/training/catalog/courses/CX-310-055.xml" target="_blank" rel="nofollow">SCJP 5.0</a> and <a href="http://www.sun.com/training/certification/java/associate_beta.xml" target="_blank" rel="nofollow">SCJA</a> exams
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
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 ]

- Varun
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: May 30, 2002
Posts: 1400
Okey, it's just for initializing the bean, that's it.
Thereafter, it won't.
Dave Wood
bronco
Ranch Hand

Joined: Aug 02, 2004
Posts: 161
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

Joined: May 30, 2002
Posts: 1400
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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Aug 02, 2004
Posts: 161
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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: May 30, 2002
Posts: 1400
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

Joined: Aug 02, 2004
Posts: 161
Good suggestion. That does seem a bit cleaner.
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
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 ]
 
wood burning stoves
 
subject: managed-property and query string