Re: DropDownChoice Default Value

2012-07-24 Thread David Hosier
I think it's likely because your KeyValue class does not implement equals. Your 
defaultValue has its own new instance of KeyValue that contains the key JAVA 
and the value java. Your defaultValue instance and what you think is the same 
instance in your list are not the same unless you correctly implement equals() 
to identify them as the same. So you are telling the dropdown that it should 
select something that it does not have in the list. Also, and this may just be 
semantics, but it's probably inappropriate to call that thing a default value 
since the dropdown will update the defaultValue value with whatever you select 
in the dropdown (i.e. that defaultValue will only be the default value until 
you change the selected value in the dropdown). So it's probably more 
appropriately named selectedValue. 

-David 


On Sunday, July 22, 2012 at 10:12 AM, vimal kumar wrote:

 Hi All, 
 I have searched and wasted much of my time figuring out the default Value for 
 DropDownChoice for Object as dropdown but couldn't find the solution. For 
 String dropdown i was able to make it work but somehow for object it is not 
 working. 
 Below is the Simple example that i have been trying, DropDownChoicePage.html 
 and DropDownChoicePage.java files. 
 Can someone please help me that what am i missing into 
 DropDownChoicePage.java class that is not setting the Drop Down Default 
 value? 
  
 DropDownChoicePage.html 
 html xmlns=http://www.w3.org/1999/xhtml;head titleDropDown 
 Example/title/headbody Select your favorite Language select 
 wicket:id=languageDropDown/select /body/html
 --- 
 DropDownChoicePage.java 
 public class DropDownChoicePage extends WebPage { 
 public class KeyValue { 
 private String key; private String value; 
 public KeyValue(String key, String value) { this.key = key; this.value = 
 value; } 
 public String getKey() { return key; } 
 public String getValue() { return value; } 
 public void setKey(String key) { this.key = key; } 
 public void setValue(String value) { this.value = value; } 
 @Override public String toString() { return getKey(); } } 
 private static final long serialVersionUID = 2304448232406333188L; 
 private KeyValue defaultValue = new KeyValue(JAVA, Java); 
 /** * Constructor */ public DropDownChoicePage() { 
 ListKeyValue keyValues = new ArrayListDropDownChoicePage.KeyValue(); 
 keyValues.add(new KeyValue(PHP, php)); keyValues.add(new KeyValue(JAVA, 
 Java)); keyValues.add(new KeyValue(DOT_NET, Dot Net)); 
 DropDownChoiceKeyValue dropDownChoice = new DropDownChoiceKeyValue( 
 languageDropDown, new PropertyModelKeyValue(this, defaultValue), 
 keyValues, new ChoiceRendererKeyValue(key, value)); 
 add(dropDownChoice); 
 } 
 public KeyValue getDefaultValue() { return defaultValue; } 
 public void setDefaultValue(KeyValue defaultValue) { this.defaultValue = 
 defaultValue; } 
 } 
 Thanks, Vimal. 




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



Re: DropDownChoice Default Value

2012-07-24 Thread David Hosier
Aww, crap. I see it was already answered in a different thread….or something 
that showed up under a different thread in my mail reader at least. Sorry for 
the noise.  


On Monday, July 23, 2012 at 11:46 PM, David Hosier wrote:

 I think it's likely because your KeyValue class does not implement equals. 
 Your defaultValue has its own new instance of KeyValue that contains the key 
 JAVA and the value java. Your defaultValue instance and what you think is the 
 same instance in your list are not the same unless you correctly implement 
 equals() to identify them as the same. So you are telling the dropdown that 
 it should select something that it does not have in the list. Also, and this 
 may just be semantics, but it's probably inappropriate to call that thing a 
 default value since the dropdown will update the defaultValue value with 
 whatever you select in the dropdown (i.e. that defaultValue will only be the 
 default value until you change the selected value in the dropdown). So it's 
 probably more appropriately named selectedValue.  
  
 -David  
  
  
 On Sunday, July 22, 2012 at 10:12 AM, vimal kumar wrote:
  
  Hi All,  
  I have searched and wasted much of my time figuring out the default Value 
  for DropDownChoice for Object as dropdown but couldn't find the solution. 
  For String dropdown i was able to make it work but somehow for object it 
  is not working.  
  Below is the Simple example that i have been trying, 
  DropDownChoicePage.html and DropDownChoicePage.java files.  
  Can someone please help me that what am i missing into 
  DropDownChoicePage.java class that is not setting the Drop Down Default 
  value?  
    
  DropDownChoicePage.html  
  html xmlns=http://www.w3.org/1999/xhtml;head titleDropDown 
  Example/title/headbody Select your favorite Language select 
  wicket:id=languageDropDown/select /body/html
  ---  
  DropDownChoicePage.java  
  public class DropDownChoicePage extends WebPage {  
  public class KeyValue {  
  private String key; private String value;  
  public KeyValue(String key, String value) { this.key = key; this.value = 
  value; }  
  public String getKey() { return key; }  
  public String getValue() { return value; }  
  public void setKey(String key) { this.key = key; }  
  public void setValue(String value) { this.value = value; }  
  @Override public String toString() { return getKey(); } }  
  private static final long serialVersionUID = 2304448232406333188L;  
  private KeyValue defaultValue = new KeyValue(JAVA, Java);  
  /** * Constructor */ public DropDownChoicePage() {  
  ListKeyValue keyValues = new ArrayListDropDownChoicePage.KeyValue(); 
  keyValues.add(new KeyValue(PHP, php)); keyValues.add(new 
  KeyValue(JAVA, Java)); keyValues.add(new KeyValue(DOT_NET, Dot 
  Net));  
  DropDownChoiceKeyValue dropDownChoice = new DropDownChoiceKeyValue( 
  languageDropDown, new PropertyModelKeyValue(this, defaultValue), 
  keyValues, new ChoiceRendererKeyValue(key, value)); 
  add(dropDownChoice);  
  }  
  public KeyValue getDefaultValue() { return defaultValue; }  
  public void setDefaultValue(KeyValue defaultValue) { this.defaultValue = 
  defaultValue; }  
  }  
  Thanks, Vimal.  
  




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



Re: DropDownChoice Default Value

2012-07-22 Thread Jeremy Thomerson
On Sun, Jul 22, 2012 at 3:52 PM, vimalsymbi vimal_sy...@yahoo.com wrote:

 Hi All,

 I have searched and wasted much of my time figuring out the default Value
 for DropDownChoice for Object as dropdown but couldn't find the solution.
 For String dropdown i was able to make it work but somehow for object it
 is not working.

 Below is the Simple example that i have been trying,
 DropDownChoicePage.html
 and DropDownChoicePage.java files.

 Can someone please help me that what am i missing into
 DropDownChoicePage.java class that is not setting the Drop Down Default
 value?

 

 DropDownChoicePage.html

 html xmlns=http://www.w3.org/1999/xhtml;
 head
 titleDropDown Example/title
 /head
 body

 Select your favorite Language   select
 wicket:id=languageDropDown/select

 /body
 /html

 ---

 DropDownChoicePage.java

 public class DropDownChoicePage extends WebPage {

 public class KeyValue {

 private String key;
 private String value;

 public KeyValue(String key, String value) {
 this.key = key;
 this.value = value;
 }

 public String getKey() {
 return key;
 }

 public String getValue() {
 return value;
 }

 public void setKey(String key) {
 this.key = key;
 }

 public void setValue(String value) {
 this.value = value;
 }

 @Override
 public String toString() {
 return getKey();
 }
 }

 private static final long serialVersionUID = 2304448232406333188L;

 private KeyValue defaultValue = new KeyValue(JAVA, Java);

 /**
  * Constructor
  */
 public DropDownChoicePage() {

 ListKeyValue keyValues = new
 ArrayListDropDownChoicePage.KeyValue();
 keyValues.add(new KeyValue(PHP, php));
 keyValues.add(new KeyValue(JAVA, Java));
 keyValues.add(new KeyValue(DOT_NET, Dot Net));

 DropDownChoiceKeyValue dropDownChoice = new
 DropDownChoiceKeyValue(
 languageDropDown, new
 PropertyModelKeyValue(this,
 defaultValue), keyValues,
 new ChoiceRendererKeyValue(key,
 value));
 add(dropDownChoice);

 }

 public KeyValue getDefaultValue() {
 return defaultValue;
 }

 public void setDefaultValue(KeyValue defaultValue) {
 this.defaultValue = defaultValue;
 }

 }

 Thanks,
 Vimal.



 --
 View this message in context:
 http://apache-wicket.1842946.n4.nabble.com/DropDownChoice-Default-Value-tp4650704.html
 Sent from the Users forum mailing list archive at Nabble.com.

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


If I had to guess I'd guess it's because your KeyValuePair class does not
properly implement either equals or hashCode.  As I say many times during
my classes: don't get so distracted with how do I do this in Wicket that
you forget that this is just java.

-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*


Re: DropDownChoice default value not found because of equal method

2008-07-31 Thread Andrea Jahn
Hi,

I created a new database and now it works fine.
Must have been an inconsistency in the development/test environment.

Thanks
Andrea


2008/7/30, Igor Vaynberg [EMAIL PROTECTED]:

 On Wed, Jul 30, 2008 at 3:02 AM, Andrea Jahn [EMAIL PROTECTED]
 wrote:
  Reason is, that the Country class contains an equal() method. Wicket
 calls
  this method,
  but the comparison of the id delivers false (different instances of the
  Integer object).

 this doesnt make any sense unless you do int1==int2, which you dont,
 you use equals which does not care about instance identity. so if your
 ids do not match you have another problem with your db somewhere. use
 the debugger and check that the values are actually the same.

 -igor

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




Re: DropDownChoice default value not found because of equal method

2008-07-30 Thread Igor Vaynberg
On Wed, Jul 30, 2008 at 3:02 AM, Andrea Jahn [EMAIL PROTECTED] wrote:
 Reason is, that the Country class contains an equal() method. Wicket calls
 this method,
 but the comparison of the id delivers false (different instances of the
 Integer object).

this doesnt make any sense unless you do int1==int2, which you dont,
you use equals which does not care about instance identity. so if your
ids do not match you have another problem with your db somewhere. use
the debugger and check that the values are actually the same.

-igor

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: DropDownChoice default value

2008-01-26 Thread Timo Rantalaiho
On Sat, 26 Jan 2008, Mathias P.W Nilsson wrote:
 I have a dropDownChoice populated with Category objects. If it is the first
 time the page is rendered 
 the Choose one is visible in the list. If I choose any category this item
 gets removed because it is not a Category object. How can I always have a
 Choose one option as the first item in my DropDownChoice?

I think that there is a setting called nullValid or something
like that (with a setter or overridable getter).

Best wishes,
Timo

-- 
Timo Rantalaiho   
Reaktor Innovations OyURL: http://www.ri.fi/ 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: DropDownChoice default value

2008-01-26 Thread Mathias P.W Nilsson

Thanks but it still does not work. I have set the setIsNullValid to true and
overrided the getDefaultChoice

 @Override
protected java.lang.CharSequence getDefaultChoice(final Object selected){
 return Test value;
}

But what happens then is that the null value is removed from the list. I
would like to have an option with id  and a value of my choice in top. 
-- 
View this message in context: 
http://www.nabble.com/DropDownChoice-default-value-tp15106932p15107379.html
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: DropDownChoice default value

2008-01-26 Thread Eelco Hillenius
On Jan 26, 2008 4:19 AM, Mathias P.W Nilsson [EMAIL PROTECTED] wrote:

 Thanks but it still does not work. I have set the setIsNullValid to true and
 overrided the getDefaultChoice

  @Override
 protected java.lang.CharSequence getDefaultChoice(final Object selected){
  return Test value;
 }

 But what happens then is that the null value is removed from the list. I
 would like to have an option with id  and a value of my choice in top.

Make that something like:

@Override
protected CharSequence getDefaultChoice(Object selected)
{
return option value=\\This is the null choice/option;
}

If you would look at the source that Wicket spits out of your earlier
attempt, you'll see that Test value is actually printed, but as it
is not printed as an option, it is ignored (and is invalid even).

Eelco

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: DropDownChoice default value

2008-01-26 Thread Mathias P.W Nilsson

Thanks alot! It works now. :jumping:
-- 
View this message in context: 
http://www.nabble.com/DropDownChoice-default-value-tp15106932p15114359.html
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]