cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help in Error in Code

Former Member
0 Kudos

Hi,

i new to WebDynpro,

i do the exercise 3 from Ja312 and in the Book i have to Add

this code Below:

the problem is that i have redlines in getCmp_firstname

and in wd.Context how can i solve it?

Regards

For resolving the issue of getCmp_firstname , i go to the component controller "Exc_IntroController" and select the context tab. There in the left Window i have context ->firstname ->lastname

public void onPlugFromStartView(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onPlugFromStartView(ServerEvent)
    
    String firstname =
    wdThis.wdGetExc_IntroController().wdGetContext().   
	currentContextElement().getCmp_firstname(); 
    
    
    String lastname =
	wdThis.wdGetExc_IntroController().wdGetContext().
	currentContextElement().getCmp_lastname();
		
		if ( ( firstname!=null ) & (lastname!=null)){
			response = "hellow , "+firstname+" " +lastname ;				
		}else {
			response = "Hellow, stranger";
		}
		
		wd.Context.currentContextElemnt().set_txtviewresult(response);
    
    
    //@@end
  }

Accepted Solutions (1)

Accepted Solutions (1)

nikhil_bose
Active Contributor
0 Kudos

wdThis.wdGetExc_IntroController().wdGetContext().

currentContextElement().getCmp_firstname();

this will access Cmp_firstname attribute in the component Exc_Intro controller where you named it as firstname and lastname

either change your code as


wdThis.wdGetExc_IntroController().wdGetContext().   
	currentContextElement().getFirstname(); 

or rename the component context attribute as cmp_firstname instead firstname

replace wd.Context with wdContext

nikhiL

Former Member
0 Kudos

Hi Nikhil,

Thanks its helps but i have now red line on set_txtviewResult

What it can be?

Regards

wdContext.currentContextElement().set_txtviewResult(response);

and i have also in response but i declare it like :

String response = null;

its o.k. ?

Regards

Former Member
0 Kudos

Hi ,

Try this

String response = "";

Regards,

Sunitha Hari

nikhil_bose
Active Contributor
0 Kudos

wdContext.currentContextElement().set after typing this you can press ctrl+ space which will list you all attributes with set method.

nikhiL

Edited by: Nikhil Bos on May 20, 2008 12:32 PM

Former Member
0 Kudos

Hi Bos,

Thanks For your Replay!

when i do ctrl+space i get 3 metods of set how i now

which of them i can use?

1 .setAttributeValue()

2. setFirstname()

3. setLastname()

i assuming that i have to use setAttributeValue() but when

i enter this code : setAttributeValue(response) i still have red line under.

Regards

nikhil_bose
Active Contributor
0 Kudos

see, set_txtviewResult(response) gives error since there is no context attribute with _txtviewResult.

1 .setAttributeValue() // common method to set values

2. setFirstname() // set firstname

3. setLastname() // set lastname

When you create new attribute in context, appropriate methods have been generated.

Hope you understand

nikhiL

Former Member
0 Kudos

Hi,

Do you have a context attribute "txtviewresult"?

If this doesnt exist create on with String data type

Can you post your context structure?

Regards

Ayyapparaj

Former Member
0 Kudos

Hi Ayyapparaj KV ,

Thanks for Replay .

which context structure u wont me to post?

Regards

Former Member
0 Kudos

Hi,

Context structure of your controller

Regards

Ayyapparaj

Former Member
0 Kudos

Hi ,

i have :FirstName LastName

if u have the book JA312in exercise 2 there is no place that it

write to add txtviewResult aand bind it to something.

but in the code the add this lines :

vwdContext.currentContextElement().setCtx_txtviewResult(response) ;

i new with this so its little confused .

Regards

Former Member
0 Kudos

Hi,

Create a context attribute Ctx_txtviewResult of type string and assign the response

regards

Ayyapparaj

Former Member
0 Kudos

Hi,

U mean to Create Value Attribute ?

how i assign the response?

Regards

Former Member
0 Kudos

Hi,

Yes a value attribute

Write the following code in the event handler of a button(for test purpose)

String response;

if ( ( firstname!=null ) & (lastname!=null))

{

response = "hellow , "firstname" " +lastname ;

}else {

response = "Hellow, stranger";

}

wdContext.currentContextElemnt().set_txtviewresult(response);

Regards

Ayyapparaj

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

if you realy have context ->firstname ->lastname in the CMP Context you should be access it with this code:

String lastname = wdThis.wdGetExc_IntroController().wdGetContext().currentContextElement().getLastname();

without the Cmp_

The wd.Context part should be wdContext without .

i hope this will help you

Former Member
0 Kudos

Hi Markus,

Thanks its helps but i have now red line on set_txtviewResult

What it can be?

Regards

wdContext.currentContextElement().set_txtviewResult(response);

Regards

Former Member
0 Kudos

Hi Ricardo,

It should be wdContext instead of wd.Context and please check in Component Controller "Exc_IntroController" whether Cmp_firstname context exists or not?

Regards,

Vaibhav