Hi,
this is just a wild guess but in your code you have line that calls
"item.remove(listChoice);" under certain conditions and the listChoice
instance is bound to the category identifier which does not seem right
to me.
As far as I understand ListViews the associated markup block is created
for each item. If you remove the listChoice from an item then Wicket has
no object to associate the markup with. So I think you cannot remove the
choice that way.
I have a similar use case where I also add and remove objects to and
from ListViews via Ajax and it was sufficient to just remove the object
from the collection that the ListView relies on and add the wrappign
container to the ajax target.
Since the listChoice is the only thing you add to an item I figure that
could also be feasible for your case but as said before this is just a
hunch.
HTH, Chris
--
The Sanity Resort <http://sanityresort.blogspot.com/>
Am 31.07.2011 21:06, schrieb ramazan pekin:
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]