Hi- I have a problem creating a dynamic form in jsf. I will try to explain the issue here while being as generic as possible. Apologizing in advance for the length of the question, but I am running into many walls and time is running out on my project. Say there is an application in which a user can select which kind of food they want at a certain number of upcoming meals. The number of upcoming meals is determined by the application. Each meal will get its own 'row' in the form, which will contain 1) a dropdown to select a food type, 2) another dropdown to select some modifier of that food type, 3) a text input to specify the quantity of that food. so, I have a datatable who's "var" attribute is a collection of beans that hold the values of the three datafields for each meal:
there is a method getMeals() in myForm which will return a collection of Meal beans, each containing a data member for food, modifier, and quantity, based on the user's context. This works. Also, the food dropdown is populated by the getAvailableFoods() method, also based on user context. This also works. Now for my problem(s): I'm finding it very hard to dynamically reference the various form components. For instance, I have attached ajax support the the food dropdown. what I would like to happen is, when a user selects a food from the dropdown, the modifiers are dynamically populated in the next dropdown dynamically. For instance, if the user selects 'sandwich' for food, the next dropdown would be populated with 'turkey', roast beef', 'pastrami', etc. If they select 'Fruit' on the first dropdown, the next dropdown gets 'apple', 'pear', 'orange', etc. The problem is- In my target ajax method, how can I access the correct modifier component to add selectItems to? I tried creating collections of components that are part of the meal bean itself, and bind them to the JSF components, but i got the error: Target Unreachable, identifier 'meal' resolved to null. I don't know how to access dynamically generated components programmatically. I also have a similar problem- the validation rules for 'quantity' will change depending on which 'modifier' was selected. How can I dynamically change the validation criteria for that textfield. I have found the methods to do it in the api, but my problem is, how do i get access to the correct 'quantity' textfield that corresponds to the 'modifier' that has changed???
Thank you [ August 21, 2007: Message edited by: Dudley Dawson ]