listviews dont use item reuse strategies...
-igor
On Wed, Aug 6, 2008 at 9:25 AM, Hoover, William <[EMAIL PROTECTED]> 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 [EMAIL PROTECTED] 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
> * [EMAIL PROTECTED] FeedbackMessageLevelComparator#BETWEEN}
> feedbackMessageLevelComparator).
> *
> * @param feedbackMessageLevelComparator
> * the [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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);
> }
>
> /**
> * [EMAIL PROTECTED]
> */
> @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;
>
> /**
> * [EMAIL PROTECTED]
> */
> @Override
> public final boolean hasNext() {
> return newModels.hasNext();
> }
>
> /**
> * [EMAIL PROTECTED]
> */
> @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;
> }
>
> /**
> * [EMAIL PROTECTED]
> */
> @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>[EMAIL PROTECTED] FeedbackMessageLevelComparator#EQ}</li>
> * <li>[EMAIL PROTECTED] FeedbackMessageLevelComparator#LT}</li>
> * <li>[EMAIL PROTECTED] FeedbackMessageLevelComparator#GT}</li>
> * <li>[EMAIL PROTECTED] FeedbackMessageLevelComparator#LTE}</li>
> * <li>[EMAIL PROTECTED] FeedbackMessageLevelComparator#GTE}</li>
> * <li>[EMAIL PROTECTED] FeedbackMessageLevelComparator#BETWEEN}</li>
> * </ol>
> */
> public enum FeedbackMessageLevelComparator {
>
> /**
> * EQUAL FeedbackMessageLevelComparator. ([EMAIL PROTECTED]
> =}).
> */
> EQ(false),
>
> /**
> * Less than feedbackMessageLevelComparator. ([EMAIL PROTECTED]
> <}).
> */
> LT(false),
>
> /**
> * Greater than feedbackMessageLevelComparator
> ([EMAIL PROTECTED] >}).
> */
> GT(false),
>
> /**
> * Less than equal to feedbackMessageLevelComparator
> ([EMAIL PROTECTED] <=}).
> */
> LTE(false),
>
> /**
> * Greater than or equal to
> feedbackMessageLevelComparator ([EMAIL PROTECTED] >=}).
> */
> 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:[EMAIL PROTECTED]
> Sent: Wednesday, August 06, 2008 11:04 AM
> To: [email protected]
> 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 <[EMAIL PROTECTED]> 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: [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]