Hi to everyone,
I am trying to generate dynamic form elements. I need to add and
remove some components dynamically. I have added listChoice component
succesfuly whenever user select a listChoice item, but when I tried to
remove listChoice component, I received an error like that:
org.apache.wicket.DefaultExceptionMapper.internalMap(DefaultExceptionMapper.java:102)
- Unexpected error occurred
org.apache.wicket.markup.MarkupException: Unable to find component
with id 'category' in [ListItem [Component id = 1]]. This means that
you declared wicket:id=category in your markup, but that you either
did not add the component to your page at all, or that the hierarchy
does not match.
.....Page.html
<td wicket:id="categoryList">
<select wicket:id="category"></select>
</td>, index = 2, current = '<select
wicket:id="category">' (line 16, column 18)]
at
org.apache.wicket.markup.MarkupStream.throwMarkupException(MarkupStream.java:536)
This is form code:
public class DynamicForm extends Form {
private static final long serialVersionUID = 1L;
final ListView<CategoryModel> listView;
private List<CategoryModel> categories;
public DynamicForm(String id) {
super(id);
categories = new ArrayList<CategoryModel>();
categories.add(new CategoryModel(masterCategories));
final WebMarkupContainer listContainer = new
WebMarkupContainer("categoryContainer");
listView = new ListView<CategoryModel>("categoryList", categories) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(final ListItem<CategoryModel> item) {
final CategoryModel category = item.getModelObject();
ListChoice<OmCategory> listChoice = new ListChoice<OmCategory>(
"category",
new PropertyModel<OmCategory>(category, "selectedCategory"),
masterCategories,
new IChoiceRenderer<OmCategory>() {
private static final long serialVersionUID = 1L;
public Object getDisplayValue(OmCategory omCategory) {
return omCategory.getCategoryCode().getLocalized();
}
public String getIdValue(OmCategory omCategory, int index) {
return omCategory.getRowId();
}
}
);
listChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID = 5417882427051940952L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
if(categories.size() > 1 && (categories.indexOf(category)
+ 1) != categories.size()) {
categories = new
ArrayList<CategoryModel>(categories.subList(0,
(categories.indexOf(category) + 1)));
}
categories.add(new CategoryModel(masterCategories));
target.add(listContainer);
}
});
if(categories.indexOf(item.getModelObject()) != -1) {
item.add(listChoice);
} else {
item.remove(listChoice);
}
}
};
listView.setOutputMarkupId(true);
listContainer.add(listView);
listContainer.setOutputMarkupId(true);
add(listContainer);
}
}
First time I am developing with wicket, and maybe I use wrongly. I'm
new and any feedback is appreciated... Sorry for my english :)
Br.
Ramazan
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]