cancel
Showing results for 
Search instead for 
Did you mean: 

How to check wrong values in isChangedByClient

Former Member
0 Kudos

Hi,

I had two issues with a validation code.

First let me describe the scenario.

We need to update the Vendor Master.

There should one primary contact against one Vendor Number.

There are multiple Secondary contact against one primary contact.

There are 4 fields for both primary and secondary contact.

Primary Contact:

First Name (Read Only, Mandatory).

Last Name (Read Only, Mandatrory).

Mobile Number (Mandatory).

Telephone (Optional).

Secondary Contact:

First Name (Mandatory).

Last Name (Mandatory).

Mobile Number (Mandatory).

Telephone (Optional).

So, I need to check two validations by Java Regular Expressions,

Name should be alphabets with ,. and space.

Telephone Number and Mobile Number would be Numbers only.

Now, the issue client wants the Sceondary Contacts table rows

can be modified without selecting them.

So, I used isChangedByClient.

That's working fine.

But the user gives First Name as Kaushik45 in first row of the secondary contact table

and also types First Name as Subho67 in third row.

The first wrong value get printed (by wdComponentAPI.getMessageManager) but

the control goes to the last wrong value.

This might be solved by using setLeadSelectionAt(i).

Now, when the user types values wrongly in First Name field for Row 1 and Row 3;

the user gets stuck in First Row.

He modifies and then click the update again.

This time update runs and update the wrong value at row 3.

So, solution might be storing all wrong values of the isChangedByClient in an array and then comparing one by one.

Please suggest.

Regards

Kaushik Banerjee

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Solved.

Former Member
0 Kudos

Hi all,

One issue is resolved. I am able tocatch all the wrong values in the else.

It was getting stopped in the first value due to raiseException.

But now also, the issue is;

I need to store all the values in array and then compare each value of the array by Java Regular Condition

untill the

for(int i=0;i<arr.length;i++)

{

if(matcher.matches for value 1==true&matcher.matches for value2==true&matcher.matches for value3==true)

{

call the update RFC

}

else if(matcher.matches for value 1=false)

{

value 1 is not matched.

}

}

Regards

Kaushik Banerjee

Former Member
0 Kudos

Hi,

I got the information about isChangedByClient()....

Its' stores the elements values at the context.

But the point is, whenever, a person deliberately gives wrong values

at 0th element's First Name, 1st element's First Name and 2nd element's First Name;

the all three wrong values are captured and displayed.

Then, I coorect the 2nd element's first name from Kaushik76 to Kaushik.

But again when I click on the update button same onActionEvent is called and this time,

it check is done on the element Kaushik only.

The matching is passed and the update RFC is called.

I can't understand why the for loop does not traverse and gets all other wrong values

which were present.

Other wrong values at : 0th element's First Name, 1st element's First Name are updated.

Regards

Kaushik Banerjee

Former Member
0 Kudos

Hi Kaushik,

Second time loop is not running so, it's taking the Last value.

Have you tried with break statement?

Please let me know.

Regards

Ramakrishna Krishnamurthy

Former Member
0 Kudos

Hi,

I tried the break statement;

it breaks the loop while first condition is satisfied.

Means, it stops at 0th element only.

But when I change the 0th element, RFC is being called even if the 1st and 2nd element has wrong values.

Regards

Kaushik Banerjee

Former Member
0 Kudos

Hi,

You are not entering loop when you clicking on the update button for the last time.

Looks a very big issue.

I hate loops.

Regards

Pooja

Former Member
0 Kudos

Hi,

I know the loop is not called.

But why so, I am not getting this behaviour.

The definition of isChangedByClient:

isChangedByClient

public boolean isChangedByClient()Returns true if the changedByClient has been set for this element. This flag will be set by the framework when an update from the client arrives. It remains true until you reset all flags in the complete context via IWDContext.resetChangedByClient().

Since this flag is kept per element, but each attribute may actually live in a different element, Web Dynpro always marks both the mapped element and the origin element marked if an attribute is changed. This has the consequence that IWDContext.resetChangedByClient() must always be called from the context in which you will look for client changes.

Returns:

true if the changedByClient has been set for this element or false otherwise.

So, I am not getting why it's not entering the loop for the second time.

Regards

Kaushik Banerjee

Edited by: Kaushik Banerjee on Aug 30, 2010 9:15 PM

Former Member
0 Kudos

Please post the actual code, your pseudocode does not make sense to me.

Former Member
0 Kudos

Hi Ilan,

I am pasting the code below.

public void onActionconf(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionconf(ServerEvent)
	MessageManager msgmanager=(MessageManager)wdThis.wdGetAPI().getComponent().getMessageManager();
	
	IPrivateMainView.IP_personNode testNodeP = wdContext.nodeP_person();
		//IPrivateMainView.IS_personNode testNodeS = wdContext.nodeS_person();
		IPrivateMainView.IS_personNode S_personNode = wdContext.nodeS_person();
	    IPrivateMainView.IS_personNode spersonNode = wdContext.nodeVendorDetails().nodeS_person();
		IPrivateMainView.IP_personElement testElementP = testNodeP.currentP_personElement();
		
	
		
		
	if(testNodeP.size()!=0){
		/*If else for tesElementP Namev null value check */		
				if(testElementP.getNamev()!=null)
				{
			/*Start of if-else for testElementP Mob Number */		
						if(testElementP.getMob_Number()!=null){
							String Mob_num = testElementP.getMob_Number();
						    String regStrforPriMob=  "[0-9]*";
							CharSequence chSeqForMob = Mob_num;
							Pattern patternForPriMob = Pattern.compile(regStrforPriMob);
						    Matcher matcherForPriMob = null;
							matcherForPriMob = patternForPriMob.matcher(chSeqForMob);
							/* Start of matcher if-else*/
							if(matcherForPriMob.matches()==true){
								if(testElementP.getTel_Number()!=null) {
								 String tel_num = testElementP.getTel_Number();
								 String regStrforPriTel = "[0-9]*";
								 CharSequence chSeqForTel = tel_num;
								 Pattern patternForPriTel = Pattern.compile(regStrforPriTel);
								 Matcher matcherForPriTel = null;
								 matcherForPriTel = patternForPriTel.matcher(chSeqForTel);
						wdComponentAPI.getMessageManager().reportSuccess("The Telephone Number of Primary Number is matching");		   
				if(matcherForPriTel.matches()==true){
				if(S_personNode.size()!=0){
				//IPrivateMainView.IS_personElement S_personElement = S_personNode.currentS_personElement();
								
							   //  for(int i=0;i<wdContext.nodeS_person().size();i++) {
										/*Start of Secondary Contact Mob Number and Tel Number if-else */	
										for(int i=0;i<wdContext.nodeS_person().size();i++){
												
										  if(wdContext.nodeS_person().getS_personElementAt(i).isChangedByClient()==true){
											IPrivateMainView.IS_personElement S_personElement = (IPrivateMainView.IS_personElement)S_personNode.getElementAt(i);
											String fName = wdContext.nodeS_person().getElementAt(i).getAttributeAsText("Namev");
											wdComponentAPI.getMessageManager().reportSuccess("The First Name for the Secondary Contact is :"+fName);																								
											String regStrforSecfName = "[a-zA-Z-øØæÆåÅ,. ]*";
											CharSequence chSeqforSecFname = fName;
											Pattern patternForSecfName = Pattern.compile(regStrforSecfName);
											Matcher matcherForSecfName = null;
											matcherForSecfName =  patternForSecfName.matcher(chSeqforSecFname);
				
																						//String lName = S_personElement.getName1();
											String lName = wdContext.nodeS_person().getElementAt(i).getAttributeAsText("Name1");
											String regStrforSeclName = "[a-zA-Z-øØæÆåÅ,. ]*";
											CharSequence chSeqForSecLname = lName;
											Pattern patternForSeclName = Pattern.compile(regStrforSeclName);
											Matcher matcherForSeclName = null;
											matcherForSeclName = patternForSeclName.matcher(chSeqForSecLname);

																						//String Mob_NumSec = S_personElement.getMob_Number();
										    String Mob_NumSec = wdContext.nodeS_person().getElementAt(i).getAttributeAsText("Mob_Number");
											String regStrforSecMob ="[0-9]*";
											CharSequence chSeqForMobSec = Mob_NumSec;
											Pattern patternForSecMob = Pattern.compile(regStrforSecMob);
											Matcher matcherForSecMob = null;
											matcherForSecMob = patternForSecMob.matcher(chSeqForMobSec);
										  if(S_personElement.getMob_Number()!=null&&S_personElement.getNamev()!=null&&S_personElement.getName1()!=null){
			  	                         
			  	                         
											//String fName = S_personElement.getNamev();
                                                                                /* Start of matcher if-else*/
											if(matcherForSecfName.matches()==true&&matcherForSeclName.matches()==true&&matcherForSecMob.matches()==true){
											/* Start of City if-else */
											if(S_personElement.getTel_Number()!=null){
											  String Tel_NumSec = wdContext.nodeS_person().getElementAt(i).getAttributeAsText("Tel_Number");
											  String regStrforSecTel = "[0-9]*";
											  CharSequence chSeqForTelSec = Tel_NumSec;
											  Pattern patternForSecTel = Pattern.compile(regStrforSecTel);
											  Matcher matcherForSecTel = null;
											  matcherForSecTel = patternForSecTel.matcher(chSeqForTelSec);
				  
											/* Start of matcher if-else */
				
											if(matcherForSecTel.matches()==true&&matcherForSecfName.matches()==true&&matcherForSeclName.matches()==true&&matcherForSecMob.matches()==true){
									wdComponentAPI.getMessageManager().reportSuccess("The First Name matches the pattern: "+matcherForSecfName.matches());			
    
																		 if(wdContext.currentCheckboxckElement().getCorrespondence()==true){
    	wdComponentAPI.getMessageManager().reportSuccess("Entering the if statement for executing the RFC");
    	
																		wdThis.wdGetVdapplicationController().updVendorDetails();
																		wdThis.wdFirePlugToFinal();
																		//break;
																		}
																		else
																		{   IWDAttributeInfo atinfo = wdContext.nodeCheckboxck().getNodeInfo().getAttribute("Correspondence");
																		msgmanager.reportContextAttributeMessage(wdContext.nodeCheckboxck().getCurrentElement(),atinfo,IMessageVdapplication.KEY4,new Object[]{},true);
																		//wdComponentAPI.getMessageManager().reportException("Kryss av for korrekt informasjon før lagring",true);
																		} /* End of check box if else*/
					  
											//}
				  
				 											 			
											} /* End of Secondary Contact Telephone Number matching */
				
											else {
												wdComponentAPI.getMessageManager().raiseException("The Secondary Contact Telephone Number is not matching",true);
											}
							  
												} /* End of Secondary Telephone Number if */	
					
					
											  }
											  /* End of matcher if-else*/
											  else {
												//wdComponentAPI.getMessageManager.re("The Mobile Number is not in the correct format for Secondary contact",true);
												

                                                wdComponentAPI.getMessageManager().reportSuccess("The First Name was : "+wdContext.nodeS_person().getElementAt(i).getAttributeValue("Namev"));
                                                //Object[] firName = new Object<i>;
                                               // firName<i> = wdContext.nodeS_person().getElementAt(i).getAttributeValue("Namev");
                                                wdContext.nodeS_person().setLeadSelection(i); 	
//                                                for(int j=0;j<firName.length;j++)
//                                                { 
                                                  /*  try {
														String fuName = wdContext.nodeS_person().getElementAt(i).getAttributeValue("Namev").toString();
														wdComponentAPI.getMessageManager().reportSuccess("The Value of fuName: "+fuName);
																											//String fName = S_personElement.getNamev();
														String regStrforFuName = "[a-zA-Z-øØæÆåÅ,. ]*";
														CharSequence chSeqforFuName = fuName;
														wdComponentAPI.getMessageManager().reportSuccess("The Value of CharSequence "+chSeqforFuName);
														Pattern patternForSecFuName = Pattern.compile(regStrforFuName);
														Matcher matcherForSecFuName = null;
														matcherForSecFuName =  patternForSecFuName.matcher(chSeqforFuName);
														wdComponentAPI.getMessageManager().reportSuccess("The matcherForSecFuName is "+matcherForSecFuName);
														if(matcherForSecFuName.matches()==false){
														wdComponentAPI.getMessageManager().reportException("Error in the First Name",true);
																										}
                                                    }
                                                	catch(ArrayIndexOutOfBoundsException ae){
                                                		ae.printStackTrace();
                                                	}
                                                	catch(Exception e){
                                                		e.printStackTrace();
                                                	}*/
//                                                                                
//}
                                               //String fuName = wdContext.nodeS_person().getElementAt(i).getAttributeValue("Namev");
												wdComponentAPI.getMessageManager().reportException("The First Name, Last Name or Mobile Number is not in the correct format for Secondary contact",true);
				  //	break;
											  }
			  				
										  }
										  else {
																					  wdComponentAPI.getMessageManager().raiseException("First Name, Last Name, Mobile Number is blank",true);
			  	
																					}
			  
								   	}
	  									
										}
								   	}
								   	
								   										
								   }
								   else {
								   	wdComponentAPI.getMessageManager().raiseException("The Telephone Number of the Primary Contact is in the Correct format",true);
								   	
								   }
									
								} /* Telephone Number element null*/
								
								//else{}
				/*Start of Secondary Contact Size if-else */				
						/* End of if-else for Secondary Contact Size */
//			  else {
//			  	wdComponentAPI.getMessageManager().reportException("The Mobile No of the Primary Contact is not in the correct format",true);		   			
//			  }
					    
				}
				/* End of matcher if-else for Primary Contact*/
				
				else{
					wdComponentAPI.getMessageManager().reportException("Primary Contact Mobile Nunber is not in the correct format",true);
				}
				
			}
			/* if for testElementP Mob Number */
			
			
			
			else {
				wdComponentAPI.getMessageManager().reportException("No Primary Contact Mobile Number",true);
			}
			
			
			
		} /* End of If else for tesElementP Namev null value check */	
				else {
					wdComponentAPI.getMessageManager().reportException("There is no First Name for Primary Contact",true);		
				}
	
		  	
    	
    }// else if for testNodeP size closed
    
    else{
    	wdComponentAPI.getMessageManager().reportException("There is no element in Primary Contact",true);
    }

    //@@end
  }

Regards

Kaushik Banerjee

Former Member
0 Kudos

if(S_personNode.size()!=0){

//IPrivateMainView.IS_personElement S_personElement = S_personNode.currentS_personElement();

// for(int i=0;i = wdContext.nodeS_person().getElementAt(i).getAttributeValue("Namev");

wdContext.nodeS_person().setLeadSelection(i);

// for(int j=0;j<firName.length;j++)

// {

/* try {

String fuName = wdContext.nodeS_person().getElementAt(i).getAttributeValue("Namev").toString();

wdComponentAPI.getMessageManager().reportSuccess("The Value of fuName: "+fuName);

//String fName = S_personElement.getNamev();

String regStrforFuName = "[a-zA-Z-øØæÆåÅ,. ]*";

CharSequence chSeqforFuName = fuName;

wdComponentAPI.getMessageManager().reportSuccess("The Value of CharSequence "+chSeqforFuName);

Pattern patternForSecFuName = Pattern.compile(regStrforFuName);

Matcher matcherForSecFuName = null;

matcherForSecFuName = patternForSecFuName.matcher(chSeqforFuName);

wdComponentAPI.getMessageManager().reportSuccess("The matcherForSecFuName is "+matcherForSecFuName);

if(matcherForSecFuName.matches()==false){

wdComponentAPI.getMessageManager().reportException("Error in the First Name",true);

}

}

catch(ArrayIndexOutOfBoundsException ae){

ae.printStackTrace();

}

catch(Exception e){

e.printStackTrace();

}*/

//}

//String fuName = wdContext.nodeS_person().getElementAt(i).getAttributeValue("Namev");

wdComponentAPI.getMessageManager().reportException("The First Name, Last Name or Mobile Number is not in the correct format for Secondary contact",true);

// break;

}

}

else {

wdComponentAPI.getMessageManager().raiseException("First Name, Last Name, Mobile Number is blank",true);

}

}

/*End of Secondary Contact Mob Number and Tel Number if-else */

}

}

}

else {

wdComponentAPI.getMessageManager().raiseException("The Telephone Number of the Primary Contact is in the Correct format",true);

}

} /* Telephone Number element null*/

//else{}

/*Start of Secondary Contact Size if-else */

/* End of if-else for Secondary Contact Size */

}

/* End of matcher if-else for Primary Contact*/

else{

wdComponentAPI.getMessageManager().reportException("Primary Contact Mobile Nunber is not in the correct format",true);

}

}

/* if for testElementP Mob Number */

else {

wdComponentAPI.getMessageManager().reportException("No Primary Contact Mobile Number",true);

}

} /* End of If else for tesElementP Namev null value check */

else {

wdComponentAPI.getMessageManager().reportException("There is no First Name for Primary Contact",true);

}

}// else if for testNodeP size closed

else{

wdComponentAPI.getMessageManager().reportException("There is no element in Primary Contact",true);

}

//@@end

}

Former Member
0 Kudos

Hi Ilan,

Could you send me a contact id so, that I can send the whole code?

It's not getting pasted here.

Regards

Kaushik Banerjee

Former Member
0 Kudos

removed

Edited by: Ilan Pillemer on Aug 31, 2010 12:34 PM

Former Member
0 Kudos

You need to put bracket code bracket on both sides.. please post rest of the code.. this is all I see.


public void onActionconf(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent ) { 
    //@@begin onActionconf(ServerEvent) 
    MessageManager msgmanager=(MessageManager)wdThis.wdGetAPI().getComponent().getMessageManager();
    IPrivateMainView.IP_personNode testNodeP = wdContext.nodeP_person(); 
    //IPrivateMainView.IS_personNode testNodeS = wdContext.nodeS_person();
    IPrivateMainView.IS_personNode S_personNode = wdContext.nodeS_person();
    IPrivateMainView.IS_personNode spersonNode = wdContext.nodeVendorDetails().nodeS_person();
    IPrivateMainView.IP_personElement testElementP = testNodeP.currentP_personElement();
    if(testNodeP.size()!=0){ /*If else for tesElementP Namev null value check */
	if(testElementP.getNamev()!=null) { /*Start of if-else for testElementP Mob Number */	
	    if(testElementP.getMob_Number()!=null){ 
		String Mob_num = testElementP.getMob_Number();
		String regStrforPriMob= "[0-9]*"; 
		CharSequence chSeqForMob = Mob_num;
		Pattern patternForPriMob = Pattern.compile(regStrforPriMob);
		Matcher matcherForPriMob = null;
		matcherForPriMob = patternForPriMob.matcher(chSeqForMob);
		/* Start of matcher if-else*/
		if(matcherForPriMob.matches()==true){
		    if(testElementP.getTel_Number()!=null){ 
			String tel_num = testElementP.getTel_Number();
			String regStrforPriTel = "[0-9]*";
			CharSequence chSeqForTel = tel_num; 
			Pattern patternForPriTel = Pattern.compile(regStrforPriTel);
			Matcher matcherForPriTel = null;
			matcherForPriTel = patternForPriTel.matcher(chSeqForTel);
			wdComponentAPI.getMessageManager().reportSuccess("The Telephone Number of Primary Number is matching");
			if(matcherForPriTel.matches()==true){
			    if(S_personNode.size()!=0){ 
				//IPrivateMainView.IS_personElement S_personElement = S_personNode.currentS_personElement(); 
				// for(int i=0;i

Former Member
0 Kudos

Hi Illan,

I sent you the full code in your contact id mentioned in SDN.

Regards

Kaushik Banerjee

Former Member
0 Kudos

Its still not clear to me what your problem is from your comments in this thread.

It looks like to me you loop through the entire list and check the elements that are changed.

The moment you find the first element that has been changed..

If the change is acceptable you update details and call a plug to navigate away.

So the first time it finds all your changed items and says what they are.

The second time, when it finds you have corrected one of them it calls the update and fires a plug thereby exiting the loop at this point.

What happens if you do not fire the plug?

And does the updVendorDetails() call only update one line?


 if(wdContext.currentCheckboxckElement().getCorrespondence()==true){
	wdComponentAPI.getMessageManager().reportSuccess("Entering the if statement for executing the RFC");
								
	wdThis.wdGetVdapplicationController().updVendorDetails();
	wdThis.wdFirePlugToFinal();
	//break;
	}  else { 
          IWDAttributeInfo atinfo = wdContext.nodeCheckboxck().getNodeInfo().getAttribute("Correspondence");
								 msgmanager.reportContextAttributeMessage(wdContext.nodeCheckboxck().getCurrentElement(),atinfo,IMessageVdapplication.KEY4,new Object[]{},true)
//wdComponentAPI.getMessageManager().reportException("Kryss av for korrekt informasjon før lagring",true);
} 

Former Member
0 Kudos

Hi Ilan,

You are correct.

If I stop the FirePlug Navigate from MainView(Current View Name) to Final View; it will stop there.

Now, the logic is fine.

First Time it's travesre the loop and then prints all wrong elements in the else statement.

Second time as the last element (say last wrong value) is corrected, so isChangedByClient gets the correct

value; so, it executes RFC and goes to the Final View.

One solution would be to write the validation code in one function and the code to call the update RFC in another function.

The update button click will call both the function one by one.

But till now I don't have the clear picture.

Regards

Kaushik Banerjee

Former Member
0 Kudos

I would definitely recommend breaking this function up into many smaller functions.

There are two reasons for breaking code up into smaller functions

(1) re-use of common code, and ease in updating it

(2) self documenting and ease in reading the code when looking for bugs.

You could for example do this:

pseudocode


bool isValidated( perhaps pass the node here ) {

code that checks all changed nodes are valid

};

..  (in your onAction code)
if ( (isValidated ( nodeToBeChecked ) ) {
 update();
}
..

Former Member
0 Kudos

Hi,

You are right.

I will break this code into two smaller functions.

But how to solve the issue;

when users corrects 1 value (in a row3),

but keeps wrong value in row2 and row1;

the isChangedByClient() takes the last value and then, the condition satisfies....

I want to do multiple update based on changed values in the secondary contact table;

do I really want to use isChangedByClient() ?

Regards

Kaushik Banerjee

Former Member
0 Kudos

Maybe diagram what you want to do using a flowchart?

Once you are satisfied the flow chart is correct then write the code.

Former Member
0 Kudos

Hi Ilan,

I now had the clear picture, what is going wrong.

It can be solved but I need a datastructure, most probable a single dimensional array.

There should two global variables int res, j;

j=1;

In my code against the update button click, there should be two method called.

int validation(){

write all validation logic here.

First inside the for loop for secondary contact;

I need to check validation for each element in the loop for say First Name.

matchingfnamesecContact(i).matches==true

then, set flag(i)=1;

else flag(i) = 0;

res=j*falg(i);

return res;

}

void callUpdate(int Result) {

Result=this.res;

if(Result==1)

{

Call the update RFC from the view.

}

}

Regards

Kaushik Banerjee

Edited by: Kaushik Banerjee on Sep 1, 2010 12:26 PM

Former Member
0 Kudos

Looks like I solved it.

But I am doing Unit Testing of the Code.

Regards

Kaushik Banerjee