I wonder if anyone can help with the following bug in my code.
It relates to a Panel which contains a DropDownChoice.
This is the exception:
java.lang.IllegalArgumentException: Cannot format given Object as a Number
at java.text.DecimalFormat.format(DecimalFormat.java:487)
at
java.text.Format.format(Format.java:140)
at
org.apache.wicket.util.convert.converters.AbstractNumberConverter.convertToString(AbstractNumberConverter.java:111)
at
org.apache.wicket.util.lang.PropertyResolverConverter.convert(PropertyResolverConverter.java:85)
at
org.apache.wicket.util.lang.PropertyResolver$MethodGetAndSet.setValue(PropertyResolver.java:1110)
at
org.apache.wicket.util.lang.PropertyResolver$ObjectAndGetSetter.setValue(PropertyResolver.java:588)
at
org.apache.wicket.util.lang.PropertyResolver.setValue(PropertyResolver.java:136)
at
org.apache.wicket.model.AbstractPropertyModel.setObject(AbstractPropertyModel.java:169)
at
com.drf.hapoalim.gui.components.AccountDropDownChoice$4.onUpdate(AccountDropDownChoice.java:108)
Line 108 relates to the following line of code:
model.setObject(accountsMap.get(accountNumber));
What I cannot understand is what Decimal conversion is going on here: The
'model' variable is declared as IModel<Account> model, and the value
returned by the map is indeed an Account object.
Here is the code (trimmed down):
public class AccountDropDownChoice extends Panel {
private static final long serialVersionUID = 530407612837913746L;
@SpringBean
private AccountService accountService;
private List accountsList = new ArrayList();
private Map<Long, Account> accountsMap = new HashMap<Long, Account>();
private Long selectedAccount;
private DropDownChoice<Long> dropDown = null;
public AccountDropDownChoice(String id, final IModel<Account> model) {
super(id);
selectedAccount = 0L;
model.setObject(null);
dropDown = new DropDownChoice<Long>("accountsDropDown", new
Model<Long>(selectedAccount), accountsList, new AccountChoiceRenderer()){
@Override
protected boolean wantOnSelectionChangedNotifications()
{
return true;
}
// Set default to 'all accounts' when used with this
constructor
@Override
protected CharSequence getDefaultChoice(Object
selected) {
return super.getDefaultChoice(0);
}
};
dropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
if (selectedAccount!=null){
Long accountNumber = (Long)
accountsList.get(Integer.parseInt(dropDown.getModelValue()));
// EXCEPTION OCCURS HERE
model.setObject(accountsMap.get(accountNumber));
}
}
});
add(dropDown);
}
Whoever can help - thank you very much!!!
--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/DropDownChoice-tp3022770p3022770.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]