aspose file tools*
The moose likes JSF and the fly likes JSF Portlet and instance variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF Portlet and instance variables" Watch "JSF Portlet and instance variables" New topic
Author

JSF Portlet and instance variables

Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Could someone tell me what are the design considerations for a JSF Portlet with regards to instance and static variables.....should they be treated the same as servlet instance variables???

Also,I am working on a portlet and I need to have some data shared across all the methods in the pagecode file....Should I place these values in a request scoped bean or can I use static/instance variables???

Lastly I would like to know whether there are any specific design considerations for using preRender/onPageLoadBegin.....


===>SCJP 1.5(72%)<===
==>SCWCD1.5(76%)<===
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Keep your instance and static variables out of any classes that extend portlet, just like you keep them out of Servlets.

Instance variables should be in your managed beans. Static variables? Those are tied to a JVM, right? So, if you have multiple JVMs in a clustered environment, I think they'd get out of sync, right? So, it's better to use the Session scope it the variable is tied to a user. If it's application centric, you can use the application scope, although JVM issues rear their head there as well. Maybe just a simple, shared database table/column if the environment is clustered. If not, use the application scope.

I'd also tell you to kill that pagecode bean. I can't stand it. It's just bad, bad JSF design and it creates completely unmanageable application. That's just my opinion though. I'm sure the lightweight that invented it loves it.

-Cameron McKenzie
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

So its fine to have instance variables in my managed beans?When you say this do you mean both page beans and managed beans or just managed beans??

Could you tell me whether my approach for the following is correct:

I have a portlet that retrieves user information from the session.It uses DTOs to get information from the database.
I have configured the 'out DTO' as a page bean(Will allow me to reference the out DTO's properties using EL?).I use the prerender attribute to call onpageloadbegin.In this method I get the user information from the session.I store this on the 'in DTO'.The getter for the ''out dto' makes a call to the database.

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

page beans and managed beans or just managed beans??


Aren't they the same thing? What's the difference?

If you can get your design to work, it sounds reasonable. Nothing wrong with referencing a DTO. I've never liked the onpageloadbegin, but that's personal bias against writing code against page events. It just makes me worry about what happens when the logic needs to be used on a different page.

-Cameron McKenzie
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

I'm not quite sure what is the difference...I just know that RAD makes a distinction between the two in the page data view...
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

When you say this do you mean both page beans and managed beans or just managed beans??....I'm not quite sure what is the difference


So if I gave you an answer to this question, you wouldn't know what the answer meant?

-Cameron McKenzie

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

Duran Harris wrote:I'm not quite sure what is the difference...I just know that RAD makes a distinction between the two in the page data view...


Well, if we were a typical bunch of flaming elitist techno-snots, we'd heap vitriol and scorn on you for depending on an IDE to do your thinking for you. And kick your puppy dog, too.

But this is the JavaRanch, and we're supposed to play nice here.

Backing Beans are POJOs, and instance variables are part of the very essence of POJOs. Static backing bean properties are OK, provided you realize that there may be multi-threading issues. Of course there are also multi-threading issues for instance members of application-scope beans, but that's because application scope is more or less the "static" version of JEE objects.

If you're interested in the difference between managed beans and backing beans, search this forum. It's a question that gets asked a lot. But the short answer is that for most practical purposes you can treat them as the same thing.

I think most of the JSF/Portlet questions get addressed in the Portlets forum. Portlets tend to put constraints on JSF more than JSF puts constraints on portlets.


Customer surveys are for companies who didn't pay proper attention to begin with.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Always trust Tim to play 'good cop' to my 'bad cop' routine.

Here's a good distinction between managed and backing beans I dug up somewhere:

A Managed Bean is any been defined in the faces-config file(s). It's exactly what its name says - a POJO managed (created and initialized) by the JSF framework.

A Backing Bean is a bean that's backing up a JSF view. That is, it's part of an EL expression that references that bean or it's properties on a JSF web page definition.

Since managed beans are created on-demand and the most common demand is from a JSF View, you can consider the two terms to be essentially equivalent.


Tim's Answer to The Difference Between a JSF Managed Bean and a Backing Bean

Also:
Java ServerFaces: A Backing Bean vs. a Managed Bean in JSF

What is the difference between a JSF Managed Bean and a Backing Bean?

-Cameron McKenzie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF Portlet and instance variables