aspose file tools*
The moose likes JSF and the fly likes Composite Components with ViewScoped bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Composite Components with ViewScoped bean" Watch "Composite Components with ViewScoped bean" New topic
Author

Composite Components with ViewScoped bean

Kevin McMahon
Greenhorn

Joined: Nov 03, 2008
Posts: 19
Hi all.

I'm using JSF 2.0 (Mojarra) and WebLogic 10.3.3.

I have a page with a datatable on (it's actually an openfaces datatable, but I don't think that matters in this instance.)

The table is backed by a viewscoped bean that provides an ArrayList of objects for data. If the datatable tags are directly in the xhtml page being called, the viewscope works fine - that is, fo subsequent posts that result in void or null methods being called, and therefore return to the same page, no new instance of the bean is created.

However, if I extract the datatable in to a composite component, and pass in the List of objects that the table should display as a parameter instead, the backing bean is instantiated every time.

e.g. The following works fine - testBean is only instantiated the first time. Clicking the button does not create a new testBean instance.



However, putting the datatable in a composite component and have tableItems as a parameter, the following doesn't work:


Does anyone know why this might be the case?

Thanks
Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218

Try moving your call to cc:customTable inside the form and take out the <h:form>
tags from the composite component. I've hit a number of problems with using h:form
inside a cc. Theoretically it should work, and sometimes it does, but sometimes it
doesn't. Are you using ui:component tags for the cc? Which mojarra version?

It's a little unusual to put the datatable outside the form. Another thing to consider
is that when you have a commandButton with a child ajax tag it will by default only
submit (albeit partially) @this, i.e. the commandButton component itself. If you had:



...then the inputText data wouldn't get submitted unless you had:



In fact looking at it again your form (excerpt) doesn't make sense. You have an outputText,
a commandButton with a child ajax tag which updates the outputText component, and then a
dataTable which is outside the form. What are you expecting to happen? where's the input?


Regards,
Brendan.
Kevin McMahon
Greenhorn

Joined: Nov 03, 2008
Posts: 19
Thanks for the suggestions. I'm fairly sure I've tried this with everything within one form (I don't have any form tags withing the cc)
I'm not using the ui:component tag. I'm using
<composite:interface> and <composite:implementation> to define my component, add calling it from the using page in the usual way, referencing the namespace.
So if my component was in a file customTable.xhtml, I would call it using

... xmlns:cc="http://java.sun.com/jsf/composite/components"

to add the namespace,

<cc:customTable /> to use the component.

I'm aware of the ajax thing you mentioned. I was just giving a simple example to demonstrate that even if the datatable isn't a render target, the backing bean is still being instantiated each time.

I'll test some more and let you know how I get on. Thanks again for the help.
Louis Jordaan
Greenhorn

Joined: Jul 22, 2011
Posts: 1
Kevin: Did you ever find a solution to this problem? I'm battling with this issue now. It looks like the view scope breaks when I pass an el expression into an attribute of a composite component.
Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218
Louis Jordaan wrote:Kevin: Did you ever find a solution to this problem? I'm battling with this issue now. It looks like the view scope breaks when I pass an el expression into an attribute of a composite component.


Hi, can you post up a code example of your issue?
Kevin McMahon
Greenhorn

Joined: Nov 03, 2008
Posts: 19
Further news - this appears to only happen when one of the composite:attributes has required="xxx" in the tag...
 
 
subject: Composite Components with ViewScoped bean