Re: [Wicket-user] Problems with ChoiceRenderer and DropDownChoice

2005-10-19 Thread Johan Compagner
Youre problem lies in this:

add(DropDownChoice(genderId, genders, new ChoiceRenderer(displayValue, id));
 ^^^

it should be:
add(DropDownChoice(gender, genders, new ChoiceRenderer(displayValue, id));

So not the ID but the real object.
Because what is in the choices (the genders list)
should be exactly the same object as what is in the selected property.

you are trying to compare the Number 0 with Person.
You can do that if you want but then you need to supply youre own choicerenderer that can handle both
inputs (doing person.getId() if it is a person and directly return the number if it is a number)

johan



On 10/19/05, WATSON Matthew [EMAIL PROTECTED] wrote:










Hi,


Since upgrading from 1.0 to 1.1 rc2 I've had problems with the ChoiceRenderer and DropDownChoice

components.


To explain:


I have two classes


class Person {

 private long id;

 private long genderId;


 getId()

 setId()

 getGenderId()

 ... etc.

}


class Gender {

 private long id;

 private String displayValue;


 getId()

 setId()

 getDisplayValue()

 ... etc.

}


Assuming I have a List of genders with values of:


 1. Male.

 2. Female.

 3. Unknown.


(These come from a database, so real id will vary).


And a form which essentially contains the following:


setModel(CompoundPropertyModel(new Person());

add(DropDownChoice(genderId, genders, new ChoiceRenderer(displayValue, id));



*** First problem occurs with the above, I get this error:


error getting id value of: 0 for property: id. Which is being thrown from within the 


ChoiceRender.java


 public String getIdValue(Object object, int index)

 {

  if (idExpression == null)

  {

   return Integer.toString(index);

  }

  

  if (object == null)

  {

   return ;

  }

  

  try

  {



 Object returnValue = Ognl.getValue(idExpression, object);



 if (returnValue == null)



 {



  return ;



 }



 



 return returnValue.toString();

  }

  catch (OgnlException ex)

  {



 throw new WicketRuntimeException(Error getting id value of:  + 



  object +  for property:  + idExpression,ex);

  }

 }



I think that
its trying somehow to see if the current Persons genderId of 0 matches
something within the list. It doesn't seem to be correctly handling
primatives as I would expect. 

I think it
wants the Person class to have a Gender object which won't be possible
in this case. If so what can either be done to the ChoiceRender or to
my code to fix this?

 Second problem occurs in AbstractSingleSelectChoice:


 public final void setModelValue(final String value)

 {

  List choices = getChoices();

  for(int index=0;indexchoices.size();index++)

  {



 // Get next choice

*1

 final Object choice =
choices.get(index);



 if(getChoiceRenderer().getIdValue(choice, index).equals(value))



 {

*2


 setModelObject(choice);




 break;



 }

  }

 }


This gets executed when the form is submitted. Again this isn't working with primatives properly.

At *1 the
choice variable is actually an instance of the 'Gender' class, whereas
at *2 the actual model object is a Long. So when it tries to do this
set() it fails.

I think Wicket should be able to handle these sorts of situations with primatives.


Does anybody have any ideas, or am I doing something wrong?


Thanks in advance,

Matt



--- 
--- 
The information contained in this e-mail is privileged and confidential. It is 
intended for the addressee only and is not necessarily the official view or 
communication of NZ Customs Service. If you are not the intended recipient you 
are asked to respect the confidentiality and not disclose, copy, or make use of 
its contents. If received in error you are asked to destroy this e-mail and 
contact the sender immediately. Your assistance is appreciated. 
 






RE: [Wicket-user] Problems with ChoiceRenderer and DropDownChoice

2005-10-19 Thread WATSON Matthew



Thanks 
for your reply.

Do you 
I think that if I try and implement my own version of a ChoiceRenderer that I 
will need to potentially override this "final" method from AbstractSingleSelectChoice?

 public final void setModelValue(final String value)  
{  
 List choices = getChoices();  
 for(int index=0;indexchoices.size();index++)  
 {  
 
 // Get next choicefinal Object choice = 
choices.get(index); 
 
 
 if(getChoiceRenderer().getIdValue(choice, 
index).equals(value)) 
 
 
 {
 setModelObject(choice);  
 
 
 break;  
 
 }  
 }  }
To be something more along the lines of: 



 public final void setModelValue(final String value)  
{  
 List choices = getChoices();  
 for(int index=0;indexchoices.size();index++)  
 {  
 
 // Get next choicefinal Object choice = 
choices.get(index); 
 
 
 if(getChoiceRenderer().getIdValue(choice, 
index).equals(value)) 
 
 
 {
 setModelObject(value); // or something 
similar.
^^^ 
break;  
 
 }  
 }  }
This would at least give me control over 
how I assign the model object.
Matt.Youre problem lies in this:add(DropDownChoice("genderId", 
genders, new ChoiceRenderer("displayValue", 
"id")); 
^^^it should be:add(DropDownChoice("gender", genders, new 
ChoiceRenderer("displayValue", "id"));So not the ID but the real 
object.Because what is in the choices (the genders list)should be 
exactly the same object as what is in the selected property.you are 
trying to compare the Number 0 with Person.You can do that if you want but 
then you need to supply youre own choicerenderer that can handle bothinputs 
(doing person.getId() if it is a person and directly return the number if it is 
a number)johan

  On 10/19/05, WATSON 
  Matthew [EMAIL PROTECTED] 
  wrote:
  
Hi, 
Since upgrading from 1.0 to 1.1 rc2 I've 
had problems with the ChoiceRenderer and DropDownChoice components. 
To explain: 
I have two classes 
class Person { 
 private long id; 
 private long genderId; 
 getId()  setId() 
 getGenderId()  
... etc. } 
class Gender { 
 private long id; 
 private String displayValue; 
 getId()  setId() 
 getDisplayValue() 
 ... etc. } 
Assuming I have a List 
of genders with values of: 
 1. 
Male.  2. 
Female.  3. 
Unknown. 
(These come from a 
database, so real id will vary). 
And a form which 
essentially contains the following: 
setModel(CompoundPropertyModel(new Person()); add(DropDownChoice("genderId", 
genders, new ChoiceRenderer("displayValue", "id")); 
*** First problem occurs 
with the above, I get this error: 
error getting id value 
of: 0 for property: id. Which is being thrown from within the 

ChoiceRender.java 
 public String getIdValue(Object object, int 
index)  {  
 if (idExpression == null)  
 {  
  return Integer.toString(index); 
 
 }  
  
 if (object == null)  
 {  
  return "";  
 }  
  
 try  
 {  
 
 Object returnValue = Ognl.getValue(idExpression, 
object);  
 
 if (returnValue == null)  
 
 {  
 
  return "";  
 
 }  
 
  
 
 return returnValue.toString();  
 }  
 catch (OgnlException ex)  
 {  
 
 throw new WicketRuntimeException("Error getting id value of: " + 
 
 
  object + " for property: " 
+ idExpression,ex);  
 }  } 
I think that its trying 
somehow to see if the current Persons genderId of 0 matches something within 
the list. It doesn't seem to be correctly handling primatives as I would 
expect. 
I think it wants the 
Person class to have a Gender object which won't be possible in this case. 
If so what can either be done to the ChoiceRender or to my code to fix 
this?
 Second problem 
occurs in AbstractSingleSelectChoice: 
 public final void setModelValue(final String 
value)  {  
 List choices = getChoices();  
 for(int index=0;indexchoices.size();index++) 
 
 {  
 
 // Get next choice *1 
 
 final Object choice = 
choices.get(index);  
 
 if(getChoiceRenderer().getIdValue(choice, 
index).equals(value))  
 
 { *2 
 
 
 
setModelObject(choice);  
 
 
 break;  
 
 }  
 }  } 
This gets executed when 
the form is submitted. Again this isn't working with primatives 
properly. At *1 the choice variable is actually an instance of the 'Gender' 
class, whereas at *2 the actual model object is a Long. So when it tries to 
do this set() it fails.
I think Wicket should be 
able to handle these sorts of situations with primatives. 
Does anybody have any 
ideas, or am I doing something wrong? 
Thanks in 
advance, Matt 
--- 

Re: [Wicket-user] Problems with ChoiceRenderer and DropDownChoice

2005-10-19 Thread Johan Compagner
no if you really want the ID as the model value
Then just give a list with IDs as the choicelist.
Then map in youre ChoiceRenderer those id's to displayvalues.

getIdValue is then pretty simple just return the object directly
getDisplayValue should do a map lookup

Choices are just make that the List of choices and the selected value has to be the same time. 
So what is in the List can be set as the value. This won't change.

johan
On 10/19/05, WATSON Matthew [EMAIL PROTECTED] wrote:







Thanks 
for your reply.

Do you 
I think that if I try and implement my own version of a ChoiceRenderer that I 
will need to potentially override this final method from AbstractSingleSelectChoice?

 public final void setModelValue(final String value)
  
{  
 List choices = getChoices();  
 for(int index=0;indexchoices.size();index++)  
 {  
 
 // Get next choice
final Object choice = 
choices.get(index); 
 
 
 if(getChoiceRenderer().getIdValue(choice, 
index).equals(value)) 
 
 
 {
 setModelObject(choice); 
 
 
 
 break;  
 
 }  
 }  
}
To be something more along the lines of: 



 public final void setModelValue(final String value)
  
{  
 List choices = getChoices();  
 for(int index=0;indexchoices.size();index++)  
 {  
 
 // Get next choice
final Object choice = 
choices.get(index); 
 
 
 if(getChoiceRenderer().getIdValue(choice, 
index).equals(value)) 
 
 
 {
 setModelObject(value);
 // or something 
similar.
^^^
break;  
 
 }  
 }  }

This would at least give me control over 
how I assign the model object.
Matt.
Youre problem lies in this:add(DropDownChoice(genderId, 
genders, new ChoiceRenderer(displayValue, 
id)); 
^^^it should be:add(DropDownChoice(gender, genders, new 
ChoiceRenderer(displayValue, id));So not the ID but the real 
object.Because what is in the choices (the genders list)should be 
exactly the same object as what is in the selected property.you are 
trying to compare the Number 0 with Person.You can do that if you want but 
then you need to supply youre own choicerenderer that can handle bothinputs 
(doing person.getId() if it is a person and directly return the number if it is 
a number)johan

  On 10/19/05, WATSON 
  Matthew [EMAIL PROTECTED] 
  wrote:
  
Hi, 
Since upgrading from 1.0 to 1.1 rc2 I've 
had problems with the ChoiceRenderer and DropDownChoice components. 
To explain: 
I have two classes 
class Person { 
 private long id; 
 private long genderId; 
 getId()  setId() 
 getGenderId()  
... etc. } 
class Gender { 
 private long id; 
 private String displayValue; 
 getId()  setId() 
 getDisplayValue() 
 ... etc. } 
Assuming I have a List 
of genders with values of: 
 1. 
Male.  2. 
Female.  3. 
Unknown. 
(These come from a 
database, so real id will vary). 
And a form which 
essentially contains the following: 
setModel(CompoundPropertyModel(new Person()); add(DropDownChoice(genderId, 
genders, new ChoiceRenderer(displayValue, id)); 
*** First problem occurs 
with the above, I get this error: 
error getting id value 
of: 0 for property: id. Which is being thrown from within the 

ChoiceRender.java 
 public String getIdValue(Object object, int 
index)  {  
 if (idExpression == null)  
 {  
  return Integer.toString(index); 
 
 }  
  
 if (object == null)  
 {  
  return ;  
 }  
  
 try  
 {  
 
 Object returnValue = Ognl.getValue(idExpression, 
object);  
 
 if (returnValue == null)  
 
 {  
 
  return ;  
 
 }  
 
  
 
 return returnValue.toString();  
 }  
 catch (OgnlException ex)  
 {  
 
 throw new WicketRuntimeException(Error getting id value of:  + 
 
 
  object +  for property:  
+ idExpression,ex);  
 }  } 
I think that its trying 
somehow to see if the current Persons genderId of 0 matches something within 
the list. It doesn't seem to be correctly handling primatives as I would 
expect. 
I think it wants the 
Person class to have a Gender object which won't be possible in this case. 
If so what can either be done to the ChoiceRender or to my code to fix 
this?
 Second problem 
occurs in AbstractSingleSelectChoice: 
 public final void setModelValue(final String 
value)  {  
 List choices = getChoices();  
 for(int index=0;indexchoices.size();index++) 
 
 {  
 
 // Get next choice *1 
 
 final Object choice = 
choices.get(index);  
 
 if(getChoiceRenderer().getIdValue(choice, 
index).equals(value))  
 
 { *2 
 
 
 
setModelObject(choice);  
 
 
 break;  
 
 }  
 }  } 
This gets executed when 
the form is submitted. Again this isn't working with primatives 
properly. At *1 the choice variable is actually an 

[Wicket-user] Problems with ChoiceRenderer and DropDownChoice

2005-10-18 Thread WATSON Matthew
Title: Problems with ChoiceRenderer and DropDownChoice






Hi,


Since upgrading from 1.0 to 1.1 rc2 I've had problems with the ChoiceRenderer and DropDownChoice

components.


To explain:


I have two classes


class Person {

 private long id;

 private long genderId;


 getId()

 setId()

 getGenderId()

 ... etc.

}


class Gender {

 private long id;

 private String displayValue;


 getId()

 setId()

 getDisplayValue()

 ... etc.

}


Assuming I have a List of genders with values of:


 1. Male.

 2. Female.

 3. Unknown.


(These come from a database, so real id will vary).


And a form which essentially contains the following:


setModel(CompoundPropertyModel(new Person());

add(DropDownChoice(genderId, genders, new ChoiceRenderer(displayValue, id));


*** First problem occurs with the above, I get this error:


error getting id value of: 0 for property: id. Which is being thrown from within the 


ChoiceRender.java


 public String getIdValue(Object object, int index)

 {

  if (idExpression == null)

  {

   return Integer.toString(index);

  }

  

  if (object == null)

  {

   return ;

  }

  

  try

  {

   Object returnValue = Ognl.getValue(idExpression, object);

   if (returnValue == null)

   {

return ;

   }

   

   return returnValue.toString();

  }

  catch (OgnlException ex)

  {

   throw new WicketRuntimeException(Error getting id value of:  + 

object +  for property:  + idExpression,ex);

  }

 }



I think that its trying somehow to see if the current Persons genderId of 0 matches something within the list. It doesn't seem to be correctly handling primatives as I would expect. 

I think it wants the Person class to have a Gender object which won't be possible in this case. If so what can either be done to the ChoiceRender or to my code to fix this?

 Second problem occurs in AbstractSingleSelectChoice:


 public final void setModelValue(final String value)

 {

  List choices = getChoices();

  for(int index=0;indexchoices.size();index++)

  {

   // Get next choice

*1   final Object choice = choices.get(index);

   if(getChoiceRenderer().getIdValue(choice, index).equals(value))

   {

*2setModelObject(choice);

break;

   }

  }

 }


This gets executed when the form is submitted. Again this isn't working with primatives properly.

At *1 the choice variable is actually an instance of the 'Gender' class, whereas at *2 the actual model object is a Long. So when it tries to do this set() it fails.

I think Wicket should be able to handle these sorts of situations with primatives.


Does anybody have any ideas, or am I doing something wrong?


Thanks in advance,

Matt



--- 
--- 
The information contained in this e-mail is privileged and confidential. It is 
intended for the addressee only and is not necessarily the official view or 
communication of NZ Customs Service. If you are not the intended recipient you 
are asked to respect the confidentiality and not disclose, copy, or make use of 
its contents. If received in error you are asked to destroy this e-mail and 
contact the sender immediately. Your assistance is appreciated.