webtier@glassfish.java.net

Re: How to avoid _at_PostConstruct on page Faces beans during postback?

From: <webtier_at_javadesktop.org>
Date: Tue, 14 Apr 2009 22:13:04 PDT

> The h:form in this use case is dedicated to the
> commandLink. There is [b]nothing else[/b] in it.
> There is no reference to myFB, not even in the
> commandLink. Yet Mojarra still re-instantiate all the
> beans referenced on that page...

I would have expected (as you are expecting), that if the MB's aren't involved, then they wouldn't be involved. :) Apparently this is not happening. One of the many reasons I shy away from using Managed Beans in my own projects (too much work to mange all that "free" management they give you ;) ).

Perhaps you can print a stack trace from inside your @PostConstruct method (or stop the debugger at that location and see the call stack)... that might give you a hint as to the code path that is leading to it being called. Are you using client-side state saving? Maybe in this case, during restore view, it needs to look up something in the bean which has the @PostConstruct?

> I'll refrain from commenting on the arrogant last
> paragraph, but re: GETs, that's what we do right now
> and this is also unsatisfactory in that:
> 1) if you have multiple actions for the URL, you end
> up with an ugly if/else/if/else/etc. in prerender

You are using prerender as your action? I think this is not what you want.

Any GET/action solution should allow you to do anything you want in the action and then let you choose to forward/redirect however you'd want. I haven't used RestFaces myself, but I suspect it should support this. Perhaps the other framework mentioned does as well.

> 2) it forces you to navigate before you know the
> result of the action

It shouldn't.

> JSF command framework is great, I was just looking
> for an optimized version for form-less action use
> cases, but I guess this doesn't exist yet...

Yes, I understand what you're getting at... I'd be curious to see the stack trace to see what is forcing the MB to instantiate. Perhaps a binding attribute will cause this, do you using bindings? (I recommend avoiding the binding hack -- but that's another story...)

Good luck!

Ken
[Message sent by forum member 'kenpaulsen' (kenpaulsen)]

http://forums.java.net/jive/thread.jspa?messageID=342199