0

i m using inside the backing bean an

private ArrayList<String> myList;


init(){
  myList = new ArrayList<String>();
  myList.add("XYZ");
}

public ArrayList<String> getMyList(){
    return myList;
}

public setMyList(ArrayList<String> l){
    myList = l;

}

insde the xhtml

i show the elements by doing:

   <h:outputText value="Item: " />  
                <p:inputText required="true" label="Item"  
                        value="#{mybean.myList[0]}" />  

when i show the page i see the value:

 XYZ 

in the page.

So my question is:

If I do NOT set "XYZ" inside the ArrayList and the user writes inside p:inputText the value "HKJ", will I find on server-side inside myList at position 0 the expected "HKJ"? Can I use ArrayList for display and set values or do i have to use String[] ?

you can find here similar question:

  http://www.velocityreviews.com/forums/t303520-jsf-using-arrays-arraylist-in-the-backing-bean.html
FrankTan
  • 1,626
  • 6
  • 28
  • 63

1 Answers1

1

JSF is working in a Lifecycle (see JSF lifecycle with example). One of the first parts of this lifecycle is to take user-sent input, validate it and push it into the JSF object tree.

So, when you connect a h:inputTexts value with a managed beans property - this field will be updated with the input a user did on the frontend (when it passes the validation, and the input field is inside a h:form).

The collection access operator ([] operator) works in the case you describe the same for Arrays and Collections (ArrayList implements Collections).

Community
  • 1
  • 1
L-Ray
  • 1,637
  • 1
  • 16
  • 29
  • the question is not about lifecycle in general but specific to the EL expression for arrays. My question is i can use Arraylist for display and set values or i must use String[] ? – FrankTan Jan 12 '14 at 15:01
  • you can see this here also: http://www.velocityreviews.com/forums/t303520-jsf-using-arrays-arraylist-in-the-backing-bean.html – FrankTan Jan 12 '14 at 15:03
  • Hi @frank, your questions was not clearly asked. This makes answering and actively helping you achieving your goals a bit difficult. Check out the edited answer above and good luck with your project. Upvote/Accepting appreciated. – L-Ray Jan 12 '14 at 15:33
  • i can't upvote o accept an answer that do not answer to my question – FrankTan Jan 13 '14 at 08:28
  • Question: Can I use ArrayList for display and set values or do i have to use String[] ? Answer:The collection access operator ([] operator) works in the case you describe the same for Arrays and Collections (ArrayList implements Collections). – L-Ray Jan 13 '14 at 08:31
  • this is the an answer. thanks. i will check this. i m still not on the point in the project that i can check this. – FrankTan Jan 13 '14 at 09:36
  • That was the updated Part - Sorry, next Time I'll mark it to be better readable. So, if this answer is useful for you, mark it as being so :-) Good luck and have fun ... :-) – L-Ray Jan 13 '14 at 09:42
  • do not worry i will accept soon ;) thx for your say your opinion. – FrankTan Jan 14 '14 at 09:04