cancel
Showing results for 
Search instead for 
Did you mean: 

Removing values from a drop down

Former Member
0 Kudos

Hi,

I have a requirement where I have to remove some fields from a drop down based on certain conditions.

The dropdown is a dropdown by key and vthe alues are getting populated from a standard RFC (HRXSS_PER_P0210_US).

E.g suppose the standard RFC has key 1 for Jan, 2 for Feb, 3 for March....and so on. Here we are getting all the values for the year, now the requirement will be to display only those months which has 31 days in it in the dropdown.

In layman term we have to filter some of the values from the dropdown before displaying.

Thanks

Shantanu

Accepted Solutions (0)

Answers (7)

Answers (7)

Former Member
0 Kudos

Hi santanu..

are make sure --this code is written in component controller..

nodeSelectedInfotype().--is comming from RFC or not....just comment the condition right now...

now i have commented the if condition just check it out...

Txsta attribute in Rfc or not

for(int i=0; i<wdContext.nodeSelectedInfotype().size(); i++)

{

vset.put(wdContext.nodeSelectedInfotype().getSelectedInfotypeElementAt(i).getAttributeAsText("Txsta"), wdContext.nodeSelectedInfotype().getSelectedInfotypeElementAt(i).getAttributeAsText("Txsta"));

}

thanks

jati

Former Member
0 Kudos

Hi,

I checked but I am getting only one record.

When I checked the size of my node it was coming as 1 and when I wrote this code in component controller I was getting size as 0.

Please help.

Thanks

Shantanu

Former Member
0 Kudos

Hi santanu..

can you tell me where you check your node size..if you check at RFC then Ok..some tiem it will not excuted properly..

firstly you have to excute the RFC then you calculate your node size...if not comming node size then some problem in back end....not comming data into RFC--then it will not excuted properly..just you print the value where you excute the RFC.

like

wdContext.current<back node name)_input().modelObject().execute()

wdContext.nodeOutput().invalidate();

wdComponentApi.getMassagemanager().reportsuccess("size"+<node>.size);

then put above code for requrement..if you are create twodiffernt method for Excute RFc and creatin drop down..then

let assume all method will wriitten in component controller

IN excute RFC method---

public void excute_rfc_mode(){

/.................instance you model node

........................................as you set parameter above..........

wdContext.current<back node name)_input().modelObject().execute()

wdContext.nodeOutput().invalidate();

wdComponentApi.getMassagemanager().reportsuccess("size"+<node>.size);

}

for drop down

public void createDropdown()

{

IWDAttributeInfo attribinfo = wdContext.nodeNode_filling_status().getNodeInfo().getAttribute("Txsta");

//here you call rfc method.....

wdThis.excute_rfc_mode();

ISimpleTypeModifiable fillstatus = attribinfo.getModifiableSimpleType();

vset = fillstatus.getSVServices().getModifiableSimpleValueSet();

if(vset!=null){

if(!vset.isEmpty()){

int size=vset.size();

for(int i=size-1;i>=0;i--){

vset.removeKey(vset.getKey(i));

}

}

}

for(int i=0; i<wdContext.nodeSelectedInfotype().size(); i++)

{

vset.put(wdContext.nodeSelectedInfotype().getSelectedInfotypeElementAt(i).getAttributeAsText("Txsta"), wdContext.nodeSelectedInfotype().getSelectedInfotypeElementAt(i).getAttributeAsText("Txsta"));

}

}

then this method call in init method of component controllerr

public void wdDoinit(){

wdThis.createDropdown();

}

hope you will get the answar

thanks

jati

Former Member
0 Kudos

Hi santanu,

do one thing

This code must be written in your Component contoller WDinit( )method

IModifiableSimpleValueSet vset is declare in your -

//@other

IModifiableSimpleValueSet vset

//@end

In component contoller

public void WdInit(){

IWDAttributeInfo attribinfo = wdContext.nodeNode_filling_status().getNodeInfo().getAttribute("Txsta");

ISimpleTypeModifiable fillstatus = attribinfo.getModifiableSimpleType();

vset = fillstatus.getSVServices().getModifiableSimpleValueSet();

if(vset!=null){

if(!vset.isEmpty()){

int size=vset.size();

for(int i=size-1;i>=0;i--){

vset.removeKey(vset.getKey(i));

}

}

}

for(int i=0; i<wdContext.nodeSelectedInfotype().size(); i++)

{

if((wdContext.nodeSelectedInfotype().getSelectedInfotypeElementAt(i).getTxsta() != "06") ||

(wdContext.nodeSelectedInfotype().getSelectedInfotypeElementAt(i).getTxsta() != "6"))

{

vset.put(wdContext.nodeSelectedInfotype().getSelectedInfotypeElementAt(i).getTxsta(), wdContext.nodeSelectedInfotype().getSelectedInfotypeElementAt(i).getLtext02());

}

}

thanks

jati

Edited by: sudhir kumar on Apr 1, 2009 11:47 AM

Former Member
0 Kudos

Hi

Thanks for all replies.

But I am facing the same problem of index out of bound exception.

Actually the selectedInfotype node is bound to a structure and that structure contains Txsta field.

The node selectedInfotype is of cardinality 0..n and the node which I binded to the dropdown node_filling_status is of cardinality 1..1.

Suggest me if this can be a error for exception as we are looping

for(int 1 = 0; i < ......selectedInfotype.size(); i++)

whether the above statement is causing problem.

Thanks

Shantanu

yogesh_galphade
Contributor
0 Kudos

Hi

Once you try with Bapi/Rfc, do all the filteration on that level.

Former Member
0 Kudos

Hi Santanu,

I have some piece of code in localy..code also using hardcode the month in dropdown..just follow your requirement

IWDAttributeInfo attrInfo =(IWDAttributeInfo) wdContext.getNodeInfo().getAttribute(IPrivatePrintViewView.IContextElement.DROP);

ISimpleTypeModifiable ms=attrInfo.getModifiableSimpleType();

IModifiableSimpleValueSet va=ms.getSVServices().getModifiableSimpleValueSet();

va.put("1","jan");

va.put("2","feb");

va.put("3","jmar");

va.put("4","apr");

va.put("5","may");

va.put("6","jun");

va.put("7","july");

String day[]={"2","4","6"};

if(!va.isEmpty()){

int size=va.size();

int s=day.length;

for(int i=size-1;i>=0;i--)

{

for(int j=s-1;j>=0;j--){

if(va.getKey(i).equals(day[j])){

va.removeKey(va.getKey(i));

}

}

}

}

above code is running forfectly in locally

As your requirement format in below..

//if value node is created in component

{

}

IIWDAttributeinf0 attinfo=wdContext.get<Node>.getNodeinfo().getAttribute(.......);

ISimpleTyp[eModifiablr msType=attinfo.getModifiableSimpleType();

IModifiableSimpleType va=msType.getSvService()getModifiableSimpleValueSet();

for(int i=0;i<<modelsize;i++)

{

va.put(wdContext.node<node>.get<node>ElementAt(i).getAttributeAsText("key")

,wdContext.node<node>.get<node>ElementAt(i).getAttributeAsText("value"))

}

string day[]={"2","4","6","9","11"};

if(!va.isEmpty()){

int size=va.size();

int s=day.length;

for(int i=size-1;i>=0;i--)

{

for(int j=s-1;j>=0;j--){

if(va.getKey(i).equals(day[j])){

va.removeKey(va.getKey(i));

}

}

}

}

thanks

jati

Former Member
0 Kudos

Hi,

I made changes accordingly but now I am getting error of array out of bound.

The initial exception that caused the request to fail, was:

  java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 

    at java.util.ArrayList.RangeCheck(ArrayList.java:507)
    at java.util.ArrayList.get(ArrayList.java:324)
    at com.sap.tc.webdynpro.progmodel.context.Node$ElementList.getElement(Node.java:2031)
    at com.sap.tc.webdynpro.progmodel.context.Node$MappedElementList.getElement(Node.java:2396)
    at com.sap.tc.webdynpro.progmodel.context.Node$MappedElementList.getElement(Node.java:2396)
    ... 45 more

My scenarion is I have a standard RFC and it is bound to a node selectedInfotype, the attribute of this model is bound to the dropdown. This node is of cardinality 0..n.

What I did I made another value node Node_filling_status of cardinality 1..1 and an attribute Txsta and binded that attribute to the dropdown removing the previous binding.

Code written at init()

IWDAttributeInfo attribinfo = wdContext.nodeNode_filling_status().getNodeInfo().getAttribute("Txsta");
ISimpleTypeModifiable fillstatus = attribinfo.getModifiableSimpleType();
IModifiableSimpleValueSet vset = fillstatus.getSVServices().getModifiableSimpleValueSet();
	
vset.clear();
	
for(int i=0; i<= wdContext.nodeSelectedInfotype().size(); i++)
{
  if((wdContext.nodeSelectedInfotype().getSelectedInfotypeElementAt(i).getTxsta() != "06") || 
     (wdContext.nodeSelectedInfotype().getSelectedInfotypeElementAt(i).getTxsta() != "6"))
      {
         vset.put(wdContext.nodeSelectedInfotype().getSelectedInfotypeElementAt(i).getTxsta(),  	       wdContext.nodeSelectedInfotype().getSelectedInfotypeElementAt(i).getLtext02());
      }
else{ vset.put("00", "");}
}

But I am getting the above mentioned error.

Please help.

Former Member
0 Kudos

Hi,

Please change the code to

for(int i=0; i< wdContext.nodeSelectedInfotype().size(); i++)

Hope it will solve your issue.

Jithin

Edited by: jithin james on Apr 1, 2009 5:55 AM

Former Member
0 Kudos

Hi,

No, I am still facing the same error.

java.lang.IndexOutOfBoundsException: Index: 1, Size: 1

at java.util.ArrayList.RangeCheck(ArrayList.java:507)

at java.util.ArrayList.get(ArrayList.java:324)

at com.sap.tc.webdynpro.progmodel.context.Node$ElementList.getElement(Node.java:2031)

at com.sap.tc.webdynpro.progmodel.context.Node$MappedElementList.getElement(Node.java:2396)

at com.sap.tc.webdynpro.progmodel.context.Node$MappedElementList.getElement(Node.java:2396)

... 45 more

Former Member
0 Kudos

FYI,

The selectedInfotype node is bound to a structure which has one the field Txsta.

Will that be causing a problem of index out of bound exception.

Please help.

Thanks

Shantanu

Former Member
0 Kudos

Hi,

You have written this code..

for(int i=0; i< =wdContext.nodeSelectedInfotype().size(); i++)

Here your node size is 1 and u are trying to acess the value at index 1...that gives you the error java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 so once if you have changed the code to

for(int i=0; i< wdContext.nodeSelectedInfotype().size(); i++)

the error would have been resolved. Atleast this error should be resolved. So please try it once again. make sure you save all data and deploy..

Jithin

Former Member
0 Kudos

Hi Santanu,

you have to do one thing when you populated drop down you should do the coding for SVS.

IWDAttributeinf0 attinfo=wdContext.get<Node>.getNodeinfo().getAttribute(.......);

ISimpleTyp[eModifiablr msType=attinfo.getModifiableSimpleType();

IModifiableSimpleType valueSet=msType.getSvService()getModifiableSimpleValueSet();

for(int i=0;i<<modelsize;i++)

{

valueSet.put("key","value");

}

hrere you have to put some code for requirement

string day[]={"2","4","6","9","11"};

if(!valueSet.empty()){

int size=valueSet.size();

int s=day.length;

for(int i=size-1;j>=0;j--)

{

for(int j=s-1;j>=0;j--){

if(valueSet.key(i).equals(day[ij)

valueSet.removeKey(valueSet.getKey(i));

}}

}

thanks

jati

Edited by: sudhir kumar on Mar 31, 2009 6:53 AM

Edited by: sudhir kumar on Mar 31, 2009 6:54 AM

Former Member
0 Kudos

Hi,

Still I am facing the same issue.

Not able to remove few values from the drop down.

1. How to get the key value from the node which is binded to the dropdown.

2. How to remove those key from the node.

Thanks

Shantanu

former_member185086
Active Contributor
0 Kudos

Hi

Follow the sudhir reply will solve your problem.

1. Populate all the data from model node to simple type with constraints look this code

// Model node which return all the month 
		IPublicAdminComp.IReturnGetAllDistrictElement district;

		// note which contain the attribute which is bound to Dropdown 
		IWDNodeInfo nodeinfo_dist = wdContext.nodeRegionDetails().getNodeInfo();

		// this is the attribute which is bound to dropdown same as previous line but this is for att and that is for node 
		IWDAttributeInfo attributeInfo = nodeinfo_dist.getAttribute(IPublicAdminComp.IRegionDetailsElement.DISTRICTCODE);
		ISimpleTypeModifiable districtYype = attributeInfo.getModifiableSimpleType();
		IModifiableSimpleValueSet valueSet_dist = districtYype.getSVServices().getModifiableSimpleValueSet();

		// Each time it will clear the node 
		valueSet_dist.clear();

		for (int i = 0; i < wdContext.nodeReturnGetAllDistrict().size(); i++)
		{
			district = wdContext.nodeReturnGetAllDistrict().getReturnGetAllDistrictElementAt(i);
			
			// Here put your constraints/condition in this way dropdown will contain only those
			//month which has 31 days  
			{
			valueSet_dist.put(district.getSalesOrgCode(), district.getSalesOrgName());
			}
		}

Best Regards

Satish Kumar

Former Member
0 Kudos

Hi

You can remove the values from the drop down by removing the value from the context as follows

wdContext.node<node Name>.removeElement(Element object)

Note: you can create the element object by using

IPrivate<apps Name>View.I<Node Name>Element element=null;

element=wdContext.node<Node Name>().create<Node Name>Element();

we can use wdContext.node<node Name>.invalidate() to refresh the context (use if required)

Former Member
0 Kudos

Hi

Can anyone provide me a sample code for fetching value of the key of the dropdown.

Or fectching the key of the dropdown attribute defined in a node.

Thanks

Shantanu

Former Member
0 Kudos

Hi shantanu,

Please find the sample code bellow


    for(int i=0; i < wdContext.nodeTemp().size();i++)
    {
    	if(wdContext.nodeTemp().getElementAt(i).getAttributeValue("key").equals("Feb"))
    	{
    		wdContext.nodeTemp().removeElement(wdContext.nodeTemp().getElementAt(i));
    	}
    }

Ninad

Former Member
0 Kudos

Hi Shantanu,

I think you can delete the row from the response of the RFC. I mean find the Feb month and delete the entire row for feb month. I have never tried deleting from the model node but I think it should work.

If this dose not work you can copy all the values of the response from the model node to a value node and bind that value node to your drop down by key and for sure you can add delete values on in that as per your logic.

Ninad

Former Member
0 Kudos

Hi Ninad,

Thanks for your prompt reply.

But do you have any idea how to delete from model node at initialization.

Or how to copy the model node into a value node and filter the values in value node.

Please provide a sample code for the same.

Thanks

Shantanu