cancel
Showing results for 
Search instead for 
Did you mean: 

Setting data in the context

Former Member
0 Kudos

Ok, I will admit I'm very much a Web Dynpro newbie, and this whole context thing is really confusing for me, though I've been a Java programmer for 6 years.

Here's what's going on. Basically, I'm trying to make a more simplified version of the spell checker (using Jazzy) that was written about in a weblog on here. But, the part that's messing me up is the context. In my Component Controller, I defined a couple things. I defined a value attribute called "misspelledWord", a value node called "Suggestions", and under that a value attribute called "word" (I have more defined than that, but for the purposes of this post, that's all you need to know)

I have a text area, and a "Check Spelling" button underneath it, and in the action for that button, I want to set all those context attributes so that I can display them in the pop-up screen that comes up, which shows the user a misspelled word and all the suggestions for it. Or, at least, it's SUPPOSED to.

In my code I do the following:

wdThis.wdGetSpellCheckComponentController().wdGetContext().currentContextElement().setMisspelledWord(ew.getText());

"ew" is an object I defined called ErrorWord, which contains all the information about each misspelled word and gets populated in my spell checking class.

This works GREAT. misspelledWord gets populated and displayed on the pop-up screen.

My problem is getting all the suggestions. I have them all in an ArrayList in my ErrorWord object, so I HAVE them, I just can't seem to store them in the context. Everything I try gives me a NullPointerException.

All I want to do is loop through my ArrayList, and assign the String value I have in there to the "word" attribute.

Thanks in advance for any help you are able to provide,

Jennifer

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos
for (Iterator i = ew.getSuggestions().iterator(); i.hasNext() ; )
{
  String word = (String) i.next();
  ISuggestionsElement suggestion = wdContext.nodeSuggestions().createAndAddSuggestionsElement();
  suggestion.setWord(word);
}

The context node "Suggestions" should be able to store any number of elements (cardinality = 0:N).

About "context":

The context is a generic, hierarchical storage for the data accessible by a controller. Contexts may be mapped which means you get references to the context elements in used controllers or to the underlying model.

Armin

Former Member
0 Kudos

Well, I'm no longer getting a NullPointerException, and for that I'm extremely grateful!

However, it's still not displaying in my pop-up view.

I'm wondering if I somehow defined my Suggestions node wrong, or something? Because, I don't have a createAndAddSuggestionsElement method option, so I had to just do createSuggestionsElement. So, I guess it makes sense that it's not showing up, since it wasn't actually added, but how do I add it then?

Thanks so much,

Jennifer

former_member182372
Active Contributor
0 Kudos

Hi Jennifer,

try to call


wdContext.nodeSuggestions().addElement(suggestion);

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

I<Node>.createAndAdd<Node>Element() is available in newer Web Dynpro releases.

In older releases, use I<Node>.create<Node>Element() and IWDNode.addElement().

Armin

Former Member
0 Kudos

Thank you SO much to both of you! It's finally working.

I don't want to admit how long I spent trying to figure this out on my own.

Former Member
0 Kudos

I really recommend Chris Whealy's excellent book "Inside Web Dynpro for Java".

http://www.amazon.com/gp/product/1592290388/ref=sr_11_1/102-6967880-1651331?%5Fencoding=UTF8

Armin