On Tue, 4 Jan 2005 14:56:10 -0500, Sean Schofield
<[EMAIL PROTECTED]> wrote:
> I was wondering how if its possible with JSF to add a component to the
> tree via as the result of a POST.

Yes, you can make arbitrary changes to the components in the tree in
the event handler to a POST.  However, if you are using JSP they will
only show up if the added components are inside a component whose
rendersChildren property is set to true (so that the parent component
takes responsibility for actually doing the rendering.

> 
> A simple example: you have a list of phone numbers and you have a
> wizard on the page that allows them to add another one.  How would
> Faces handle something like this?  In the typical examples, the user
> is editing a form with exisitng elements that are known at design
> time.  I guess I'd be most interested in adding to an existing list as
> that would be the only case where I wouldn't know all of the data
> ahead of time.

There's a couple of different approaches that could be used.

If your list is inside a UIData component (such as <h:dataTable>),
simply add the new object to the list that is bound to the "value"
property.  Assuming you haven't set the "rows" property to limit how
many rows are rendered, the next rendering of the component will pick
them all up.  You don't need to mess with the component tree at all,
because UIData iterates over all its column children, once per row,
for you.

if you are constructing your presentation out of individual
components, then you'd just add them as children of the appropriate
parent, set their values, and then ensure that you're going to render
the same page again.

> 
> My guess is that something is possible but that it wouldn't be the
> easiest thing to accomplish.  Even if you are able to create a new
> component and add it to the tree, it seems there would be an issue
> with binding that data to the model.

The binding is actually pretty easy -- just create a new ValueBinding
instance (via Application.createValueBinding()) and then update the
component with something like:

  component.setValueBinding("value", vb);

> 
> I'm not an expert on faces (yet) but I wanted to get started thinking
> about this issue.  Does anyone have any ideas on how I could approach
> this?  Maybe I would need to extend UIData or something?
> 
> sean
> 

Craig

Reply via email to