I removed "item.remove(listChoice);" from code and I just changed
ListView definition, I used PropertyModel, and every thing working
well...
listView = new ListView<CategoryModel>("categoryList", categories) {
-> I changed this line as below
=> listView = new ListView<CategoryModel>("categoryList", new
PropertyModel<List<CategoryModel>>(this, "categories")) {
On Mon, Aug 1, 2011 at 12:09 AM, ramazan pekin <[email protected]> wrote:
> And this is CatogoryModel class:
>
> public class CategoryModel implements Serializable {
>
> private static final long serialVersionUID = 1L;
>
> private List<OmCategory> omCategories;
>
> private OmCategory selectedCategory;
>
> public CategoryModel(List<OmCategory> omCategories) {
> this.omCategories = omCategories;
> }
>
> public List<OmCategory> getOmCategories() {
> return omCategories;
> }
>
> public void setOmCategories(List<OmCategory> omCategories) {
> this.omCategories = omCategories;
> }
>
> public OmCategory getSelectedCategory() {
> return selectedCategory;
> }
>
> public void setSelectedCategory(OmCategory selectedCategory) {
> this.selectedCategory = selectedCategory;
> }
>
> }
>
>
> On Mon, Aug 1, 2011 at 12:05 AM, ramazan pekin <[email protected]> wrote:
>> Actually, as you said, when I add new bounded object to the collection
>> new listChoice has been added to page, but whenever I tried to remove
>> object from collection, related listChoice is not being removed from
>> page. I have added wrapping container and I specified as target
>> component to listChoice's onchange action. As result, I have added
>> "item.remove(listChoice);" to code but this time, exception raised.
>>
>> I think I am using ListView wrongly, main problem looks like ListView
>> related model object. This is my current markup file content.
>>
>> <body>
>> <form wicket:id="form">
>> <table wicket:id="categoryContainer">
>> <tr>
>> <td wicket:id="categoryList">
>> <select wicket:id="category"/>
>> </td>
>> </tr>
>> </table>
>> <input type="submit" value="Submit"/>
>> </form>
>> </body>
>>
>> On Sun, Jul 31, 2011 at 11:02 PM, Christian Huber <[email protected]>
>> wrote:
>>> 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]
>>>>
>>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]