cancel
Showing results for 
Search instead for 
Did you mean: 

Destroying Dynamically created ui elements

Former Member
0 Kudos

Hi All,

We are generating labels at runtime in doModify method ,when view is loaded.

(we are able to do this)

IWDLabel Label = (IWDLabel)view.createElement

IWDLabel.class, "Label" );

There is button in a view .

Requirment is to replace labels in the same container on click of button.

but before replacing labels we have to remove initially generated labels from container .

We are using followin code to remove elements from the container

container.removeAllChildren();

container.destroyAllChildren();

After this When we are regenerating labels on click of button

it gives an exception

+Cannot add element with duplicate ID "Label" of type com.sap.tc.webdynpro.clientserver.uielib.standard.impl.TextView

+

Please let us know the solutions.

Thanks;

Zaid

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Just give the labels you are creating different IDs. This can be achieved for example by passing NULL as ID.

Armin

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

You have to use below code to remove the elements

view.getElement("Lable0").destroy();

instead of

container.removeAllChildren();

container.destroyAllChildren();

I hope it solve your problem

Thanks

Former Member
0 Kudos

Thanks all of you for the replies.

We have passed "null" as id for ui elements as suggested by Armin,which solved the problem.

Thanks,

Zaid

Former Member
0 Kudos

We have to just recreate a part of view , and only this part has dynamic part.

by view.reset() will it be fine in this case ???

Former Member
0 Kudos

This will bring your view to the state that it was during design time. All the dynamically created content would be removed.

Regards,

Murtuza

Former Member
0 Kudos

Thanks for reply, but i need to create the elements with NAME

Here we create this label multiple times in for loop.

IWDLabel Label = (IWDLabel)view.createElement

IWDLabel.class, "Label"+i );

and we need to recreate these labels again.

Hence i did destroyAllChildren and removeAllChildren, as given earlier.

Yet it gives me this exception when i recreate after this.

is there something i am missing or even on Destroy and Remove methods being called, the name still exists ????

thanks and regards;

ZAID

Former Member
0 Kudos

Hi Zaid,

Just try this in wdDoMofifyView whenever you want to remove all the childrens.

view.resetView();

Regards,

Murtuza

Former Member
0 Kudos

The IDs of the labels must be unique inside the complete view, not only the container. Thus if you create a label "Label3" inside a container and you have already used this ID in the same view at some other place, this exception will occur. Maybe this is the reason.

Armin

Former Member
0 Kudos

Hi,

the error Cannot add element with duplicate ID "Label" of type com.sap.tc.webdynpro.clientserver.uielib.standard.impl.TextView says that already some element with the id exists.

see the "Armin Reichert " posts in this thread.

Regards,

ramesh