cancel
Showing results for 
Search instead for 
Did you mean: 

Remove Selected Element in ItemListBox

0 Kudos

Hi All,

          There are two ItemList Boxes Say( A,B). I selected an item from List A and once I click on Button the selected item gets added to List B. But I want the selected item to be removed from List A once it gets added to List B.I tried the removeelement but did not work.

wdcontext.nodeA.removeelement(element name);

Also when i select an element in List B and try to remove, always first element is getting selected and removed. Here, i used the above removeelement(element name). The lead selection is always set to 0. I am not able to change leadselection even after selecting other elements. Please help me regarding these two issues.

thanks,

Nooruddin

Accepted Solutions (1)

Accepted Solutions (1)

ErvinSzolke
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Nooruddin,

try this way:

wdContext.nodeA().removeElementAt(wdContext.nodeA().getLeadSelection());

Setting the leadselection works this way:

wdContext.nodeA().setLeadSelection(3);  // this focuses on the 4th element, since indexing starting from 0

I hope this helps.

Regards,
Ervin

0 Kudos

thanks Ervin for replying. But i am getting error at removeElementAt(). This method is undefined..

thanks,

Nooruddin

ErvinSzolke
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

can you send me the exact line you are typing in?

For instance I can see in your initial description wdcontext which is incorrect, it has to be wdContext (case sensitive).

Another hint:

I also suggest to use the Code Insight feature.

If you enter wdContext and you press the dot (".") then press CTRL+Space then it opens up the possible methods you can type after the dot.

Regards,

Ervin

0 Kudos

Hi Ervin,

             This is the line where I am getting error.

wdContext.nodeSelectedBranches().removeElementAt(wdContext.nodeSelectedBranches().getLeadSelection());

thanks,

Nooruddin

ErvinSzolke
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi,
the code shall work.
Let me summarize.
1. create a WD application let's say called LeadSelApp
2. create a context like this
(note: I accidentally added in wrong order and I have just noticed it, now I won't change these screenshots. Add obviously in order one, two and three, but this is just an example)
3. in the Outline View press Apply Template
4. Select Table
5. select the context node and its elements
6. As result you will have this on the screen (Add also a button called "remove"):
7. Add to wdDoInit() this:
//@@begin javadoc:wdDoInit()
/** Hook method called to initialize controller. */
public void wdDoInit()
{
//@@begin wdDoInit()
IPrivateLeadSelCompView.IAElement a;
a = wdContext.nodeA().createAElement();
a.setOne("1");
a.setTwo("2");
a.setThree("3");
wdContext.nodeA().addElement(a);

a = wdContext.nodeA().createAElement();

a.setOne("4);

a.setTwo("5);

a.setThree("6);

wdContext.nodeA().addElement(a);

}
Your Event onActionRemove() looks this way:

public void onActionRemove(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionRemove(ServerEvent)

wdContext.nodeA().removeElementAt(wdContext.nodeA().getLeadSelection());

//@@end

}

It behaves in runtime this way:
After first invocation you see this:

Select a line

Press remove

Regards,

Ervin

0 Kudos

But here i am tying two itemlistbox ui elements...

thanks,

Nooruddin

0 Kudos

Ervin,

        Really appreciate your patience. the Problem i am facing here is eventhough i select othervalues in the itemlist box only the first item is getting removed. thats the problem i am facing.

thanks,

Nooruddin

Sharathmg
Active Contributor
0 Kudos

Try this help document.

It used item list box with drag and drop.

It should fulfill your requirement.

Document:

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f0fec52a-abad-2b10-48b8-cbdfd0...

Regards,

Sharath

Sharathmg
Active Contributor
0 Kudos

Also use the parameter mapping for the item list box(similar to mapping for buttons/links) in wdModifyView().

public IWDParameterMapping mappingOfOnLeadSelect()

Returns the parameter mapping for event onLeadSelect.


To pass UI element event parameter values into action handler parameters,
a parameter mapping has to be defined. Add code like the following inside
method wdDoModifyView() of the view controller: 

 if (firstTime)
{
   IWDItemListBox myItemListBox = (IWDItemListBox) view.getElement("ID-of-ItemListBox");
   myItemListBox.mappingOfOnLeadSelect().addSourceMapping
   (
     IWDItemListBox.IWDOnLeadSelect.INDEX, // event parameter name
     "name-of-action-parameter" // (type int)
   );
}

ErvinSzolke
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

it works with ItemListBox too.

Create an ItemListBox, make sure the parameter MultiSelection is true, assign context A to its datasource and say "two" to its Text property, and try this code in your remove event:

for ( int j = 0; j<wdContext.nodeA().size(); )  

     if (wdContext.nodeA().isMultiSelected(j))   

          wdContext.nodeA().removeElementAt(j);

      else 

          j++;

Works like a charm to me.

I added an Itemlistbox rigth below the remove button. The context is the same like the one the table has.

I multiselected (with button CTRL) the 5 and the 8

It is removed from the context and since both the table as well as the Itemlistbox has been bound to the same context, the 2 lines are removed from both the UI elements.

If I had more time I was writing a nicer code, but this one works perfectly.

Cheers,

Ervin

ErvinSzolke
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Sharath,

very nice document, I believe it 100% covers what Nooruddin requires.

Nice one.

Cheers,

Ervin

Sharathmg
Active Contributor
0 Kudos

Thank you Ervin.

0 Kudos

Thank you  Ervin and Sharath. You helped me a lot in this. The drag and drop document was a good learning for me. Will try to implement that in future. But for now the Client just wants to have two item list boxes with buttons. I was able to remove the elements now...

thanks,

Nooruddin

Answers (0)