That makes the TextFields reflect their original model correctly, but it also disposes of any modified values.
For example: 1. List starts with "1", "2", "3" 2. Add two entries "4", "5" 3. Modify "1" to "modified" 4. Remove "2" What I would like to see is: "modified", "3", "4", "5" What I end up seeing is: "1", "3", "", "" On Thu, Aug 2, 2012 at 1:44 PM, Sven Meier <[email protected]> wrote: > After submit your TextFields still have their previous RAW_INPUT, call > form#clearInput() so they render the value from the model. > > Sven > > > On 08/02/2012 05:31 PM, Benjamin Heiskell wrote: >> >> Additions seem to work fine with setReuseItems(true), but I've been >> having trouble with removals. My remove AjaxButton calls >> listView.getList().remove(item.getIndex()), but that always removes >> the last element. Am I making an incorrect assumption about how this >> should work? >> >> The following is a simplified version of my FormComponentPanel that >> replicates the problem. It's used the a CompoundPropertyModel with a >> POJO containing the string list. >> >> public class TextFieldListView extends FormComponentPanel<List<String>> { >> >> private static final long serialVersionUID = 1L; >> >> private final ListView<String> listView; >> >> public TextFieldListView(final String id) { >> super(id); >> >> setOutputMarkupId(true); >> >> listView = new ListView<String>("list") { >> private static final long serialVersionUID = 1L; >> >> @Override >> protected void populateItem(final ListItem<String> item) { >> final TextField<String> textField = new >> TextField<String>("item", item.getModel()); >> >> item.add(textField); >> item.add(new RemoveButton("remove", item)); >> } >> }; >> >> listView.setReuseItems(true); >> >> add(listView); >> add(new AddButton("add")); >> } >> >> @Override >> public void onInitialize() { >> super.onInitialize(); >> listView.setModel(getModel()); >> } >> >> @SuppressWarnings("unchecked") >> protected void convertInput() { >> this.setConvertedInput((List<String>)listView.getList()); >> } >> >> private class AddButton extends AjaxButton { >> >> private static final long serialVersionUID = 1L; >> >> public AddButton(final String id) { >> super(id); >> setDefaultFormProcessing(false); >> } >> >> @Override >> protected void onSubmit(final AjaxRequestTarget target, final >> Form<?> form) { >> listView.getModelObject().add(""); >> target.add(TextFieldListView.this); >> } >> >> @Override >> protected void onError(final AjaxRequestTarget target, final >> Form<?> form) { >> throw new IllegalStateException("AJAX request threw an >> error"); >> } >> } >> >> private class RemoveButton extends AjaxButton { >> >> private static final long serialVersionUID = 1L; >> >> private final ListItem<String> item; >> >> public RemoveButton(final String id, final ListItem<String> item) >> { >> super(id); >> this.item = item; >> setDefaultFormProcessing(false); >> } >> >> @Override >> protected void onSubmit(final AjaxRequestTarget target, final >> Form<?> form) { >> listView.getList().remove(item.getIndex()); >> target.add(TextFieldListView.this); >> } >> >> @Override >> protected void onError(final AjaxRequestTarget target, final >> Form<?> form) { >> throw new IllegalStateException("AJAX request threw an >> error"); >> } >> }; >> } >> >> Thanks! >> >> On Thu, Aug 2, 2012 at 10:13 AM, Andrea Del Bene <[email protected]> >> wrote: >>> >>> Hi, >>> >>> what kind of problem have you encountered with ListView? >>>> >>>> Hi, >>>> >>>> I have a List<String> that I want to represent with TextFields. I need >>>> to be able to dynamically add and remove them via AJAX. >>>> >>>> From what I’ve read online (and experienced firsthand) ListViews do >>>> not seem to be designed for this. >>>> >>>> What is the best way to approach this problem? >>>> >>>> Thanks! >>>> Ben >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: [email protected] >>>> For additional commands, e-mail: [email protected] >>>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [email protected] >>> For additional commands, e-mail: [email protected] >>> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
