Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JSF and the fly likes JSF and trinidad- Help with multiple iterations in a table 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 "JSF and trinidad- Help with multiple iterations in a table" Watch "JSF and trinidad- Help with multiple iterations in a table" New topic
Author

JSF and trinidad- Help with multiple iterations in a table

Dave Joseph
Greenhorn

Joined: Dec 15, 2008
Posts: 5
Hi, im very new to the JSF framework and apache trinidad. I need help with what many of you will probably think is very trivial, but i really can't figure this out at all!!

I am working on a page which collects a user's input via a textfield. the top level textfield is called "procedure". there is an add button which allows the user to add more than one procedure per page, and also a remove button as well. The Procedure object has one string called label, and a string array of tags.

The user is supposed to be able to add multiple "tag" textfields for each procedure. This is the part that i am stuck on. Basically, every Procedure object can contain an array of strings called "tag". Im just not too sure how to code it in the view. The following code does add a new string in the array, but does not allow for the actual input of tags from the page.



Can someone help me troubleshoot my logic?

Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Nest another table or list component inside the column for the tags.
Dave Joseph
Greenhorn

Joined: Dec 15, 2008
Posts: 5
Bauke Scholtz wrote:Nest another table or list component inside the column for the tags.


I am still not too sure on what binds an array's current index. when i click the add button on the inside array, i create another " string". what should be placed inside the [index]?



Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You don't need to specify the index. The UIData does it itself.
Dave Joseph
Greenhorn

Joined: Dec 15, 2008
Posts: 5
Bauke Scholtz wrote:You don't need to specify the index. The UIData does it itself.



i really appreciate your help so far and i'm almost there!



the inputText field with "#{tagRow}" now returns the value of what's inside the array, but i still can't set it (set tag) is never applied. When i click add tag, the test value "something added here" is added into the array, and that's what returns in the inputText area.



Here is my bean code.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
The setter of a list or datamodel will indeed never be called. EL will only get the list by the getter and then add the item to the obtained list.
Dave Joseph
Greenhorn

Joined: Dec 15, 2008
Posts: 5
Bauke Scholtz wrote:The setter of a list or datamodel will indeed never be called. EL will only get the list by the getter and then add the item to the obtained list.


That's rather confusing. I've been trying to find some good documentation online for this but after searching all morning i still can't find an example like the one i'm working with. I've only been able to find ones where single variables are set (phone number, first name, last name), but never a collection/arraylist.

how can the item added if it can never be read (or set) in from the page?
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
It works just the same way as your parent table, the tr:table. The setter of its value, #{DocumentBean.proList}", is also never been called.

JSF EL doesn't do like the following:
List list = new List();
list.add(index, item);
bean.setList(list);

But it rather does like:
bean.getList().add(index, item);
Dave Joseph
Greenhorn

Joined: Dec 15, 2008
Posts: 5
Bauke Scholtz wrote:It works just the same way as your parent table, the tr:table. The setter of its value, #{DocumentBean.proList}", is also never been called.

JSF EL doesn't do like the following:
List list = new List();
list.add(index, item);
bean.setList(list);

But it rather does like:
bean.getList().add(index, item);


you are the man. thank you so much for your help. i was able to accomplish what i needed with your insight.

Can you or anyone else recommend me a good reference where i can learn more about how the framework handles bindings and such? BalusC's website provides very good examples, but I am still having some issues understanding how the bindings work in depth.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
My website indeed contains lot of useful JSF related resources. For an insight about the bindings in the JSF lifecycle you may find this article useful: http://balusc.blogspot.com/2006/09/debug-jsf-lifecycle.html
 
 
subject: JSF and trinidad- Help with multiple iterations in a table