Problem with ActionForm + dynamically generated fields..
Gabriel Fox
Ranch Hand
Joined: Oct 17, 2001
Posts: 170
posted
0
Hello, I am trying to resolve this : if i have a search input field ,say : name :<html:text property="propertyName" /> <html:submit/> In this case, i need the actionForm to declare a setter,getter and instance variable for propertyName.After doing a search i populate same screen with search results which are display in 2 columns : 1.ID(uneditable)2.Department(Editable,input field). So , the user can change any of the Department field and click the save button to update the database, using just one save button per search- result screen. Question; how do i handle form parameter for the department field, because their names are generated dynamically at runtime .Hence , i cannot add setter,getters in ActionForm subclass for the update action ,since they are NOT known at compile time. All ideas are welcomed please.
Jason Menard
Sheriff
Joined: Nov 09, 2000
Posts: 6450
posted
0
You could use an action form that has a collection of result beans as an attribute, where a result bean consists of a String id and a String department. You would use nested tags to render the page. See:
Thanks very much , i will try it out when i get to work and get back to you. Cheers.
Gabriel Fox
Ranch Hand
Joined: Oct 17, 2001
Posts: 170
posted
0
Hello, i got this from the previous reference "Just as the iterate tag provide a parent to other tags, nested tags does the same but there is no logic for iterating or otherwise." Does this mean nested tags cannot be used for looping through a collection. i.e. using : <nested:nest> or <nested:iterate> I did the following in the posted scenario: 1.declared an ArrayList in my XYZActionForm private ArrayList searcList; 2.added setter and getter for ArrayList //ActionForm constructor public XYZActionForm() { searcList=new ArrayList (); } public Object[] getSearchList() { return this.searcList.toArray(); } public void setSearchList(ArrayList list) { this.searcList=list; } 3.The setSearchList(ArrayList) was called in my Action class and passed an ArrayList populated by a DB query via a DataAccess Object (using new SearchEntity(String ID,String department); ). So,unlike the Monkey scenario ,where the list is populated in the constructor. PROBLEM SCENARIO: I need to retrieve the ArrayList poulated by the search , loop thru the ArrayList, displaying a column for ID ,And department in input field. The user can change the department field. So, if he clicks the SAVE button , i want to get the current input for all search records and update the DB. Can i achieve this because the search results are generated at runtime ,hence are not defined in ActionForm. MAY BE! but how does the getSearchList() method defined above inform struts that some form variable are not defined in the ActionForm and they need to be handled like those defined in ActionForm. Your ideas will be so much appreciated.
Jason Menard
Sheriff
Joined: Nov 09, 2000
Posts: 6450
posted
0
If I understand you correctly, your List is made up of SearchEntity objects which contain id and department attributes. If you are trying to save these values back to the form via a submit, you may need a couple more methods in your form: