tags:

views:

53

answers:

2

I need to create an input form that will allow a user to enter any number of values for a particular attribute.

I've tried several approaches, all of which seem to have various levels of failure. The latest model bean looks something like:

public class Product {
  private String name;
  private ArrayList<String> tags = new ArrayList(5);

  {
    tags.add("");  //seed with 1 non-null element
  }

  ...accessors...
}

The input fields look something like:

    <h:dataTable id="tags" value="#{product.tags}" var="tag">
      <h:column><h:inputText id="t" value="#{tag}"></h:inputText></h:column>

My plan was to allow the user is to use javascript to add additional form fields as needed.

This type of setup gives me a 'Target Unreachable' error. What am I missing?

My problem now is that the setter for tags does not get called. Oddly enough, the setter for name does.

I am using JSF 1.1 on WebSphere 6.1

A: 

shouldn't "#{product.tag[0]}" be "#{product.tags[0]}"?

amp123
yes, that was a typo in breaking down my problem, i'll edit to reflect this.
Sean
+1  A: 
BalusC
BalusC, with your help i've been able to get a bit farther. However, I'm encountering a new issue. I've removed the logic to support adding the text fields through JS, the only thing left figuring out why the managed view isn't being updated with the form. I've updated accordingly above.
Sean
Long story short: http://balusc.blogspot.com/2006/06/using-datatables.html#AddNewRowsToDatatable
BalusC
that section makes sense, however i'm still unable to get setTags in managed bean to execute (setName executes). I don't see any exceptions in the logs; and the request does contain what i typed in for a tag. my understanding of the jsf request life cycle would be that the view is first restored (execute gets in managed bean) then the request values are applied (execute the sets). i feel like i am missing something, but don't know what.the rendered input tag looks like:<input id="new:tags:0:tag" type="text" name="new:tags:0:tag" value="ball" />
Sean
I don't recall if a `List<String>` would work in JSF 1.1, but I'd give `List<RowObject>` a shot. Further it's good to know that setters are never called for collections or nested model objects. JSF will basically do `bean.getList().get(rowIndex).setSomeProperty(requestParameterValue)`.
BalusC
BalusC, that did the trick. Create an object for a tag (which is what I would need to end up doing).Thanks for the info on the fact setters aren't called for collections or nested model objects. i don't recall reading that anywhere.
Sean
You're welcome, but why did you remove the upvote?
BalusC
misclick, but i can't seem to upvote it again without you editing the response...can you edit and i can re-upvote?
Sean
OK, no problem.
BalusC