You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Markus Haspl <m....@gmail.com> on 2008/08/06 16:19:50 UTC

ListView in Forms

hi,

first, i'm a very newbie to wicket... I want to add a ListView in a Form.
The ListView has two Texfields and one Checkbox each row. When i submit the
form the values are still the old ones.

here the code:

private class InputForm extends Form {



 IModel pluginPropertiesModel;

 public InputForm(String id, IPlugin plugin){
            super(id);



            final IPlugin Iplugin = plugin;

            pluginPropertiesModel = new LoadableDetachableModel(){
                public Object load()
                {
                    log.debug("load the Model");
                    Iplugin.loadPluginProperties();
                    return pluginProperties;
                }
            };

            ListView propertiesList = new ListView("pluginRepeater",
pluginPropertiesModel) {

                @Override
                public void populateItem(ListItem item)
                {
                    PluginProperties pluginProperties =
(PluginProperties)item.getModelObject();
                    TextField propertiesName = new TextField("name",new
Model(pluginProperties.getName()));
                    TextField propertiesValue = new TextField("value",new
Model(pluginProperties.getValue()));
                    CheckBox propertiesDefault = new
CheckBox("defaultProperty",new Model(pluginProperties.isDefaultProperty()));
                    item.add(propertiesName);
                    item.add(propertiesValue);
                    item.add(propertiesDefault);
                }
            };
            propertiesList.setReuseItems(true);
            add(propertiesList);

        add(new Button("saveButton"));


        }

        public void onSubmit()
        {
            List<PluginProperties> pluginProperties =
(List<PluginProperties>)pluginPropertiesModel.getObject();
            for(PluginProperties property:pluginProperties){
                info(""+property.getName()+": "+property.getValue()+" ==
"+property.isDefaultProperty());
                log.debug(""+property.getName()+": "+property.getValue()+"
== "+property.isDefaultProperty());
            }




        }
    }


thanks in advance
markus

Re: ListView in Forms

Posted by Markus Haspl <m....@gmail.com>.
hi,

thanks. this works!!!! :-)

avajon

On Sat, Aug 9, 2008 at 1:11 AM, brian.diekelman <de...@gmail.com> wrote:

>
>
> There are a few things going on here... try this and see if it does what
> you
> want it to do.  If so reply back and I'll explain what the underlying issue
> was:
>
> TextField propertiesName = new TextField("name",new
> PropertyModel(pluginProperties, "name"));
> TextField propertiesValue = new TextField("value",new
> PropertyModel(pluginProperties, "value"));
> CheckBox propertiesDefault = new CheckBox("defaultProperty",new
> PropertyModel(pluginProperties, "defaultProperty"));
>
>
> Markus Haspl wrote:
> >
> > no, there aren't any errors.
> >
> > but i don't understand why i have to use propertiesName.getModelObject();
> > in
> > the onSubmit() method. Because there may be hundrets of propertiesName in
> > the ListView/Form.
> >
> > Would it be better to make a Forms in a ListView? But then i need for
> > every
> > Form a submit-button. that wouldn't be so nice...
> >
> > thanks
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/ListView-in-Forms-tp18852263p18900382.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: ListView in Forms

Posted by "brian.diekelman" <de...@gmail.com>.

There are a few things going on here... try this and see if it does what you
want it to do.  If so reply back and I'll explain what the underlying issue
was:

TextField propertiesName = new TextField("name",new
PropertyModel(pluginProperties, "name"));
TextField propertiesValue = new TextField("value",new
PropertyModel(pluginProperties, "value"));
CheckBox propertiesDefault = new CheckBox("defaultProperty",new
PropertyModel(pluginProperties, "defaultProperty")); 


Markus Haspl wrote:
> 
> no, there aren't any errors.
> 
> but i don't understand why i have to use propertiesName.getModelObject();
> in
> the onSubmit() method. Because there may be hundrets of propertiesName in
> the ListView/Form.
> 
> Would it be better to make a Forms in a ListView? But then i need for
> every
> Form a submit-button. that wouldn't be so nice...
> 
> thanks
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/ListView-in-Forms-tp18852263p18900382.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: ListView in Forms

Posted by Igor Vaynberg <ig...@gmail.com>.
On Thu, Aug 7, 2008 at 1:36 AM, Markus Haspl <m....@gmail.com> wrote:
> no, there aren't any errors.
>
> but i don't understand why i have to use propertiesName.getModelObject(); in
> the onSubmit() method. Because there may be hundrets of propertiesName in
> the ListView/Form.

well, it is the way you setup the model by doing new model(value), so
the model acts as the container for the value rather then some glue
between value and some other container such as a class field. see the
models page on the wiki.

-igor


>
> Would it be better to make a Forms in a ListView? But then i need for every
> Form a submit-button. that wouldn't be so nice...
>
> thanks
>
> On Wed, Aug 6, 2008 at 7:01 PM, Igor Vaynberg <ig...@gmail.com>wrote:
>
>> if there are no errors then you are not using your models properly
>>
>>  TextField propertiesName = new TextField("name",new
>> Model(pluginProperties.getName()));
>>
>> to get a value back with a model like that you would have to call
>> propertiesName.getModelObject()
>>
>> -igor
>>
>> On Wed, Aug 6, 2008 at 8:27 AM, Markus Haspl <m....@gmail.com> wrote:
>> > there are no valiation errors. with info() i get the old values.
>> >  info(""+property.getName()+": "+property.getValue()+" ==
>> > "+property.isDefaultProperty());
>> >
>> >
>> > On Wed, Aug 6, 2008 at 5:03 PM, Igor Vaynberg <igor.vaynberg@gmail.com
>> >wrote:
>> >
>> >> add a feedbackpanel and see if there are any validation errors
>> >>
>> >> -igor
>> >>
>> >> On Wed, Aug 6, 2008 at 7:19 AM, Markus Haspl <m....@gmail.com> wrote:
>> >> > hi,
>> >> >
>> >> > first, i'm a very newbie to wicket... I want to add a ListView in a
>> Form.
>> >> > The ListView has two Texfields and one Checkbox each row. When i
>> submit
>> >> the
>> >> > form the values are still the old ones.
>> >> >
>> >> > here the code:
>> >> >
>> >> > private class InputForm extends Form {
>> >> >
>> >> >
>> >> >
>> >> >  IModel pluginPropertiesModel;
>> >> >
>> >> >  public InputForm(String id, IPlugin plugin){
>> >> >            super(id);
>> >> >
>> >> >
>> >> >
>> >> >            final IPlugin Iplugin = plugin;
>> >> >
>> >> >            pluginPropertiesModel = new LoadableDetachableModel(){
>> >> >                public Object load()
>> >> >                {
>> >> >                    log.debug("load the Model");
>> >> >                    Iplugin.loadPluginProperties();
>> >> >                    return pluginProperties;
>> >> >                }
>> >> >            };
>> >> >
>> >> >            ListView propertiesList = new ListView("pluginRepeater",
>> >> > pluginPropertiesModel) {
>> >> >
>> >> >                @Override
>> >> >                public void populateItem(ListItem item)
>> >> >                {
>> >> >                    PluginProperties pluginProperties =
>> >> > (PluginProperties)item.getModelObject();
>> >> >                    TextField propertiesName = new TextField("name",new
>> >> > Model(pluginProperties.getName()));
>> >> >                    TextField propertiesValue = new
>> TextField("value",new
>> >> > Model(pluginProperties.getValue()));
>> >> >                    CheckBox propertiesDefault = new
>> >> > CheckBox("defaultProperty",new
>> >> Model(pluginProperties.isDefaultProperty()));
>> >> >                    item.add(propertiesName);
>> >> >                    item.add(propertiesValue);
>> >> >                    item.add(propertiesDefault);
>> >> >                }
>> >> >            };
>> >> >            propertiesList.setReuseItems(true);
>> >> >            add(propertiesList);
>> >> >
>> >> >        add(new Button("saveButton"));
>> >> >
>> >> >
>> >> >        }
>> >> >
>> >> >        public void onSubmit()
>> >> >        {
>> >> >            List<PluginProperties> pluginProperties =
>> >> > (List<PluginProperties>)pluginPropertiesModel.getObject();
>> >> >            for(PluginProperties property:pluginProperties){
>> >> >                info(""+property.getName()+": "+property.getValue()+"
>> ==
>> >> > "+property.isDefaultProperty());
>> >> >                log.debug(""+property.getName()+":
>> "+property.getValue()+"
>> >> > == "+property.isDefaultProperty());
>> >> >            }
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >        }
>> >> >    }
>> >> >
>> >> >
>> >> > thanks in advance
>> >> > markus
>> >> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> For additional commands, e-mail: users-help@wicket.apache.org
>> >>
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

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


Re: ListView in Forms

Posted by Markus Haspl <m....@gmail.com>.
no, there aren't any errors.

but i don't understand why i have to use propertiesName.getModelObject(); in
the onSubmit() method. Because there may be hundrets of propertiesName in
the ListView/Form.

Would it be better to make a Forms in a ListView? But then i need for every
Form a submit-button. that wouldn't be so nice...

thanks

On Wed, Aug 6, 2008 at 7:01 PM, Igor Vaynberg <ig...@gmail.com>wrote:

> if there are no errors then you are not using your models properly
>
>  TextField propertiesName = new TextField("name",new
> Model(pluginProperties.getName()));
>
> to get a value back with a model like that you would have to call
> propertiesName.getModelObject()
>
> -igor
>
> On Wed, Aug 6, 2008 at 8:27 AM, Markus Haspl <m....@gmail.com> wrote:
> > there are no valiation errors. with info() i get the old values.
> >  info(""+property.getName()+": "+property.getValue()+" ==
> > "+property.isDefaultProperty());
> >
> >
> > On Wed, Aug 6, 2008 at 5:03 PM, Igor Vaynberg <igor.vaynberg@gmail.com
> >wrote:
> >
> >> add a feedbackpanel and see if there are any validation errors
> >>
> >> -igor
> >>
> >> On Wed, Aug 6, 2008 at 7:19 AM, Markus Haspl <m....@gmail.com> wrote:
> >> > hi,
> >> >
> >> > first, i'm a very newbie to wicket... I want to add a ListView in a
> Form.
> >> > The ListView has two Texfields and one Checkbox each row. When i
> submit
> >> the
> >> > form the values are still the old ones.
> >> >
> >> > here the code:
> >> >
> >> > private class InputForm extends Form {
> >> >
> >> >
> >> >
> >> >  IModel pluginPropertiesModel;
> >> >
> >> >  public InputForm(String id, IPlugin plugin){
> >> >            super(id);
> >> >
> >> >
> >> >
> >> >            final IPlugin Iplugin = plugin;
> >> >
> >> >            pluginPropertiesModel = new LoadableDetachableModel(){
> >> >                public Object load()
> >> >                {
> >> >                    log.debug("load the Model");
> >> >                    Iplugin.loadPluginProperties();
> >> >                    return pluginProperties;
> >> >                }
> >> >            };
> >> >
> >> >            ListView propertiesList = new ListView("pluginRepeater",
> >> > pluginPropertiesModel) {
> >> >
> >> >                @Override
> >> >                public void populateItem(ListItem item)
> >> >                {
> >> >                    PluginProperties pluginProperties =
> >> > (PluginProperties)item.getModelObject();
> >> >                    TextField propertiesName = new TextField("name",new
> >> > Model(pluginProperties.getName()));
> >> >                    TextField propertiesValue = new
> TextField("value",new
> >> > Model(pluginProperties.getValue()));
> >> >                    CheckBox propertiesDefault = new
> >> > CheckBox("defaultProperty",new
> >> Model(pluginProperties.isDefaultProperty()));
> >> >                    item.add(propertiesName);
> >> >                    item.add(propertiesValue);
> >> >                    item.add(propertiesDefault);
> >> >                }
> >> >            };
> >> >            propertiesList.setReuseItems(true);
> >> >            add(propertiesList);
> >> >
> >> >        add(new Button("saveButton"));
> >> >
> >> >
> >> >        }
> >> >
> >> >        public void onSubmit()
> >> >        {
> >> >            List<PluginProperties> pluginProperties =
> >> > (List<PluginProperties>)pluginPropertiesModel.getObject();
> >> >            for(PluginProperties property:pluginProperties){
> >> >                info(""+property.getName()+": "+property.getValue()+"
> ==
> >> > "+property.isDefaultProperty());
> >> >                log.debug(""+property.getName()+":
> "+property.getValue()+"
> >> > == "+property.isDefaultProperty());
> >> >            }
> >> >
> >> >
> >> >
> >> >
> >> >        }
> >> >    }
> >> >
> >> >
> >> > thanks in advance
> >> > markus
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: ListView in Forms

Posted by Igor Vaynberg <ig...@gmail.com>.
if there are no errors then you are not using your models properly

 TextField propertiesName = new TextField("name",new
Model(pluginProperties.getName()));

to get a value back with a model like that you would have to call
propertiesName.getModelObject()

-igor

On Wed, Aug 6, 2008 at 8:27 AM, Markus Haspl <m....@gmail.com> wrote:
> there are no valiation errors. with info() i get the old values.
>  info(""+property.getName()+": "+property.getValue()+" ==
> "+property.isDefaultProperty());
>
>
> On Wed, Aug 6, 2008 at 5:03 PM, Igor Vaynberg <ig...@gmail.com>wrote:
>
>> add a feedbackpanel and see if there are any validation errors
>>
>> -igor
>>
>> On Wed, Aug 6, 2008 at 7:19 AM, Markus Haspl <m....@gmail.com> wrote:
>> > hi,
>> >
>> > first, i'm a very newbie to wicket... I want to add a ListView in a Form.
>> > The ListView has two Texfields and one Checkbox each row. When i submit
>> the
>> > form the values are still the old ones.
>> >
>> > here the code:
>> >
>> > private class InputForm extends Form {
>> >
>> >
>> >
>> >  IModel pluginPropertiesModel;
>> >
>> >  public InputForm(String id, IPlugin plugin){
>> >            super(id);
>> >
>> >
>> >
>> >            final IPlugin Iplugin = plugin;
>> >
>> >            pluginPropertiesModel = new LoadableDetachableModel(){
>> >                public Object load()
>> >                {
>> >                    log.debug("load the Model");
>> >                    Iplugin.loadPluginProperties();
>> >                    return pluginProperties;
>> >                }
>> >            };
>> >
>> >            ListView propertiesList = new ListView("pluginRepeater",
>> > pluginPropertiesModel) {
>> >
>> >                @Override
>> >                public void populateItem(ListItem item)
>> >                {
>> >                    PluginProperties pluginProperties =
>> > (PluginProperties)item.getModelObject();
>> >                    TextField propertiesName = new TextField("name",new
>> > Model(pluginProperties.getName()));
>> >                    TextField propertiesValue = new TextField("value",new
>> > Model(pluginProperties.getValue()));
>> >                    CheckBox propertiesDefault = new
>> > CheckBox("defaultProperty",new
>> Model(pluginProperties.isDefaultProperty()));
>> >                    item.add(propertiesName);
>> >                    item.add(propertiesValue);
>> >                    item.add(propertiesDefault);
>> >                }
>> >            };
>> >            propertiesList.setReuseItems(true);
>> >            add(propertiesList);
>> >
>> >        add(new Button("saveButton"));
>> >
>> >
>> >        }
>> >
>> >        public void onSubmit()
>> >        {
>> >            List<PluginProperties> pluginProperties =
>> > (List<PluginProperties>)pluginPropertiesModel.getObject();
>> >            for(PluginProperties property:pluginProperties){
>> >                info(""+property.getName()+": "+property.getValue()+" ==
>> > "+property.isDefaultProperty());
>> >                log.debug(""+property.getName()+": "+property.getValue()+"
>> > == "+property.isDefaultProperty());
>> >            }
>> >
>> >
>> >
>> >
>> >        }
>> >    }
>> >
>> >
>> > thanks in advance
>> > markus
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

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


Re: ListView in Forms

Posted by Markus Haspl <m....@gmail.com>.
there are no valiation errors. with info() i get the old values.
 info(""+property.getName()+": "+property.getValue()+" ==
"+property.isDefaultProperty());


On Wed, Aug 6, 2008 at 5:03 PM, Igor Vaynberg <ig...@gmail.com>wrote:

> add a feedbackpanel and see if there are any validation errors
>
> -igor
>
> On Wed, Aug 6, 2008 at 7:19 AM, Markus Haspl <m....@gmail.com> wrote:
> > hi,
> >
> > first, i'm a very newbie to wicket... I want to add a ListView in a Form.
> > The ListView has two Texfields and one Checkbox each row. When i submit
> the
> > form the values are still the old ones.
> >
> > here the code:
> >
> > private class InputForm extends Form {
> >
> >
> >
> >  IModel pluginPropertiesModel;
> >
> >  public InputForm(String id, IPlugin plugin){
> >            super(id);
> >
> >
> >
> >            final IPlugin Iplugin = plugin;
> >
> >            pluginPropertiesModel = new LoadableDetachableModel(){
> >                public Object load()
> >                {
> >                    log.debug("load the Model");
> >                    Iplugin.loadPluginProperties();
> >                    return pluginProperties;
> >                }
> >            };
> >
> >            ListView propertiesList = new ListView("pluginRepeater",
> > pluginPropertiesModel) {
> >
> >                @Override
> >                public void populateItem(ListItem item)
> >                {
> >                    PluginProperties pluginProperties =
> > (PluginProperties)item.getModelObject();
> >                    TextField propertiesName = new TextField("name",new
> > Model(pluginProperties.getName()));
> >                    TextField propertiesValue = new TextField("value",new
> > Model(pluginProperties.getValue()));
> >                    CheckBox propertiesDefault = new
> > CheckBox("defaultProperty",new
> Model(pluginProperties.isDefaultProperty()));
> >                    item.add(propertiesName);
> >                    item.add(propertiesValue);
> >                    item.add(propertiesDefault);
> >                }
> >            };
> >            propertiesList.setReuseItems(true);
> >            add(propertiesList);
> >
> >        add(new Button("saveButton"));
> >
> >
> >        }
> >
> >        public void onSubmit()
> >        {
> >            List<PluginProperties> pluginProperties =
> > (List<PluginProperties>)pluginPropertiesModel.getObject();
> >            for(PluginProperties property:pluginProperties){
> >                info(""+property.getName()+": "+property.getValue()+" ==
> > "+property.isDefaultProperty());
> >                log.debug(""+property.getName()+": "+property.getValue()+"
> > == "+property.isDefaultProperty());
> >            }
> >
> >
> >
> >
> >        }
> >    }
> >
> >
> > thanks in advance
> > markus
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

RE: ListView in Forms

Posted by "Hoover, William " <wh...@nemours.org>.
That is an issue in itself ;o) 

-----Original Message-----
From: Igor Vaynberg [mailto:igor.vaynberg@gmail.com] 
Sent: Wednesday, August 06, 2008 1:00 PM
To: users@wicket.apache.org
Subject: Re: ListView in Forms

listviews dont use item reuse strategies...

-igor

On Wed, Aug 6, 2008 at 9:25 AM, Hoover, William <wh...@nemours.org>
wrote:
> If there are errors try setting this strategy on your list view:
>
> public class ReuseOnFeedbackMessageStrategy implements 
> IItemReuseStrategy {
>
>        private static final long serialVersionUID = 1L;
>        private static final int LEVEL_NA = 0;
>        private int feedbackMessageThresholdLevel;
>        private FeedbackMessageLevelComparator 
> feedbackMessageLevelComparator;
>        private int upperThresholdLevel;
>
>        /**
>         * Constructs a new ReuseOnFeedbackMessageStrategy taking an 
> feedbackMessageLevelComparator that does not require a lower/upper 
> bound threshold level.
>         *
>         * @param feedbackMessageLevelComparator
>         *            the {@link FeedbackMessageLevelComparator} to be
> used when comparing the active message with the threshold
>         * @param feedbackMessageThresholdLevel
>         *            the threshold level to be compared
>         */
>        public ReuseOnFeedbackMessageStrategy(final
> FeedbackMessageLevelComparator feedbackMessageLevelComparator, final 
> int
> feedbackMessageThresholdLevel) {
>                super();
>                if
> (feedbackMessageLevelComparator.isLowerAndUpperBoundRequired) {
>                        throw new IllegalArgumentException("This 
> feedbackMessageLevelComparator requires a lower/upper bound threshold 
> level and so it is not allowed within this constructor (see
javadoc).");
>                }
>                init(feedbackMessageLevelComparator,
> feedbackMessageThresholdLevel, LEVEL_NA);
>        }
>
>        /**
>         * Constructs a new ReuseOnFeedbackMessageStrategy. Accepts a 
> feedbackMessageLevelComparator that requires both a lower and upper 
> bound feedback level (typically used with a
>         * {@link FeedbackMessageLevelComparator#BETWEEN}
> feedbackMessageLevelComparator).
>         *
>         * @param feedbackMessageLevelComparator
>         *            the {@link FeedbackMessageLevelComparator} to be
> used when comparing the active message with a lower and upper bound 
> threshold level
>         * @param lowerThresholdLevel
>         *            the threshold lower bound feedback message level
>         * @param upperThresholdLevel
>         *            the threshold upper bound feedback message level
>         */
>        public ReuseOnFeedbackMessageStrategy(final
> FeedbackMessageLevelComparator feedbackMessageLevelComparator, final 
> int lowerThresholdLevel, final int upperThresholdLevel) {
>                super();
>                if
> (!feedbackMessageLevelComparator.isLowerAndUpperBoundRequired) {
>                        throw new IllegalArgumentException(
>                                        "This 
> feedbackMessageLevelComparator does not require a lower/upper bound 
> threshold level and so it is not allowed within this constructor (see 
> javadoc).");
>                }
>                init(feedbackMessageLevelComparator,
> lowerThresholdLevel, upperThresholdLevel);
>        }
>
>        /**
>         * Initialized the ReuseOnFeedbackMessageStrategy.
>         *
>         * @param boundaryOperator
>         *            the {@link FeedbackMessageLevelComparator} to be
> used when comparing the active message with the threshold
>         * @param lowerBoundThresholdLevel
>         *            the threshold lower bound feedback message level
> or a single threshold for operators that only require one threshold 
> value (i.e. =, <, >, <=, or >=)
>         * @param upperBoundThresholdLevel
>         *            the threshold upper bound feedback message level
>         */
>        private final void init(final FeedbackMessageLevelComparator 
> boundaryOperator, final int lowerBoundThresholdLevel, final int
> upperBoundThresholdLevel) {
>                setFeedbackMessageLevelComparator(boundaryOperator);
>
> setFeedbackMessageThresholdLevel(lowerBoundThresholdLevel);
>                setUpperThresholdLevel(upperBoundThresholdLevel);
>        }
>
>        /**
>         * {@inheritDoc}
>         */
>        @SuppressWarnings("unchecked")
>        @Override
>        public final Iterator<Item> getItems(final IItemFactory 
> factory, final Iterator newModels, final Iterator existingItems) {
>                final List<Item> existingItemList = new 
> ArrayList<Item>();
>
>                while (existingItems.hasNext()) {
>                        existingItemList.add((Item) 
> existingItems.next());
>                }
>
>                return new Iterator<Item>() {
>                        private int index = 0;
>                        private transient Boolean hasMessage;
>
>                        /**
>                         * {@inheritDoc}
>                         */
>                        @Override
>                        public final boolean hasNext() {
>                                return newModels.hasNext();
>                        }
>
>                        /**
>                         * {@inheritDoc}
>                         */
>                        @Override
>                        public final Item next() {
>                                final IModel model = (IModel) 
> newModels.next();
>                                final Item item;
>
>                                if (hasMessage == null) {
>                                        hasMessage = 
> hasFeedbackMessage();
>                                }
>                                if (hasMessage &&
> !existingItemList.isEmpty()) {
>                                        // validation error was found, 
> set existing items
>                                        item = 
> existingItemList.get(index);
>                                        item.setIndex(index);
>                                } else {
>                                        // no validation error, set new

> items
>                                        item = factory.newItem(index, 
> model);
>                                }
>                                index++;
>
>                                if (!hasNext()) {
>                                        hasMessage = null;
>                                }
>                                return item;
>                        }
>
>                        /**
>                         * {@inheritDoc}
>                         */
>                        @Override
>                        public final void remove() {
>                                throw new 
> UnsupportedOperationException();
>                        }
>                };
>        }
>
>        /**
>         * Search through the wicket feed back messages within the 
> session and determine if there are any messages that meet the given 
> criteria based on the supplied feedbackMessageLevelComparator and
>         * feedbackMessage threshold level.
>         *
>         * @return true if a feedbackMessage was found within the 
> session that meets the criteria specified.
>         */
>        @SuppressWarnings("unchecked")
>        private final boolean hasFeedbackMessage() {
>                FeedbackMessage feedbackMessage;
>                for (final Iterator<FeedbackMessage> iter = 
> Session.get().getFeedbackMessages().iterator(); iter.hasNext();) {
>                        feedbackMessage = iter.next();
>                        if
> (getFeedbackMessageLevelComparator().compare(feedbackMessage,
> getFeedbackMessageThresholdLevel(), getUpperThresholdLevel())) {
>                                onFeedbackMessage(feedbackMessage);
>                                return true;
>                        }
>                }
>                return false;
>        }
>
>        /**
>         * Called in the event that a feedback message was found
>         *
>         * @param feedbackMessage
>         *            the found feedback message
>         */
>        protected void onFeedbackMessage(final FeedbackMessage
> feedbackMessage) {
>                // override if needed
>        }
>
>        /**
>         * Gets the feedbackMessageLevelComparator.
>         *
>         * @return the feedbackMessageLevelComparator to get.
>         */
>        private final FeedbackMessageLevelComparator
> getFeedbackMessageLevelComparator() {
>                return feedbackMessageLevelComparator;
>        }
>
>        /**
>         * Sets the feedbackMessageLevelComparator.
>         *
>         * @param feedbackMessageLevelComparator
>         *            the feedbackMessageLevelComparator to set
>         */
>        private final void setFeedbackMessageLevelComparator(final
> FeedbackMessageLevelComparator feedbackMessageLevelComparator) {
>                this.feedbackMessageLevelComparator = 
> feedbackMessageLevelComparator;
>        }
>
>        /**
>         * Gets the feed back message threshold level.
>         *
>         * @return the feedbackMessageThresholdLevel to get.
>         */
>        public final int getFeedbackMessageThresholdLevel() {
>                return feedbackMessageThresholdLevel;
>        }
>
>        /**
>         * Sets the feedback message threshold level.
>         *
>         * @param feedbackMessageThresholdLevel
>         *            the feedbackMessageThresholdLevel to set
>         */
>        public final void setFeedbackMessageThresholdLevel(final int
> feedbackMessageThresholdLevel) {
>                this.feedbackMessageThresholdLevel = 
> feedbackMessageThresholdLevel;
>        }
>
>        /**
>         * Gets the upper threshold level.
>         *
>         * @return the upperThresholdLevel to get.
>         */
>        private final int getUpperThresholdLevel() {
>                return upperThresholdLevel;
>        }
>
>        /**
>         * Sets the upper threshold level.
>         *
>         * @param upperThresholdLevel
>         *            the upperThresholdLevel to set.
>         */
>        private final void setUpperThresholdLevel(final int
> upperThresholdLevel) {
>                // TODO : Consider exposing Upper threshold level to 
> outside.
>                this.upperThresholdLevel = upperThresholdLevel;
>        }
>
>        /**
>         * Comparators used in feedback message level comparison : <br 
> />
>         * <ol>
>         * <li>{@link FeedbackMessageLevelComparator#EQ}</li>
>         * <li>{@link FeedbackMessageLevelComparator#LT}</li>
>         * <li>{@link FeedbackMessageLevelComparator#GT}</li>
>         * <li>{@link FeedbackMessageLevelComparator#LTE}</li>
>         * <li>{@link FeedbackMessageLevelComparator#GTE}</li>
>         * <li>{@link FeedbackMessageLevelComparator#BETWEEN}</li>
>         * </ol>
>         */
>        public enum FeedbackMessageLevelComparator {
>
>                /**
>                 * EQUAL FeedbackMessageLevelComparator. ({@literal
=}).
>                 */
>                EQ(false),
>
>                /**
>                 * Less than feedbackMessageLevelComparator. ({@literal

> <}).
>                 */
>                LT(false),
>
>                /**
>                 * Greater than feedbackMessageLevelComparator 
> ({@literal >}).
>                 */
>                GT(false),
>
>                /**
>                 * Less than equal to feedbackMessageLevelComparator 
> ({@literal <=}).
>                 */
>                LTE(false),
>
>                /**
>                 * Greater than or equal to 
> feedbackMessageLevelComparator ({@literal >=}).
>                 */
>                GTE(false),
>
>                /**
>                 * Between feedbackMessageLevelComparator.Between (and
> including) a lower and upper bound threshold
>                 */
>                BETWEEN(true);
>
>                /**
>                 * flag indicating if lower and upper bound are to be 
> specified.
>                 */
>                private boolean isLowerAndUpperBoundRequired;
>
>                /**
>                 * Default constructor.
>                 *
>                 * @param isLowerAndUpperBoundRequired
>                 *            flag to indicate whether or not both a
> lower and upper bound value are required for this 
> feedbackMessageLevelComparator.
>                 */
>                private FeedbackMessageLevelComparator(final boolean
> isLowerAndUpperBoundRequired) {
>                        this.isLowerAndUpperBoundRequired = 
> isLowerAndUpperBoundRequired;
>                }
>
>                /**
>                 * @return true if this feedbackMessageLevelComparator 
> requires both a lower and upper bound threshold level. Otherwise the 
> feedbackMessageLevelComparator only requires a single bound value.
>                 */
>                public final boolean isLowerAndUpperBoundRequired() {
>                        return isLowerAndUpperBoundRequired;
>                }
>
>                /**
>                 * Compares the received active feedbackMessage's level

> based on the feedbackMessageLevelComparator.
>                 *
>                 * @param activeMessage
>                 *            the FeedbackMessage to compare
>                 * @param thresholdLevel
>                 *            the threshold level to be compared (may
> act as lower bound threshold for comparators that require lower/upper)
>                 * @param upperBoundThresholdLevel
>                 *            the threshold upper bound feedback
message
> level (used only for comparators that require it)
>                 *
>                 * @return true if the operation is satisfied based on 
> the feedbackMessageLevelComparator (i.e. 500 == 500)
>                 */
>                public final boolean compare(final FeedbackMessage 
> activeMessage, final int thresholdLevel, final int
> upperBoundThresholdLevel) {
>                        final boolean isValid;
>                        switch (this) {
>                        case EQ:
>                                isValid = activeMessage.getLevel() == 
> thresholdLevel;
>                                break;
>                        case LT:
>                                isValid = activeMessage.getLevel() < 
> thresholdLevel;
>                                break;
>                        case GT:
>                                isValid = activeMessage.getLevel() > 
> thresholdLevel;
>                                break;
>                        case LTE:
>                                isValid = activeMessage.getLevel() <= 
> thresholdLevel;
>                                break;
>                        case GTE:
>                                isValid = activeMessage.getLevel() >= 
> thresholdLevel;
>                                break;
>                        case BETWEEN:
>                                isValid = thresholdLevel <=
> activeMessage.getLevel() && activeMessage.getLevel() <= 
> upperBoundThresholdLevel;
>                                break;
>                        default:
>                                isValid = false;
>                        }
>                        return isValid;
>                }
>        }
> }
>
> -----Original Message-----
> From: Igor Vaynberg [mailto:igor.vaynberg@gmail.com]
> Sent: Wednesday, August 06, 2008 11:04 AM
> To: users@wicket.apache.org
> Subject: Re: ListView in Forms
>
> add a feedbackpanel and see if there are any validation errors
>
> -igor
>
> On Wed, Aug 6, 2008 at 7:19 AM, Markus Haspl <m....@gmail.com>
wrote:
>> hi,
>>
>> first, i'm a very newbie to wicket... I want to add a ListView in a
> Form.
>> The ListView has two Texfields and one Checkbox each row. When i 
>> submit the form the values are still the old ones.
>>
>> here the code:
>>
>> private class InputForm extends Form {
>>
>>
>>
>>  IModel pluginPropertiesModel;
>>
>>  public InputForm(String id, IPlugin plugin){
>>            super(id);
>>
>>
>>
>>            final IPlugin Iplugin = plugin;
>>
>>            pluginPropertiesModel = new LoadableDetachableModel(){
>>                public Object load()
>>                {
>>                    log.debug("load the Model");
>>                    Iplugin.loadPluginProperties();
>>                    return pluginProperties;
>>                }
>>            };
>>
>>            ListView propertiesList = new ListView("pluginRepeater",
>> pluginPropertiesModel) {
>>
>>                @Override
>>                public void populateItem(ListItem item)
>>                {
>>                    PluginProperties pluginProperties = 
>> (PluginProperties)item.getModelObject();
>>                    TextField propertiesName = new 
>> TextField("name",new
>
>> Model(pluginProperties.getName()));
>>                    TextField propertiesValue = new 
>> TextField("value",new Model(pluginProperties.getValue()));
>>                    CheckBox propertiesDefault = new 
>> CheckBox("defaultProperty",new
> Model(pluginProperties.isDefaultProperty()));
>>                    item.add(propertiesName);
>>                    item.add(propertiesValue);
>>                    item.add(propertiesDefault);
>>                }
>>            };
>>            propertiesList.setReuseItems(true);
>>            add(propertiesList);
>>
>>        add(new Button("saveButton"));
>>
>>
>>        }
>>
>>        public void onSubmit()
>>        {
>>            List<PluginProperties> pluginProperties = 
>> (List<PluginProperties>)pluginPropertiesModel.getObject();
>>            for(PluginProperties property:pluginProperties){
>>                info(""+property.getName()+": "+property.getValue()+"
>> == "+property.isDefaultProperty());
>>                log.debug(""+property.getName()+":
> "+property.getValue()+"
>> == "+property.isDefaultProperty());
>>            }
>>
>>
>>
>>
>>        }
>>    }
>>
>>
>> thanks in advance
>> markus
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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



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


Re: ListView in Forms

Posted by Igor Vaynberg <ig...@gmail.com>.
listviews dont use item reuse strategies...

-igor

On Wed, Aug 6, 2008 at 9:25 AM, Hoover, William <wh...@nemours.org> wrote:
> If there are errors try setting this strategy on your list view:
>
> public class ReuseOnFeedbackMessageStrategy implements
> IItemReuseStrategy {
>
>        private static final long serialVersionUID = 1L;
>        private static final int LEVEL_NA = 0;
>        private int feedbackMessageThresholdLevel;
>        private FeedbackMessageLevelComparator
> feedbackMessageLevelComparator;
>        private int upperThresholdLevel;
>
>        /**
>         * Constructs a new ReuseOnFeedbackMessageStrategy taking an
> feedbackMessageLevelComparator that does not require a lower/upper bound
> threshold level.
>         *
>         * @param feedbackMessageLevelComparator
>         *            the {@link FeedbackMessageLevelComparator} to be
> used when comparing the active message with the threshold
>         * @param feedbackMessageThresholdLevel
>         *            the threshold level to be compared
>         */
>        public ReuseOnFeedbackMessageStrategy(final
> FeedbackMessageLevelComparator feedbackMessageLevelComparator, final int
> feedbackMessageThresholdLevel) {
>                super();
>                if
> (feedbackMessageLevelComparator.isLowerAndUpperBoundRequired) {
>                        throw new IllegalArgumentException("This
> feedbackMessageLevelComparator requires a lower/upper bound threshold
> level and so it is not allowed within this constructor (see javadoc).");
>                }
>                init(feedbackMessageLevelComparator,
> feedbackMessageThresholdLevel, LEVEL_NA);
>        }
>
>        /**
>         * Constructs a new ReuseOnFeedbackMessageStrategy. Accepts a
> feedbackMessageLevelComparator that requires both a lower and upper
> bound feedback level (typically used with a
>         * {@link FeedbackMessageLevelComparator#BETWEEN}
> feedbackMessageLevelComparator).
>         *
>         * @param feedbackMessageLevelComparator
>         *            the {@link FeedbackMessageLevelComparator} to be
> used when comparing the active message with a lower and upper bound
> threshold level
>         * @param lowerThresholdLevel
>         *            the threshold lower bound feedback message level
>         * @param upperThresholdLevel
>         *            the threshold upper bound feedback message level
>         */
>        public ReuseOnFeedbackMessageStrategy(final
> FeedbackMessageLevelComparator feedbackMessageLevelComparator, final int
> lowerThresholdLevel, final int upperThresholdLevel) {
>                super();
>                if
> (!feedbackMessageLevelComparator.isLowerAndUpperBoundRequired) {
>                        throw new IllegalArgumentException(
>                                        "This
> feedbackMessageLevelComparator does not require a lower/upper bound
> threshold level and so it is not allowed within this constructor (see
> javadoc).");
>                }
>                init(feedbackMessageLevelComparator,
> lowerThresholdLevel, upperThresholdLevel);
>        }
>
>        /**
>         * Initialized the ReuseOnFeedbackMessageStrategy.
>         *
>         * @param boundaryOperator
>         *            the {@link FeedbackMessageLevelComparator} to be
> used when comparing the active message with the threshold
>         * @param lowerBoundThresholdLevel
>         *            the threshold lower bound feedback message level
> or a single threshold for operators that only require one threshold
> value (i.e. =, <, >, <=, or >=)
>         * @param upperBoundThresholdLevel
>         *            the threshold upper bound feedback message level
>         */
>        private final void init(final FeedbackMessageLevelComparator
> boundaryOperator, final int lowerBoundThresholdLevel, final int
> upperBoundThresholdLevel) {
>                setFeedbackMessageLevelComparator(boundaryOperator);
>
> setFeedbackMessageThresholdLevel(lowerBoundThresholdLevel);
>                setUpperThresholdLevel(upperBoundThresholdLevel);
>        }
>
>        /**
>         * {@inheritDoc}
>         */
>        @SuppressWarnings("unchecked")
>        @Override
>        public final Iterator<Item> getItems(final IItemFactory factory,
> final Iterator newModels, final Iterator existingItems) {
>                final List<Item> existingItemList = new
> ArrayList<Item>();
>
>                while (existingItems.hasNext()) {
>                        existingItemList.add((Item)
> existingItems.next());
>                }
>
>                return new Iterator<Item>() {
>                        private int index = 0;
>                        private transient Boolean hasMessage;
>
>                        /**
>                         * {@inheritDoc}
>                         */
>                        @Override
>                        public final boolean hasNext() {
>                                return newModels.hasNext();
>                        }
>
>                        /**
>                         * {@inheritDoc}
>                         */
>                        @Override
>                        public final Item next() {
>                                final IModel model = (IModel)
> newModels.next();
>                                final Item item;
>
>                                if (hasMessage == null) {
>                                        hasMessage =
> hasFeedbackMessage();
>                                }
>                                if (hasMessage &&
> !existingItemList.isEmpty()) {
>                                        // validation error was found,
> set existing items
>                                        item =
> existingItemList.get(index);
>                                        item.setIndex(index);
>                                } else {
>                                        // no validation error, set new
> items
>                                        item = factory.newItem(index,
> model);
>                                }
>                                index++;
>
>                                if (!hasNext()) {
>                                        hasMessage = null;
>                                }
>                                return item;
>                        }
>
>                        /**
>                         * {@inheritDoc}
>                         */
>                        @Override
>                        public final void remove() {
>                                throw new
> UnsupportedOperationException();
>                        }
>                };
>        }
>
>        /**
>         * Search through the wicket feed back messages within the
> session and determine if there are any messages that meet the given
> criteria based on the supplied feedbackMessageLevelComparator and
>         * feedbackMessage threshold level.
>         *
>         * @return true if a feedbackMessage was found within the
> session that meets the criteria specified.
>         */
>        @SuppressWarnings("unchecked")
>        private final boolean hasFeedbackMessage() {
>                FeedbackMessage feedbackMessage;
>                for (final Iterator<FeedbackMessage> iter =
> Session.get().getFeedbackMessages().iterator(); iter.hasNext();) {
>                        feedbackMessage = iter.next();
>                        if
> (getFeedbackMessageLevelComparator().compare(feedbackMessage,
> getFeedbackMessageThresholdLevel(), getUpperThresholdLevel())) {
>                                onFeedbackMessage(feedbackMessage);
>                                return true;
>                        }
>                }
>                return false;
>        }
>
>        /**
>         * Called in the event that a feedback message was found
>         *
>         * @param feedbackMessage
>         *            the found feedback message
>         */
>        protected void onFeedbackMessage(final FeedbackMessage
> feedbackMessage) {
>                // override if needed
>        }
>
>        /**
>         * Gets the feedbackMessageLevelComparator.
>         *
>         * @return the feedbackMessageLevelComparator to get.
>         */
>        private final FeedbackMessageLevelComparator
> getFeedbackMessageLevelComparator() {
>                return feedbackMessageLevelComparator;
>        }
>
>        /**
>         * Sets the feedbackMessageLevelComparator.
>         *
>         * @param feedbackMessageLevelComparator
>         *            the feedbackMessageLevelComparator to set
>         */
>        private final void setFeedbackMessageLevelComparator(final
> FeedbackMessageLevelComparator feedbackMessageLevelComparator) {
>                this.feedbackMessageLevelComparator =
> feedbackMessageLevelComparator;
>        }
>
>        /**
>         * Gets the feed back message threshold level.
>         *
>         * @return the feedbackMessageThresholdLevel to get.
>         */
>        public final int getFeedbackMessageThresholdLevel() {
>                return feedbackMessageThresholdLevel;
>        }
>
>        /**
>         * Sets the feedback message threshold level.
>         *
>         * @param feedbackMessageThresholdLevel
>         *            the feedbackMessageThresholdLevel to set
>         */
>        public final void setFeedbackMessageThresholdLevel(final int
> feedbackMessageThresholdLevel) {
>                this.feedbackMessageThresholdLevel =
> feedbackMessageThresholdLevel;
>        }
>
>        /**
>         * Gets the upper threshold level.
>         *
>         * @return the upperThresholdLevel to get.
>         */
>        private final int getUpperThresholdLevel() {
>                return upperThresholdLevel;
>        }
>
>        /**
>         * Sets the upper threshold level.
>         *
>         * @param upperThresholdLevel
>         *            the upperThresholdLevel to set.
>         */
>        private final void setUpperThresholdLevel(final int
> upperThresholdLevel) {
>                // TODO : Consider exposing Upper threshold level to
> outside.
>                this.upperThresholdLevel = upperThresholdLevel;
>        }
>
>        /**
>         * Comparators used in feedback message level comparison : <br
> />
>         * <ol>
>         * <li>{@link FeedbackMessageLevelComparator#EQ}</li>
>         * <li>{@link FeedbackMessageLevelComparator#LT}</li>
>         * <li>{@link FeedbackMessageLevelComparator#GT}</li>
>         * <li>{@link FeedbackMessageLevelComparator#LTE}</li>
>         * <li>{@link FeedbackMessageLevelComparator#GTE}</li>
>         * <li>{@link FeedbackMessageLevelComparator#BETWEEN}</li>
>         * </ol>
>         */
>        public enum FeedbackMessageLevelComparator {
>
>                /**
>                 * EQUAL FeedbackMessageLevelComparator. ({@literal =}).
>                 */
>                EQ(false),
>
>                /**
>                 * Less than feedbackMessageLevelComparator. ({@literal
> <}).
>                 */
>                LT(false),
>
>                /**
>                 * Greater than feedbackMessageLevelComparator
> ({@literal >}).
>                 */
>                GT(false),
>
>                /**
>                 * Less than equal to feedbackMessageLevelComparator
> ({@literal <=}).
>                 */
>                LTE(false),
>
>                /**
>                 * Greater than or equal to
> feedbackMessageLevelComparator ({@literal >=}).
>                 */
>                GTE(false),
>
>                /**
>                 * Between feedbackMessageLevelComparator.Between (and
> including) a lower and upper bound threshold
>                 */
>                BETWEEN(true);
>
>                /**
>                 * flag indicating if lower and upper bound are to be
> specified.
>                 */
>                private boolean isLowerAndUpperBoundRequired;
>
>                /**
>                 * Default constructor.
>                 *
>                 * @param isLowerAndUpperBoundRequired
>                 *            flag to indicate whether or not both a
> lower and upper bound value are required for this
> feedbackMessageLevelComparator.
>                 */
>                private FeedbackMessageLevelComparator(final boolean
> isLowerAndUpperBoundRequired) {
>                        this.isLowerAndUpperBoundRequired =
> isLowerAndUpperBoundRequired;
>                }
>
>                /**
>                 * @return true if this feedbackMessageLevelComparator
> requires both a lower and upper bound threshold level. Otherwise the
> feedbackMessageLevelComparator only requires a single bound value.
>                 */
>                public final boolean isLowerAndUpperBoundRequired() {
>                        return isLowerAndUpperBoundRequired;
>                }
>
>                /**
>                 * Compares the received active feedbackMessage's level
> based on the feedbackMessageLevelComparator.
>                 *
>                 * @param activeMessage
>                 *            the FeedbackMessage to compare
>                 * @param thresholdLevel
>                 *            the threshold level to be compared (may
> act as lower bound threshold for comparators that require lower/upper)
>                 * @param upperBoundThresholdLevel
>                 *            the threshold upper bound feedback message
> level (used only for comparators that require it)
>                 *
>                 * @return true if the operation is satisfied based on
> the feedbackMessageLevelComparator (i.e. 500 == 500)
>                 */
>                public final boolean compare(final FeedbackMessage
> activeMessage, final int thresholdLevel, final int
> upperBoundThresholdLevel) {
>                        final boolean isValid;
>                        switch (this) {
>                        case EQ:
>                                isValid = activeMessage.getLevel() ==
> thresholdLevel;
>                                break;
>                        case LT:
>                                isValid = activeMessage.getLevel() <
> thresholdLevel;
>                                break;
>                        case GT:
>                                isValid = activeMessage.getLevel() >
> thresholdLevel;
>                                break;
>                        case LTE:
>                                isValid = activeMessage.getLevel() <=
> thresholdLevel;
>                                break;
>                        case GTE:
>                                isValid = activeMessage.getLevel() >=
> thresholdLevel;
>                                break;
>                        case BETWEEN:
>                                isValid = thresholdLevel <=
> activeMessage.getLevel() && activeMessage.getLevel() <=
> upperBoundThresholdLevel;
>                                break;
>                        default:
>                                isValid = false;
>                        }
>                        return isValid;
>                }
>        }
> }
>
> -----Original Message-----
> From: Igor Vaynberg [mailto:igor.vaynberg@gmail.com]
> Sent: Wednesday, August 06, 2008 11:04 AM
> To: users@wicket.apache.org
> Subject: Re: ListView in Forms
>
> add a feedbackpanel and see if there are any validation errors
>
> -igor
>
> On Wed, Aug 6, 2008 at 7:19 AM, Markus Haspl <m....@gmail.com> wrote:
>> hi,
>>
>> first, i'm a very newbie to wicket... I want to add a ListView in a
> Form.
>> The ListView has two Texfields and one Checkbox each row. When i
>> submit the form the values are still the old ones.
>>
>> here the code:
>>
>> private class InputForm extends Form {
>>
>>
>>
>>  IModel pluginPropertiesModel;
>>
>>  public InputForm(String id, IPlugin plugin){
>>            super(id);
>>
>>
>>
>>            final IPlugin Iplugin = plugin;
>>
>>            pluginPropertiesModel = new LoadableDetachableModel(){
>>                public Object load()
>>                {
>>                    log.debug("load the Model");
>>                    Iplugin.loadPluginProperties();
>>                    return pluginProperties;
>>                }
>>            };
>>
>>            ListView propertiesList = new ListView("pluginRepeater",
>> pluginPropertiesModel) {
>>
>>                @Override
>>                public void populateItem(ListItem item)
>>                {
>>                    PluginProperties pluginProperties =
>> (PluginProperties)item.getModelObject();
>>                    TextField propertiesName = new TextField("name",new
>
>> Model(pluginProperties.getName()));
>>                    TextField propertiesValue = new
>> TextField("value",new Model(pluginProperties.getValue()));
>>                    CheckBox propertiesDefault = new
>> CheckBox("defaultProperty",new
> Model(pluginProperties.isDefaultProperty()));
>>                    item.add(propertiesName);
>>                    item.add(propertiesValue);
>>                    item.add(propertiesDefault);
>>                }
>>            };
>>            propertiesList.setReuseItems(true);
>>            add(propertiesList);
>>
>>        add(new Button("saveButton"));
>>
>>
>>        }
>>
>>        public void onSubmit()
>>        {
>>            List<PluginProperties> pluginProperties =
>> (List<PluginProperties>)pluginPropertiesModel.getObject();
>>            for(PluginProperties property:pluginProperties){
>>                info(""+property.getName()+": "+property.getValue()+"
>> == "+property.isDefaultProperty());
>>                log.debug(""+property.getName()+":
> "+property.getValue()+"
>> == "+property.isDefaultProperty());
>>            }
>>
>>
>>
>>
>>        }
>>    }
>>
>>
>> thanks in advance
>> markus
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


RE: ListView in Forms

Posted by "Hoover, William " <wh...@nemours.org>.
If there are errors try setting this strategy on your list view:

public class ReuseOnFeedbackMessageStrategy implements
IItemReuseStrategy {

	private static final long serialVersionUID = 1L;
	private static final int LEVEL_NA = 0;
	private int feedbackMessageThresholdLevel;
	private FeedbackMessageLevelComparator
feedbackMessageLevelComparator;
	private int upperThresholdLevel;

	/**
	 * Constructs a new ReuseOnFeedbackMessageStrategy taking an
feedbackMessageLevelComparator that does not require a lower/upper bound
threshold level.
	 * 
	 * @param feedbackMessageLevelComparator
	 *            the {@link FeedbackMessageLevelComparator} to be
used when comparing the active message with the threshold
	 * @param feedbackMessageThresholdLevel
	 *            the threshold level to be compared
	 */
	public ReuseOnFeedbackMessageStrategy(final
FeedbackMessageLevelComparator feedbackMessageLevelComparator, final int
feedbackMessageThresholdLevel) {
		super();
		if
(feedbackMessageLevelComparator.isLowerAndUpperBoundRequired) {
			throw new IllegalArgumentException("This
feedbackMessageLevelComparator requires a lower/upper bound threshold
level and so it is not allowed within this constructor (see javadoc).");
		}
		init(feedbackMessageLevelComparator,
feedbackMessageThresholdLevel, LEVEL_NA);
	}

	/**
	 * Constructs a new ReuseOnFeedbackMessageStrategy. Accepts a
feedbackMessageLevelComparator that requires both a lower and upper
bound feedback level (typically used with a
	 * {@link FeedbackMessageLevelComparator#BETWEEN}
feedbackMessageLevelComparator).
	 * 
	 * @param feedbackMessageLevelComparator
	 *            the {@link FeedbackMessageLevelComparator} to be
used when comparing the active message with a lower and upper bound
threshold level
	 * @param lowerThresholdLevel
	 *            the threshold lower bound feedback message level
	 * @param upperThresholdLevel
	 *            the threshold upper bound feedback message level
	 */
	public ReuseOnFeedbackMessageStrategy(final
FeedbackMessageLevelComparator feedbackMessageLevelComparator, final int
lowerThresholdLevel, final int upperThresholdLevel) {
		super();
		if
(!feedbackMessageLevelComparator.isLowerAndUpperBoundRequired) {
			throw new IllegalArgumentException(
					"This
feedbackMessageLevelComparator does not require a lower/upper bound
threshold level and so it is not allowed within this constructor (see
javadoc).");
		}
		init(feedbackMessageLevelComparator,
lowerThresholdLevel, upperThresholdLevel);
	}

	/**
	 * Initialized the ReuseOnFeedbackMessageStrategy.
	 * 
	 * @param boundaryOperator
	 *            the {@link FeedbackMessageLevelComparator} to be
used when comparing the active message with the threshold
	 * @param lowerBoundThresholdLevel
	 *            the threshold lower bound feedback message level
or a single threshold for operators that only require one threshold
value (i.e. =, <, >, <=, or >=)
	 * @param upperBoundThresholdLevel
	 *            the threshold upper bound feedback message level
	 */
	private final void init(final FeedbackMessageLevelComparator
boundaryOperator, final int lowerBoundThresholdLevel, final int
upperBoundThresholdLevel) {
		setFeedbackMessageLevelComparator(boundaryOperator);
	
setFeedbackMessageThresholdLevel(lowerBoundThresholdLevel);
		setUpperThresholdLevel(upperBoundThresholdLevel);
	}

	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("unchecked")
	@Override
	public final Iterator<Item> getItems(final IItemFactory factory,
final Iterator newModels, final Iterator existingItems) {
		final List<Item> existingItemList = new
ArrayList<Item>();

		while (existingItems.hasNext()) {
			existingItemList.add((Item)
existingItems.next());
		}

		return new Iterator<Item>() {
			private int index = 0;
			private transient Boolean hasMessage;

			/**
			 * {@inheritDoc}
			 */
			@Override
			public final boolean hasNext() {
				return newModels.hasNext();
			}

			/**
			 * {@inheritDoc}
			 */
			@Override
			public final Item next() {
				final IModel model = (IModel)
newModels.next();
				final Item item;

				if (hasMessage == null) {
					hasMessage =
hasFeedbackMessage();
				}
				if (hasMessage &&
!existingItemList.isEmpty()) {
					// validation error was found,
set existing items
					item =
existingItemList.get(index);
					item.setIndex(index);
				} else {
					// no validation error, set new
items
					item = factory.newItem(index,
model);
				}
				index++;

				if (!hasNext()) {
					hasMessage = null;
				}
				return item;
			}

			/**
			 * {@inheritDoc}
			 */
			@Override
			public final void remove() {
				throw new
UnsupportedOperationException();
			}
		};
	}

	/**
	 * Search through the wicket feed back messages within the
session and determine if there are any messages that meet the given
criteria based on the supplied feedbackMessageLevelComparator and
	 * feedbackMessage threshold level.
	 * 
	 * @return true if a feedbackMessage was found within the
session that meets the criteria specified.
	 */
	@SuppressWarnings("unchecked")
	private final boolean hasFeedbackMessage() {
		FeedbackMessage feedbackMessage;
		for (final Iterator<FeedbackMessage> iter =
Session.get().getFeedbackMessages().iterator(); iter.hasNext();) {
			feedbackMessage = iter.next();
			if
(getFeedbackMessageLevelComparator().compare(feedbackMessage,
getFeedbackMessageThresholdLevel(), getUpperThresholdLevel())) {
				onFeedbackMessage(feedbackMessage);
				return true;
			}
		}
		return false;
	}

	/**
	 * Called in the event that a feedback message was found
	 * 
	 * @param feedbackMessage
	 *            the found feedback message
	 */
	protected void onFeedbackMessage(final FeedbackMessage
feedbackMessage) {
		// override if needed
	}

	/**
	 * Gets the feedbackMessageLevelComparator.
	 * 
	 * @return the feedbackMessageLevelComparator to get.
	 */
	private final FeedbackMessageLevelComparator
getFeedbackMessageLevelComparator() {
		return feedbackMessageLevelComparator;
	}

	/**
	 * Sets the feedbackMessageLevelComparator.
	 * 
	 * @param feedbackMessageLevelComparator
	 *            the feedbackMessageLevelComparator to set
	 */
	private final void setFeedbackMessageLevelComparator(final
FeedbackMessageLevelComparator feedbackMessageLevelComparator) {
		this.feedbackMessageLevelComparator =
feedbackMessageLevelComparator;
	}

	/**
	 * Gets the feed back message threshold level.
	 * 
	 * @return the feedbackMessageThresholdLevel to get.
	 */
	public final int getFeedbackMessageThresholdLevel() {
		return feedbackMessageThresholdLevel;
	}

	/**
	 * Sets the feedback message threshold level.
	 * 
	 * @param feedbackMessageThresholdLevel
	 *            the feedbackMessageThresholdLevel to set
	 */
	public final void setFeedbackMessageThresholdLevel(final int
feedbackMessageThresholdLevel) {
		this.feedbackMessageThresholdLevel =
feedbackMessageThresholdLevel;
	}

	/**
	 * Gets the upper threshold level.
	 * 
	 * @return the upperThresholdLevel to get.
	 */
	private final int getUpperThresholdLevel() {
		return upperThresholdLevel;
	}

	/**
	 * Sets the upper threshold level.
	 * 
	 * @param upperThresholdLevel
	 *            the upperThresholdLevel to set.
	 */
	private final void setUpperThresholdLevel(final int
upperThresholdLevel) {
		// TODO : Consider exposing Upper threshold level to
outside.
		this.upperThresholdLevel = upperThresholdLevel;
	}

	/**
	 * Comparators used in feedback message level comparison : <br
/>
	 * <ol>
	 * <li>{@link FeedbackMessageLevelComparator#EQ}</li>
	 * <li>{@link FeedbackMessageLevelComparator#LT}</li>
	 * <li>{@link FeedbackMessageLevelComparator#GT}</li>
	 * <li>{@link FeedbackMessageLevelComparator#LTE}</li>
	 * <li>{@link FeedbackMessageLevelComparator#GTE}</li>
	 * <li>{@link FeedbackMessageLevelComparator#BETWEEN}</li>
	 * </ol>
	 */
	public enum FeedbackMessageLevelComparator {

		/**
		 * EQUAL FeedbackMessageLevelComparator. ({@literal =}).
		 */
		EQ(false),

		/**
		 * Less than feedbackMessageLevelComparator. ({@literal
<}).
		 */
		LT(false),

		/**
		 * Greater than feedbackMessageLevelComparator
({@literal >}).
		 */
		GT(false),

		/**
		 * Less than equal to feedbackMessageLevelComparator
({@literal <=}).
		 */
		LTE(false),

		/**
		 * Greater than or equal to
feedbackMessageLevelComparator ({@literal >=}).
		 */
		GTE(false),

		/**
		 * Between feedbackMessageLevelComparator.Between (and
including) a lower and upper bound threshold
		 */
		BETWEEN(true);

		/**
		 * flag indicating if lower and upper bound are to be
specified.
		 */
		private boolean isLowerAndUpperBoundRequired;

		/**
		 * Default constructor.
		 * 
		 * @param isLowerAndUpperBoundRequired
		 *            flag to indicate whether or not both a
lower and upper bound value are required for this
feedbackMessageLevelComparator.
		 */
		private FeedbackMessageLevelComparator(final boolean
isLowerAndUpperBoundRequired) {
			this.isLowerAndUpperBoundRequired =
isLowerAndUpperBoundRequired;
		}

		/**
		 * @return true if this feedbackMessageLevelComparator
requires both a lower and upper bound threshold level. Otherwise the
feedbackMessageLevelComparator only requires a single bound value.
		 */
		public final boolean isLowerAndUpperBoundRequired() {
			return isLowerAndUpperBoundRequired;
		}

		/**
		 * Compares the received active feedbackMessage's level
based on the feedbackMessageLevelComparator.
		 * 
		 * @param activeMessage
		 *            the FeedbackMessage to compare
		 * @param thresholdLevel
		 *            the threshold level to be compared (may
act as lower bound threshold for comparators that require lower/upper)
		 * @param upperBoundThresholdLevel
		 *            the threshold upper bound feedback message
level (used only for comparators that require it)
		 * 
		 * @return true if the operation is satisfied based on
the feedbackMessageLevelComparator (i.e. 500 == 500)
		 */
		public final boolean compare(final FeedbackMessage
activeMessage, final int thresholdLevel, final int
upperBoundThresholdLevel) {
			final boolean isValid;
			switch (this) {
			case EQ:
				isValid = activeMessage.getLevel() ==
thresholdLevel;
				break;
			case LT:
				isValid = activeMessage.getLevel() <
thresholdLevel;
				break;
			case GT:
				isValid = activeMessage.getLevel() >
thresholdLevel;
				break;
			case LTE:
				isValid = activeMessage.getLevel() <=
thresholdLevel;
				break;
			case GTE:
				isValid = activeMessage.getLevel() >=
thresholdLevel;
				break;
			case BETWEEN:
				isValid = thresholdLevel <=
activeMessage.getLevel() && activeMessage.getLevel() <=
upperBoundThresholdLevel;
				break;
			default:
				isValid = false;
			}
			return isValid;
		}
	}
}

-----Original Message-----
From: Igor Vaynberg [mailto:igor.vaynberg@gmail.com] 
Sent: Wednesday, August 06, 2008 11:04 AM
To: users@wicket.apache.org
Subject: Re: ListView in Forms

add a feedbackpanel and see if there are any validation errors

-igor

On Wed, Aug 6, 2008 at 7:19 AM, Markus Haspl <m....@gmail.com> wrote:
> hi,
>
> first, i'm a very newbie to wicket... I want to add a ListView in a
Form.
> The ListView has two Texfields and one Checkbox each row. When i 
> submit the form the values are still the old ones.
>
> here the code:
>
> private class InputForm extends Form {
>
>
>
>  IModel pluginPropertiesModel;
>
>  public InputForm(String id, IPlugin plugin){
>            super(id);
>
>
>
>            final IPlugin Iplugin = plugin;
>
>            pluginPropertiesModel = new LoadableDetachableModel(){
>                public Object load()
>                {
>                    log.debug("load the Model");
>                    Iplugin.loadPluginProperties();
>                    return pluginProperties;
>                }
>            };
>
>            ListView propertiesList = new ListView("pluginRepeater",
> pluginPropertiesModel) {
>
>                @Override
>                public void populateItem(ListItem item)
>                {
>                    PluginProperties pluginProperties = 
> (PluginProperties)item.getModelObject();
>                    TextField propertiesName = new TextField("name",new

> Model(pluginProperties.getName()));
>                    TextField propertiesValue = new 
> TextField("value",new Model(pluginProperties.getValue()));
>                    CheckBox propertiesDefault = new 
> CheckBox("defaultProperty",new
Model(pluginProperties.isDefaultProperty()));
>                    item.add(propertiesName);
>                    item.add(propertiesValue);
>                    item.add(propertiesDefault);
>                }
>            };
>            propertiesList.setReuseItems(true);
>            add(propertiesList);
>
>        add(new Button("saveButton"));
>
>
>        }
>
>        public void onSubmit()
>        {
>            List<PluginProperties> pluginProperties = 
> (List<PluginProperties>)pluginPropertiesModel.getObject();
>            for(PluginProperties property:pluginProperties){
>                info(""+property.getName()+": "+property.getValue()+" 
> == "+property.isDefaultProperty());
>                log.debug(""+property.getName()+":
"+property.getValue()+"
> == "+property.isDefaultProperty());
>            }
>
>
>
>
>        }
>    }
>
>
> thanks in advance
> markus
>

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



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


Re: ListView in Forms

Posted by Igor Vaynberg <ig...@gmail.com>.
add a feedbackpanel and see if there are any validation errors

-igor

On Wed, Aug 6, 2008 at 7:19 AM, Markus Haspl <m....@gmail.com> wrote:
> hi,
>
> first, i'm a very newbie to wicket... I want to add a ListView in a Form.
> The ListView has two Texfields and one Checkbox each row. When i submit the
> form the values are still the old ones.
>
> here the code:
>
> private class InputForm extends Form {
>
>
>
>  IModel pluginPropertiesModel;
>
>  public InputForm(String id, IPlugin plugin){
>            super(id);
>
>
>
>            final IPlugin Iplugin = plugin;
>
>            pluginPropertiesModel = new LoadableDetachableModel(){
>                public Object load()
>                {
>                    log.debug("load the Model");
>                    Iplugin.loadPluginProperties();
>                    return pluginProperties;
>                }
>            };
>
>            ListView propertiesList = new ListView("pluginRepeater",
> pluginPropertiesModel) {
>
>                @Override
>                public void populateItem(ListItem item)
>                {
>                    PluginProperties pluginProperties =
> (PluginProperties)item.getModelObject();
>                    TextField propertiesName = new TextField("name",new
> Model(pluginProperties.getName()));
>                    TextField propertiesValue = new TextField("value",new
> Model(pluginProperties.getValue()));
>                    CheckBox propertiesDefault = new
> CheckBox("defaultProperty",new Model(pluginProperties.isDefaultProperty()));
>                    item.add(propertiesName);
>                    item.add(propertiesValue);
>                    item.add(propertiesDefault);
>                }
>            };
>            propertiesList.setReuseItems(true);
>            add(propertiesList);
>
>        add(new Button("saveButton"));
>
>
>        }
>
>        public void onSubmit()
>        {
>            List<PluginProperties> pluginProperties =
> (List<PluginProperties>)pluginPropertiesModel.getObject();
>            for(PluginProperties property:pluginProperties){
>                info(""+property.getName()+": "+property.getValue()+" ==
> "+property.isDefaultProperty());
>                log.debug(""+property.getName()+": "+property.getValue()+"
> == "+property.isDefaultProperty());
>            }
>
>
>
>
>        }
>    }
>
>
> thanks in advance
> markus
>

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


Re: ListView in Forms

Posted by Markus Haspl <m....@gmail.com>.
i thought i have to use it when i need the updatet values...

On Wed, Aug 6, 2008 at 4:28 PM, Hoover, William <wh...@nemours.org> wrote:

> Why do you use propertiesList.setReuseItems(true)?
>
> -----Original Message-----
> From: Markus Haspl [mailto:m.haspl@gmail.com]
> Sent: Wednesday, August 06, 2008 10:20 AM
> To: users@wicket.apache.org
> Subject: ListView in Forms
>
> hi,
>
> first, i'm a very newbie to wicket... I want to add a ListView in a
> Form.
> The ListView has two Texfields and one Checkbox each row. When i submit
> the form the values are still the old ones.
>
> here the code:
>
> private class InputForm extends Form {
>
>
>
>  IModel pluginPropertiesModel;
>
>  public InputForm(String id, IPlugin plugin){
>            super(id);
>
>
>
>            final IPlugin Iplugin = plugin;
>
>            pluginPropertiesModel = new LoadableDetachableModel(){
>                public Object load()
>                {
>                    log.debug("load the Model");
>                    Iplugin.loadPluginProperties();
>                    return pluginProperties;
>                }
>            };
>
>            ListView propertiesList = new ListView("pluginRepeater",
> pluginPropertiesModel) {
>
>                @Override
>                public void populateItem(ListItem item)
>                {
>                    PluginProperties pluginProperties =
> (PluginProperties)item.getModelObject();
>                    TextField propertiesName = new TextField("name",new
> Model(pluginProperties.getName()));
>                    TextField propertiesValue = new
> TextField("value",new Model(pluginProperties.getValue()));
>                    CheckBox propertiesDefault = new
> CheckBox("defaultProperty",new
> Model(pluginProperties.isDefaultProperty()));
>                    item.add(propertiesName);
>                    item.add(propertiesValue);
>                    item.add(propertiesDefault);
>                }
>            };
>            propertiesList.setReuseItems(true);
>            add(propertiesList);
>
>        add(new Button("saveButton"));
>
>
>        }
>
>        public void onSubmit()
>        {
>            List<PluginProperties> pluginProperties =
> (List<PluginProperties>)pluginPropertiesModel.getObject();
>            for(PluginProperties property:pluginProperties){
>                info(""+property.getName()+": "+property.getValue()+" ==
> "+property.isDefaultProperty());
>                log.debug(""+property.getName()+":
> "+property.getValue()+"
> == "+property.isDefaultProperty());
>            }
>
>
>
>
>        }
>    }
>
>
> thanks in advance
> markus
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

RE: ListView in Forms

Posted by "Hoover, William " <wh...@nemours.org>.
Why do you use propertiesList.setReuseItems(true)? 

-----Original Message-----
From: Markus Haspl [mailto:m.haspl@gmail.com] 
Sent: Wednesday, August 06, 2008 10:20 AM
To: users@wicket.apache.org
Subject: ListView in Forms

hi,

first, i'm a very newbie to wicket... I want to add a ListView in a
Form.
The ListView has two Texfields and one Checkbox each row. When i submit
the form the values are still the old ones.

here the code:

private class InputForm extends Form {



 IModel pluginPropertiesModel;

 public InputForm(String id, IPlugin plugin){
            super(id);



            final IPlugin Iplugin = plugin;

            pluginPropertiesModel = new LoadableDetachableModel(){
                public Object load()
                {
                    log.debug("load the Model");
                    Iplugin.loadPluginProperties();
                    return pluginProperties;
                }
            };

            ListView propertiesList = new ListView("pluginRepeater",
pluginPropertiesModel) {

                @Override
                public void populateItem(ListItem item)
                {
                    PluginProperties pluginProperties =
(PluginProperties)item.getModelObject();
                    TextField propertiesName = new TextField("name",new
Model(pluginProperties.getName()));
                    TextField propertiesValue = new
TextField("value",new Model(pluginProperties.getValue()));
                    CheckBox propertiesDefault = new
CheckBox("defaultProperty",new
Model(pluginProperties.isDefaultProperty()));
                    item.add(propertiesName);
                    item.add(propertiesValue);
                    item.add(propertiesDefault);
                }
            };
            propertiesList.setReuseItems(true);
            add(propertiesList);

        add(new Button("saveButton"));


        }

        public void onSubmit()
        {
            List<PluginProperties> pluginProperties =
(List<PluginProperties>)pluginPropertiesModel.getObject();
            for(PluginProperties property:pluginProperties){
                info(""+property.getName()+": "+property.getValue()+" ==
"+property.isDefaultProperty());
                log.debug(""+property.getName()+":
"+property.getValue()+"
== "+property.isDefaultProperty());
            }




        }
    }


thanks in advance
markus


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