On 10-Apr-09, at 3:10 PM, Igor Vaynberg wrote:

look at textfield.

all you have to do is to write out the input tags with a name you
obtain from formcomponent.getname() - to guarantee uniqueness, then
override convertinput() and pull those values out of the request into
a collection and call setconvertedinput(collection). formcomponent
will take care of everything else such as validation and updating the
model. thats all there is to it.


Thanks Igor, in my version I had overridden updateModel like so to get it working:

        public void updateModel() {
                String[] added = this.getInputAsArray();
String[] removed = getRequest().getParameters("removed_" + getInputName());
                MultiTextInputModel model = (MultiTextInputModel) 
this.getModel();
model.setItems(added == null ? EMPTY_STRING_COL : Arrays.asList(added)); model.setRemovedItems(removed == null ? EMPTY_STRING_COL : Arrays.asList(removed));
                
        }
I'm assuming that convertInput fires before update model, so I should override that method as you suggest to handle different types but maintain my updateModel as well to shovel things into the right places in the model?

Craig.

-igor

On Fri, Apr 10, 2009 at 10:49 AM, Craig Tataryn <crai...@tataryn.net> wrote:
I have a component I'm designing where it displays a list of items to the user, so the setup for the component on the page might look like this:

      add(new MultiTextInput<Collection<String>>("tags", new
ArrayList<String>() {
       {
               add("apple");
               add("banana");
       }
      }));

The widget will render two sets of hidden inputs, one for the
original/additional items (name="tags") which were entered and one for
deleted items (name="removed_tags").

For instance:

<input type="hidden" name="tags" value="apple"/>
<input type="hidden" name="tags" value="peach"/>
<input type="hidden" name="tags" value="grape"/>
<input type="hidden" name="removed_tags" value="banana"/>

The above would result from me keeping apple and adding peach, grape, and
removing banana.

I'm a bit stuck on how I should get my component to put these values back into it's model? Obviously in behind the scenes I'm going to have to do some stuff in the MultiTextInput ctor to have the incoming Collection added to a composite model that contains both the original/added items and the
removed items.

I'm just not sure where I broker the form submittal so that I have a chance to move the "tags" and "removed_tags" into the proper place in the model for my component. When the user calls getModelObject() on my component they'll
get an object back where they can query model.getItems() and
model.getRemovedItems().

As always, any help greatly appreciated!

Craig.

--
Craig Tataryn
site: http://www.basementcoders.com/
podcast:http://feeds.feedburner.com/TheBasementCoders
irc: ThaDon on freenode #basementcoders, ##wicket, #papernapkin
twitter: craiger

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to