Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

values not getting removed from List<SelectItem>

user8696578Jul 22 2013 — edited Jul 24 2013

Hi ADF Experts,

The below is a remove functionlity which isn't working. Could you please help in this

public void removeSelectedValues(ActionEvent actionEvent) {

    // Add event code here...

    List<String> values = (List<String>)this.getPrp1().getValue(); //this has 3 values of type List<String>

           tempList = actualList; //this has 5 elements of <SelectItem> during debug its showing 5 elements. actualList and tempList is also of Type List<SelectItem>

          for (String location: values)

          {

            SelectItem si = new SelectItem(location);

            actualList.remove(si) ;//I am trying to remove but its not working<out of 5 elements I wanted to remove 3 elements>

          }

Thanks in advance

BISWA

JDeveloper 11.1.1.7.0 Version

This post has been answered by user8696578 on Jul 24 2013
Jump to Answer

Comments

Stephen J.

After you create the SelectItem si, try searching the list for it and see if you're actually getting a match.  My guess is it's not an exact match to the SelectItem object in the list, even if they have the same String value.

user8696578

Hi Stephen,

Thanks for your reply. Can you suggest any example. It still does not work.

Thanks

Biswa

Frank Nimphius-Oracle

Hi,

iterate the actualList and compare the select value label with the sting you have. You compare different instances which seems to be the reason for failure

Frank

user8696578
Answer

Hey Frank,

Thanks for the help. I solved it and below is the correct format.

  public void removeSelectedValues(ActionEvent actionEvent) {

    // Add event code here...

    List<String> list = (List<String>)this.getPrp1().getValue();

       for(int i= 0;i < list.size();i++){

              String child =list.get(i).toString();

           System.out.println(child);

           for(int j=0;j <this.actualList.size();j++){

             

               String parent =this.actualList.get(j).getValue().toString();

              

               if(child.equals(parent)){

                   System.out.println(j);

                   this.actualList.remove(this.actualList.get(j));

               }

           }

       }

}

Thanks,

Biswa

Marked as Answer by user8696578 · Sep 27 2020
1 - 4
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 21 2013
Added on Jul 22 2013
4 comments
743 views