cancel
Showing results for 
Search instead for 
Did you mean: 

Strange issue clearing context element

derekvincent
Participant
0 Kudos

Hello, I am having a strange issue with a couple WebDynpro I am writting. I am writting a web dynpro application in 04 the leverages some web services. I am not using AWS but the old model type.

I have a WS call where the input signature look likes this:


  CustomerId[] 
  Origin 
  Destination 
  Date 

All the inputs are strings but I can take a array of customer Id's.

Now when I import the WS into the NWDS I get a model context that looks as follows:


CustomerFlight 
       - CustomerId 
               - value 
      - Origin 
      - Destination 
      - Date 
      - Response_CustomerFlight 
          .... 

So I can set the Origin, Destination, Date no problem accessing the currentCustomerFlightElement but the set CustomerId has caused me some greif. Accessing the nodeCustomerId that was creating an adding a element for each entry in the list never seems to properly set the context elements. I found the in the currentCustomerFlightElement.modelObject their is a setCustomId which takes an array or list method. This method seem to work to set the values but I do not seem to be able to clear the values in the modeobject ever and passing in a new array of new values adds to the original list and does not over write.

I have trie using different invalidate functions in the different nodes as well removing all of the elementsin the node for the customer Id but with no joy.

Any ideas?

Accepted Solutions (0)

Answers (4)

Answers (4)

derekvincent
Participant
0 Kudos

I figured out the issue. Their are 2 setters for the method. One takes a List and the other takes an array. The one that takes the array seems to add to the array in the context model currently. The list one replace the current model with the passed in list.

I passed in a blank list and all is well.

D.

former_member187439
Active Participant
0 Kudos

Hi Derek, I'm facing a similar issue. Can you help out?

I have to treat one of my model nodes as a table and loop it to pass more than one value before i execute the function module.

For doing this, when i do just invalidate, i face a problem.

wdContext.nodeExt_Text_Tbl().invalidate();

The old value is not getting cleared from the second time.The new values are getting appended to the old values every time my code passes new values.

So, the only solution i had is to remove values through the below code

wdContext.nodeExt_Text_Tbl().invalidate();

while ( wdContext.nodeExt_Text_Tbl().size() > 0 ) wdContext.nodeExt_Text_Tbl().removeElement( wdContext.nodeExt_Text_Tbl().getElementAt(0) );

This solves the issue.But i face another big problem. That is, for the first time i call the method, my values are not getting added to the node. Only from the second time i call the method, the values are getting added.

I'm using the same method for another similar node and it works fine. I dont have a clue why i face this behaviour for this node alone. Please do help out..

Thanks in advance,

Kavitha

derekvincent
Participant
0 Kudos

Kavitha, I am not sure the issue are the same.

In my case I found that clearing the elements from the context left the underlying model intact and I had a method to work with the model object that allowed me to pass an empty ArrayList to it which worked for clearing it. I did not have an issue afterward with putting values back in.

You may want to post this as a new topic in the forum and see if someone can help. I suspect you may want elaborate a little more on the where you are setting, call the FM and clearing the context elements.

Cheers,

Derek

derekvincent
Participant
0 Kudos

*Mithiu: this code looks like it is for using adaptive web services which I am not using in this case. *

Manoj, the context element themselves seem to be cleared... the code I have works and I tried your code and it works to clear the context... it just seems that clearing the specific context element does not clear the modeloject value for the customer Id array.

Derek.

derekvincent
Participant
0 Kudos

Yea no problem... The code below is what I currently but I have tried a couple differnet things like creating a custimerId element and adding it to the node.


public void executeViewCustomerDespatch( )
{
  //@@begin executeViewCustomerDespatch()
  ArrayList customerList = new ArrayList();

  if (wdContext.currentCustomerDespatchViewElement().getCustomers().equalsIgnoreCase("All")) {	

    IWDAttributeInfo customerAttributeInfo = wdContext.nodeCustomerDespatchView().getNodeInfo().getAttribute("Customers");
    ISimpleTypeModifiable customerType = customerAttributeInfo.getModifiableSimpleType();
    IModifiableSimpleValueSet customerValueSet = customerType.getSVServices().getModifiableSimpleValueSet();
  	  	
    for (int i=0; i < customerValueSet.size(); i++) {
      // Do not add the All value the array that is going to be sent to the webservice.
      if (!customerValueSet.getKey(i).toString().equalsIgnoreCase("All")){
        customerList.add((String)customerValueSet.getKey(i));				
      }
    }	
		    
  } else {

    customerList.add(wdContext.currentCustomerDespatchViewElement().getCustomers());
  }
	
  String[] customers = new String[customerList.size()];
  customerList.toArray(customers);
	
  wdContext.currentViewCustomerDespatchElement().modelObject().setCustomerId((List)customerList);	
  wdContext.currentViewCustomerDespatchElement().setOrigin(wdContext.currentCustomerDespatchViewElement().getOrigin());
  wdContext.currentViewCustomerDespatchElement().setDestination(wdContext.currentCustomerDespatchViewElement().getDestination());
    
  SimpleDateFormat FORMATTER = new SimpleDateFormat("yyyyMMdd");
  String returnDate = null;
  returnDate = FORMATTER.format(wdContext.currentCustomerDespatchViewElement().getDate());
  wdContext.currentViewCustomerDespatchElement().setDate(returnDate);

  //$$begin Service Controller(196561066)
  IWDMessageManager manager = wdComponentAPI.getMessageManager();
  try{
    wdContext.currentViewCustomerDespatchElement().modelObject().execute();
    wdContext.nodeResponse_viewCustomerDespatch().invalidate();
    wdContext.nodeResult_viewCustomerDespatch().invalidate();
  } catch(Exception ce) {
    manager.reportException(ce.getMessage(), false);
  }
  //$$end
	
  wdContext.nodeCustomerId().invalidate();
  wdContext.nodeViewCustomerDespatch().nodeCustomerId().invalidate();
  while(wdContext.nodeCustomerId().size() !=0 ) {
  
    wdContext.nodeViewCustomerDespatch().nodeCustomerId().removeElement(
    wdContext.nodeCustomerId().getElementAt(wdContext.nodeCustomerId().size() -1));
  }	
  //@@end
}

former_member751941
Active Contributor
0 Kudos

Hi Derek,

According to the structure.

Request_CustomerFlight

- CustomerId

- value

- Origin

- Destination

- Date

- Response_CustomerFlight

Code to execute webservice model.

try

{

ModelName model = new ModelName();

Request_CustomerFlight request_CustomerFlight = new Request_CustomerFlight(model);

request_CustomerFlight.setOrigin("Give Value");

request_CustomerFlight.setDestination("Give Value");

request_CustomerFlight.setDate("Give Value");

request_CustomerFlight arrayOfCustomerId = new ArrayOfCustomerId();

request_CustomerFlight.setCustomerId(arrayOfCustomerId);

int size = "Give Value";

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

{

CustomerId customerId = new CustomerId();

customerId.setValue(<"Give Value">);

arrayOfCustomerId.addCustomerId(customerId);

}

wdContext.currentRequest_CustomerFlightElement().modelObject().execute();

wdContext.nodeResponse_CustomerFlight().invalidate();

}

catch(CMIException excp)

{

wdComponentAPI.getMessageManager().reportException("Can't Execute Model.",true);

}

Regards,

Mithu

Former Member
0 Kudos

Hi,

wdContext.nodeCustomerId().invalidate();

After the the execution of the above line there must not be any element in the node CustomerId.

But anyhow you are explicitly removing the elements using:

while(wdContext.nodeCustomerId().size() !=0 ) {

wdContext.nodeViewCustomerDespatch().nodeCustomerId().removeElement(

wdContext.nodeCustomerId().getElementAt(wdContext.nodeCustomerId().size() -1));

}

Don't you think that (wdContext.nodeCustomerId().size() -1) is constant here.

Try this:

while(wdContext.nodeCustomerId().size() !=0 ) {

int i = wdContext.nodeCustomerId().size();

wdContext.nodeViewCustomerDespatch().nodeCustomerId().removeElement(

wdContext.nodeCustomerId().getCutomerIdElementAt(i--));

}

Ho[pe this will solve your problem.

thanks & regards,

Manoj

Former Member
0 Kudos

Hi,

Could you post the line of codes that you have used to execute this model object.

Then it will be more cllear to find out the bug.

thanks & regards,

Manoj