0

I am trying to learn JSF and doing some basic stuff.

In the <h:form> should be an <h:inputText> field. The text written in the textbox should be added in an ArrayList and this list must be seen in a <h:dataTable> under the textfield. I don't know how I can iterate in JSF in an ArrayList and print into view. I also don't know how to add Strings in the ArrayList. I have done this with Servlet + JSP but I dont know how to do it in JSF.

..here is my code: http://pastebin.com/3jX1jYXH

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
NoName123
  • 137
  • 5
  • 20
  • Please edit your code providing the proper JSF code and show what have you tried. – Luiggi Mendoza Jun 04 '13 at 21:22
  • Dont need help anymore just found the answer:http://stackoverflow.com/questions/13609511/jsf-adding-a-string-to-list – NoName123 Jun 04 '13 at 21:43
  • That's a possible solution, but not one to follow if you're in learning phase (as stated in your question). Still, is up to you... – Luiggi Mendoza Jun 04 '13 at 21:44
  • What do you mean? Bad code?...I am unterstanding the code but I just dont get why he returns this string: return "./index.xhtml"; – NoName123 Jun 04 '13 at 21:48
  • First, using `@ApplicationScoped` when it could be `@ViewScoped` or `@SessionScoped` (I would prefer the former). Second, using `ArrayList` attribute instead of `List` backed up by `ArrayList` (refer to [What does it mean to “program to an interface”?](http://stackoverflow.com/q/383947/1065197)). Third, no need to return `"./index.xhtml"` or a `String` at all, the method used for the `action` of the `` can *return* a `void` instead to stay in the same view. Fourth, no need to pass a parameter to the action method. – Luiggi Mendoza Jun 04 '13 at 21:54
  • Last but not least, you can use `` or `` to show the items contained in your `List`. – Luiggi Mendoza Jun 04 '13 at 21:54
  • IMO it would be better if you understand the MVC pattern very well: use view logic **only** in the view (in this case, in Facelets), have the controller classes for what they should do: control the flow of the application, and let the model classes (services, data access, entities) handle the model logic (business rules, relationships with database or other data sources, etc). Then, grab concepts from Servlets and understand that JSF is on top of it. – Luiggi Mendoza Jun 04 '13 at 22:08

0 Answers0