You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by MissOvenMitts <ch...@gmail.com> on 2014/02/06 10:47:22 UTC

Choice Renderers Display Issue After Submit

Hi guys!

I'm using a ChoiceRenderer for the first time, and am having a slight
problem with it. Any help would be *greatly* appreciated!

I have a DropDownChoice used to select a particular PeriodBean object which
uses a ChoiceRenderer to properly display only the "Description" string of
the object. The issue is that once a selection is made and I submit the form
(works properly), the DropDownChoice goes back to not having a selection
displayed (because, I'm assuming, it doesn't know how to take the item in
the property model and display it in the DropDownChoice). How do I make it
continue to properly display the selected PeriodBean Description?

Here's code (simplified version of mine):


// This is what a PeriodBean looks like:
public class PeriodBean implements Serializable {

    private String periodIndex;
    private String periodDescription;

    public String getPeriodIndex() {
        return periodIndex;
    }

    public void setPeriodIndex(String periodIndex) {
        this.periodIndex = periodIndex;
    }

    public String getPeriodDescription() {
        return periodDescription;
    }

    public void setPeriodDescription(String periodDescription) {
        this.periodDescription = periodDescription;
    }

}


// This is what my SearchCriteriaBean looks like (stores the selected value
from the dropdown):
public class SearchCriteriaBean implements Serializable {
  
    private PeriodBean selectedPeriod;

    public PeriodBean getSelectedPeriod() {
        return performancePeriod;
    }

    public void setSelectedPeriod(PeriodBean periodBean ) {
        this.selectedPeriod= periodBean;
    }

}


// This is a PeriodList item that creates the list of acceptable choices for
my dropdown
public class PeriodList extends
            AbstractReadOnlyModel<List&lt;? extends PeriodBean>> {

        public PeriodList() {
            super();
        }

        @Override
        public List<PeriodBean> getObject() {
            List<PeriodBean> pendings = new ArrayList<PeriodBean>();
            
	    // Go to the database and do some stuff to get the proper list of
selectable pending periods
            
	    return pendingPeriods;
        }

        public Iterator<PeriodBean> iterator() {
            List<PeriodBean> pendings = this.getObject();
            return pendings.iterator();
        }
    };




// And this is JAVA in the Page itself:

// Create a search criteria
SearchCriteriaBean searchCriteria = new SearchCriteriaBean(); //Defined
above

// Create a list
PeriodList periodChoices = new PeriodList(); //Defined above

// Create my dropdown and choice renderer to display the period description
ChoiceRenderer<PeriodBean> choiceRenderer = new ChoiceRenderer<PeriodBean>(
                "periodDescription", "periodIndex");
DropDownChoice<PeriodBean> periodChoice = new DropDownChoice<PeriodBean>(
     "periodChoice",
      new PropertyModel<PeriodBean>(searchCriteria, "selectedPeriod"),
periodChoices, choiceRenderer);
periodChoice.setOutputMarkupId(true);
periodChoice.setRequired(true);
form.add(periodChoice); // There is a form on this page but I am not showing
for simplicity.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Choice-Renderers-Display-Issue-After-Submit-tp4664225.html
Sent from the Users forum 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: Choice Renderers Display Issue After Submit

Posted by MissOvenMitts <ch...@gmail.com>.
I answered my own question! I'm a dork. But, for others that might have this
same problem:

Because the object in the SearchCriteria bean that you are selecting
(selectedPeriod) is now a different type of Object than a String, if you
recreate your list of objects to feed to the DropDownChoice (as I do at
various parts of the code), you will need to implement a proper EQUALS
method in your Object (PeriodBean). Otherwise, your selection connected to
the model (selectedPeriod) is not equal to the object sitting in the list of
options (because you recreated the list). That means your choice is not
shown in the DropDownChoice anymore (it says to "Select an Option" instead).

So, PeriodBean needed this:

    @Override
    public boolean equals(final Object obj) {
        if (obj == this) {
            return true;
        } else if (obj == null) {
            return false;
        } else if (obj instanceof PeriodBean) {
            PeriodBean other = (PeriodBean) obj;
            return other.getPeriodIndex().equals(getPeriodIndex());
        }
        return false;
    }

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Choice-Renderers-Display-Issue-After-Submit-tp4664225p4664237.html
Sent from the Users forum 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: Choice Renderers Display Issue After Submit

Posted by Sven Meier <sv...@meiers.net>.
Sorry, I've missing that post.

AbstractSingleSelectChoice#getModelValue() still doesn't look right to me:

     @Override
     public String getModelValue()
     {
         final T object = getModelObject();
         if (object != null)
         {
             int index = getChoices().indexOf(object); // <------
             return getChoiceRenderer().getIdValue(object, index);
         }
         else
         {
             return "";
         }
     }

It's not nice to have to implement #equals() just for this line.

Sven

On 02/07/2014 12:57 PM, Martin Grigorov wrote:
> The user explains in his second mail that everything is fine once the
> #equals() method is properly implemented.
>
> Martin Grigorov
> Wicket Training and Consulting
>
>
> On Fri, Feb 7, 2014 at 12:50 PM, Sven Meier <sv...@meiers.net> wrote:
>
>> I don't see a reason why this shouldn't work.
>>
>> Please create a quickstart showing the problem.
>>
>> Sven
>>
>>
>> On 02/06/2014 10:47 AM, MissOvenMitts wrote:
>>
>>> Hi guys!
>>>
>>> I'm using a ChoiceRenderer for the first time, and am having a slight
>>> problem with it. Any help would be *greatly* appreciated!
>>>
>>> I have a DropDownChoice used to select a particular PeriodBean object
>>> which
>>> uses a ChoiceRenderer to properly display only the "Description" string of
>>> the object. The issue is that once a selection is made and I submit the
>>> form
>>> (works properly), the DropDownChoice goes back to not having a selection
>>> displayed (because, I'm assuming, it doesn't know how to take the item in
>>> the property model and display it in the DropDownChoice). How do I make it
>>> continue to properly display the selected PeriodBean Description?
>>>
>>> Here's code (simplified version of mine):
>>>
>>>
>>> // This is what a PeriodBean looks like:
>>> public class PeriodBean implements Serializable {
>>>
>>>       private String periodIndex;
>>>       private String periodDescription;
>>>
>>>       public String getPeriodIndex() {
>>>           return periodIndex;
>>>       }
>>>
>>>       public void setPeriodIndex(String periodIndex) {
>>>           this.periodIndex = periodIndex;
>>>       }
>>>
>>>       public String getPeriodDescription() {
>>>           return periodDescription;
>>>       }
>>>
>>>       public void setPeriodDescription(String periodDescription) {
>>>           this.periodDescription = periodDescription;
>>>       }
>>>
>>> }
>>>
>>>
>>> // This is what my SearchCriteriaBean looks like (stores the selected
>>> value
>>> from the dropdown):
>>> public class SearchCriteriaBean implements Serializable {
>>>          private PeriodBean selectedPeriod;
>>>
>>>       public PeriodBean getSelectedPeriod() {
>>>           return performancePeriod;
>>>       }
>>>
>>>       public void setSelectedPeriod(PeriodBean periodBean ) {
>>>           this.selectedPeriod= periodBean;
>>>       }
>>>
>>> }
>>>
>>>
>>> // This is a PeriodList item that creates the list of acceptable choices
>>> for
>>> my dropdown
>>> public class PeriodList extends
>>>               AbstractReadOnlyModel<List&lt;? extends PeriodBean>> {
>>>
>>>           public PeriodList() {
>>>               super();
>>>           }
>>>
>>>           @Override
>>>           public List<PeriodBean> getObject() {
>>>               List<PeriodBean> pendings = new ArrayList<PeriodBean>();
>>>                      // Go to the database and do some stuff to get the
>>> proper list of
>>> selectable pending periods
>>>                      return pendingPeriods;
>>>           }
>>>
>>>           public Iterator<PeriodBean> iterator() {
>>>               List<PeriodBean> pendings = this.getObject();
>>>               return pendings.iterator();
>>>           }
>>>       };
>>>
>>>
>>>
>>>
>>> // And this is JAVA in the Page itself:
>>>
>>> // Create a search criteria
>>> SearchCriteriaBean searchCriteria = new SearchCriteriaBean(); //Defined
>>> above
>>>
>>> // Create a list
>>> PeriodList periodChoices = new PeriodList(); //Defined above
>>>
>>> // Create my dropdown and choice renderer to display the period
>>> description
>>> ChoiceRenderer<PeriodBean> choiceRenderer = new
>>> ChoiceRenderer<PeriodBean>(
>>>                   "periodDescription", "periodIndex");
>>> DropDownChoice<PeriodBean> periodChoice = new DropDownChoice<PeriodBean>(
>>>        "periodChoice",
>>>         new PropertyModel<PeriodBean>(searchCriteria, "selectedPeriod"),
>>> periodChoices, choiceRenderer);
>>> periodChoice.setOutputMarkupId(true);
>>> periodChoice.setRequired(true);
>>> form.add(periodChoice); // There is a form on this page but I am not
>>> showing
>>> for simplicity.
>>>
>>> --
>>> View this message in context: http://apache-wicket.1842946.
>>> n4.nabble.com/Choice-Renderers-Display-Issue-After-Submit-tp4664225.html
>>> Sent from the Users forum 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
>>>
>>>
>> ---------------------------------------------------------------------
>> 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: Choice Renderers Display Issue After Submit

Posted by Martin Grigorov <mg...@apache.org>.
The user explains in his second mail that everything is fine once the
#equals() method is properly implemented.

Martin Grigorov
Wicket Training and Consulting


On Fri, Feb 7, 2014 at 12:50 PM, Sven Meier <sv...@meiers.net> wrote:

> I don't see a reason why this shouldn't work.
>
> Please create a quickstart showing the problem.
>
> Sven
>
>
> On 02/06/2014 10:47 AM, MissOvenMitts wrote:
>
>> Hi guys!
>>
>> I'm using a ChoiceRenderer for the first time, and am having a slight
>> problem with it. Any help would be *greatly* appreciated!
>>
>> I have a DropDownChoice used to select a particular PeriodBean object
>> which
>> uses a ChoiceRenderer to properly display only the "Description" string of
>> the object. The issue is that once a selection is made and I submit the
>> form
>> (works properly), the DropDownChoice goes back to not having a selection
>> displayed (because, I'm assuming, it doesn't know how to take the item in
>> the property model and display it in the DropDownChoice). How do I make it
>> continue to properly display the selected PeriodBean Description?
>>
>> Here's code (simplified version of mine):
>>
>>
>> // This is what a PeriodBean looks like:
>> public class PeriodBean implements Serializable {
>>
>>      private String periodIndex;
>>      private String periodDescription;
>>
>>      public String getPeriodIndex() {
>>          return periodIndex;
>>      }
>>
>>      public void setPeriodIndex(String periodIndex) {
>>          this.periodIndex = periodIndex;
>>      }
>>
>>      public String getPeriodDescription() {
>>          return periodDescription;
>>      }
>>
>>      public void setPeriodDescription(String periodDescription) {
>>          this.periodDescription = periodDescription;
>>      }
>>
>> }
>>
>>
>> // This is what my SearchCriteriaBean looks like (stores the selected
>> value
>> from the dropdown):
>> public class SearchCriteriaBean implements Serializable {
>>         private PeriodBean selectedPeriod;
>>
>>      public PeriodBean getSelectedPeriod() {
>>          return performancePeriod;
>>      }
>>
>>      public void setSelectedPeriod(PeriodBean periodBean ) {
>>          this.selectedPeriod= periodBean;
>>      }
>>
>> }
>>
>>
>> // This is a PeriodList item that creates the list of acceptable choices
>> for
>> my dropdown
>> public class PeriodList extends
>>              AbstractReadOnlyModel<List&lt;? extends PeriodBean>> {
>>
>>          public PeriodList() {
>>              super();
>>          }
>>
>>          @Override
>>          public List<PeriodBean> getObject() {
>>              List<PeriodBean> pendings = new ArrayList<PeriodBean>();
>>                     // Go to the database and do some stuff to get the
>> proper list of
>> selectable pending periods
>>                     return pendingPeriods;
>>          }
>>
>>          public Iterator<PeriodBean> iterator() {
>>              List<PeriodBean> pendings = this.getObject();
>>              return pendings.iterator();
>>          }
>>      };
>>
>>
>>
>>
>> // And this is JAVA in the Page itself:
>>
>> // Create a search criteria
>> SearchCriteriaBean searchCriteria = new SearchCriteriaBean(); //Defined
>> above
>>
>> // Create a list
>> PeriodList periodChoices = new PeriodList(); //Defined above
>>
>> // Create my dropdown and choice renderer to display the period
>> description
>> ChoiceRenderer<PeriodBean> choiceRenderer = new
>> ChoiceRenderer<PeriodBean>(
>>                  "periodDescription", "periodIndex");
>> DropDownChoice<PeriodBean> periodChoice = new DropDownChoice<PeriodBean>(
>>       "periodChoice",
>>        new PropertyModel<PeriodBean>(searchCriteria, "selectedPeriod"),
>> periodChoices, choiceRenderer);
>> periodChoice.setOutputMarkupId(true);
>> periodChoice.setRequired(true);
>> form.add(periodChoice); // There is a form on this page but I am not
>> showing
>> for simplicity.
>>
>> --
>> View this message in context: http://apache-wicket.1842946.
>> n4.nabble.com/Choice-Renderers-Display-Issue-After-Submit-tp4664225.html
>> Sent from the Users forum 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
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Choice Renderers Display Issue After Submit

Posted by Sven Meier <sv...@meiers.net>.
I don't see a reason why this shouldn't work.

Please create a quickstart showing the problem.

Sven

On 02/06/2014 10:47 AM, MissOvenMitts wrote:
> Hi guys!
>
> I'm using a ChoiceRenderer for the first time, and am having a slight
> problem with it. Any help would be *greatly* appreciated!
>
> I have a DropDownChoice used to select a particular PeriodBean object which
> uses a ChoiceRenderer to properly display only the "Description" string of
> the object. The issue is that once a selection is made and I submit the form
> (works properly), the DropDownChoice goes back to not having a selection
> displayed (because, I'm assuming, it doesn't know how to take the item in
> the property model and display it in the DropDownChoice). How do I make it
> continue to properly display the selected PeriodBean Description?
>
> Here's code (simplified version of mine):
>
>
> // This is what a PeriodBean looks like:
> public class PeriodBean implements Serializable {
>
>      private String periodIndex;
>      private String periodDescription;
>
>      public String getPeriodIndex() {
>          return periodIndex;
>      }
>
>      public void setPeriodIndex(String periodIndex) {
>          this.periodIndex = periodIndex;
>      }
>
>      public String getPeriodDescription() {
>          return periodDescription;
>      }
>
>      public void setPeriodDescription(String periodDescription) {
>          this.periodDescription = periodDescription;
>      }
>
> }
>
>
> // This is what my SearchCriteriaBean looks like (stores the selected value
> from the dropdown):
> public class SearchCriteriaBean implements Serializable {
>    
>      private PeriodBean selectedPeriod;
>
>      public PeriodBean getSelectedPeriod() {
>          return performancePeriod;
>      }
>
>      public void setSelectedPeriod(PeriodBean periodBean ) {
>          this.selectedPeriod= periodBean;
>      }
>
> }
>
>
> // This is a PeriodList item that creates the list of acceptable choices for
> my dropdown
> public class PeriodList extends
>              AbstractReadOnlyModel<List&lt;? extends PeriodBean>> {
>
>          public PeriodList() {
>              super();
>          }
>
>          @Override
>          public List<PeriodBean> getObject() {
>              List<PeriodBean> pendings = new ArrayList<PeriodBean>();
>              
> 	    // Go to the database and do some stuff to get the proper list of
> selectable pending periods
>              
> 	    return pendingPeriods;
>          }
>
>          public Iterator<PeriodBean> iterator() {
>              List<PeriodBean> pendings = this.getObject();
>              return pendings.iterator();
>          }
>      };
>
>
>
>
> // And this is JAVA in the Page itself:
>
> // Create a search criteria
> SearchCriteriaBean searchCriteria = new SearchCriteriaBean(); //Defined
> above
>
> // Create a list
> PeriodList periodChoices = new PeriodList(); //Defined above
>
> // Create my dropdown and choice renderer to display the period description
> ChoiceRenderer<PeriodBean> choiceRenderer = new ChoiceRenderer<PeriodBean>(
>                  "periodDescription", "periodIndex");
> DropDownChoice<PeriodBean> periodChoice = new DropDownChoice<PeriodBean>(
>       "periodChoice",
>        new PropertyModel<PeriodBean>(searchCriteria, "selectedPeriod"),
> periodChoices, choiceRenderer);
> periodChoice.setOutputMarkupId(true);
> periodChoice.setRequired(true);
> form.add(periodChoice); // There is a form on this page but I am not showing
> for simplicity.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Choice-Renderers-Display-Issue-After-Submit-tp4664225.html
> Sent from the Users forum 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
>


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