• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Composite Components with ViewScoped bean

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Further news - this appears to only happen when one of the composite:attributes has required="xxx" in the tag...
 
reply
    Bookmark Topic Watch Topic
  • New Topic