• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

JSF2 how pass dataTable loop var to custom component

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to encapsulate a site-wide bookmarkable URL GET link strategy as a reusable component. I have a number of entity classes (Activity, Actor, Block, ..) that extend Element. Each entity class T has its own <T>Manager as managed bean. In many pages I want to be able to link (via bookmarkable GET URL) to view page for many entities. There is a lot of repetition in the coding for table columns with links:

I want to encapsulate the link part as a reusable component: resources/util/view_link.xhtml:

However for some reason I can't pass the dataTable loop var to the custom composite.This fails:

The error reported claims that "The following attribute(s) are required, but no values have been supplied for them: element. ", but clearly the var 'actor' is not null (I've checked).

It seems one can't pass loop variables to components this way. If so:

Q1: why not ?

Q2: is there a way around this ?

Grateful for feedback,

Saloon Keeper
Posts: 27817
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because a dataTable isn't a loop. It's a 2-dimensional display. It would be fully within its rights to run the entire set of rows as parallel operations and that would still be within the JSF2 spec definition.

However, more to the point, you're attempting to pass a Java object through a text channel. Think about that for a second. Java objects are binary constructs. When you render a page, the EL expressions are applied and the controllers use the results to render text. Then when you submit the page, text gets sent back down to the server. So EL that resolves to complex objects doesn't fit.

What you can do is add a property to your model object that renders it as text. Sometimes that can be as simple as:

And reference the "actor.textValue" attribute in your EL.

It depends on what form you want to use.

If the object in question is a database object, you might want to only render the key and let the second stage of the process use that key to retrieve the object. Or, if you prefer something more secure, generate a UUID, stash the object handle in your HttpSession using that UUID as the attribute name, render the object reference as the UUID, then have the backend pluck it back out of the HttpSession.
    Bookmark Topic Watch Topic
  • New Topic