Skip to Content
avatar image
Former Member

Context Getter/Setter for node attribute

Hi

I noticed in webdynpro tutorials a lot of hardcoded field names.

To update the value of an context variable there are getter/setters and it's perfect.

But when we need to deal with attributes of context variable it's necessary pass a string parameter containing the name of the context variable....Is this the only way? It doesn't seem to be a good programming practice for me. If at least WD generated some constants (like for messages), then it will be ok.

Follow example (Problem is in bold type):

<i>wdContext.currentContextElement().setEMailAddress("");

wdContext.getNodeInfo().getAttribute(<b>"EMailAddress"</b>)

.getModifiableSimpleType().setFieldLabel("E-Mail Address");</i>

Thanks.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Aug 19, 2004 at 03:21 PM

    Hi Ronaldo,

    it's all already there 😉 Assume you have an attribute "Address" on the root level of the context in the view controller "Work", then you can use

    wdContext.getNodeInfo().getAttribute(IPrivateWork.IContextElement.ADDRESS);

    to replace the hardcoded string "Address" for the attribute name.

    Next point: To avoid the hardcoded text for the field label, you define an entry of type "Text" in the message pool, maybe named "Mail". Text, which is not specified as standard, error or warning is referenced by the IWDTextAccessor of the current component:

    wdComponentAPI.getTextAccessor().getText("Mail");

    Hope that helps.

    Regards

    Stefan

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 20, 2004 at 01:56 PM

    Stefan

    Just Perfect.

    But tell me, where could I find this kind of information (instead of asking in the forum)? Is there any documentation that I should read? Or should I inspect all automatically generated classes to get a whole pictures of the resources offered by wd? What do you recommend?

    Is there any tutorial/sample that demonstrate best practices with wd?

    Thank you again.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Ronaldo,

      to be honest, i wonder, why not all WD tutorials do reveal those little "tricks" already. People should be pointed to the right direction right from the start, shouldn't they?

      Anyway, what i've recognized so far is, that the WD runtime API documentation is very good and always up to date, including some code samples for API methods usage on the level you want.

      Since it's not very entertaining to read Java API docs, i suggest to start with the more general documentation about Web Dynpro followed by a look into the API docs, if you want to get more implementation details. And last but not least, the Eclipse code completion feature can help you too.

      BTW, the forum is some kind of online asynchronous code completion, so don't hesitate to continue asking 😉

      I haven't seen something like best practices for Web Dynpro so far, one could think about writing some.

      Regards

      Stefan