You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Michael Jaruska <mi...@gmail.com> on 2012/05/13 10:59:44 UTC
dropdown and values added with jquery
Hi,
in my Page (not relevant code removed for simplicity) is dropdown:
public class MyPage extends WebBase{
//perie
private Model<Perie> modelPerie;
//two values in dropdown:
private List<Perie> perie = Arrays.asList(new Perie("start", "-Vyberte druh peří-"), new Perie("vsypek", "nové 806"));
private DropDownChoice<Perie> vyberPeria;
private ChoiceRendererPerie rendererPerie;
public PageEshop(){
this.rendererPerie = new ChoiceRendererPerie();
this.modelPerie = new Model<Perie>(this.perie.get(0));
this.vyberPeria = new DropDownChoice<Perie>("vyberPeria", this.modelPerie, this.perie, this.rendererPerie);
MyForm form = new MyForm("inputForm");
form.add(vyberPeria);
this.add(form);
}
private class MyForm extends Form<Object>{
public MyForm(String id){
super(id);
}
@Override
protected void onSubmit(){
//with value added with jquery this produce error
System.out.println(PageEshop.this.modelPerie.getObject().getHodnota());
}
}
}
and in relevant markup I add new choice in this dropdown with jquery:
<form wicket:id="inputForm">
<div id="perie">
<label>Typ peří:</label>
<select id="2" wicket:id="vyberPeria"></select>
</div>
<script>
jQuery(document).ready(
function()
{
//-->this add another value into dropdown, now there are three values:
$('#2').append($('<option></option>').val('testkluc').html('testovaci text'));
})
</script>
</form>
Of course, when I select this added value ('testkluc') in dropdown and submit it, from onSubmit() I try to do something with this, I get error:
...
java.lang.reflect.InvocationTargetException
...PageEshop$MyForm.onSubmit(...
Yes, I know that this third value isn't in model so error is predictable. Question is: how to deal with situation when I need
add new value in HTML and this value isn't in my model in java?
Thanks,
MJ
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org