cancel
Showing results for 
Search instead for 
Did you mean: 

Using Context ariable

Former Member
0 Kudos

Hi all

Can I associate a context variable in Webdynpro-java to an Input field in my program.ie.I will create only the UIElements at design time but define the context variable and their association to UI elements will be done in program at runtime.Also can I store these context variables created(if possible) to arraylist.How can I pass that arraylist to the next view?

If anybody knows, please help me.

Thanks in advance

Fahad Hamsa

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi

Whenever you use wdContext.current<Node>Element().set<Attribute>() or wdContext.current<Node>Element().get<Attribute>() you have to be sure that the element exists.If it doesn't exist, you will get null pointer exeption because you are trying to access an element which doesn't exist.

To be able to use above methods, you can set the cardinalities of the node to either 1..1(Exactly one element) or 1..n(At least one element).This ensures that at least one elemnt is created.

If you have to use 0..1(At most 1 element) or 0..n(Any no. of elements), you will have to first create the element using wdContext.create<Node>Elemet() before using

wdContext.current<Node>Element().set<Attribute>() or wdContext.current<Node>Element().get<Attribute>().

Regards,

Ajay

Former Member
0 Kudos

Thanks,I will try it and let you know

Former Member
0 Kudos

I used the node with cardinality 1:n in my first view and component controller.Then also it is showing null pointer exception

Former Member
0 Kudos

Hi

Try This

IPrivate<ViewName>.I<Name>Node node=wdContext.node<Name>();

IPrivate<ViewName>.I<Name>Element element=wdContext.create<Name>Element();

element.setHash(new HashMap);

node.addElement(element);

Kind Regards

Mukesh

Former Member
0 Kudos

Hi

In the detailed description check on which line of your program you are getting this error.

BTW, this might be occurring because you are trying to access some method of HashMap directly e.g

HashMap hm = wdContext.currentContextElement().getHashMap();

hm.put("name","value");

You will have to instantiate the HashMap before accessing it.

e.g.

HashMap hm = new HashMap();

hm.put("name","value");

after performing the operations on HashMap you can set it to the context variable as

wdContext.currentContextElement().setHashMap(hm);

Regards,

Ajay

Former Member
0 Kudos

Hi

I declared the HashMap context variable in a node.At that time I was getting Null pointer Exception.When I deleted that node and decared the context variable in rootnode, I am getting the result.Why it happens?Can I use the HashMap context variable in a Node?

Former Member
0 Kudos

Hi Fahad,

When you created a context attribute of type Hashmap within a node, it should be given somevalue during the init process. That's why you are getting the null pointer exception

Regards,

Saravanan K

Former Member
0 Kudos

I gave the init values in the init() of my first view as

wdThis.wdGetContext.current<node>Element().set<hash>(new HashMap()).Then it is showing the null ptr exception at the starting itself.

Former Member
0 Kudos

Hi Fahad,

Please check the cardinality of the <node> is 1..1.

Kind Regards

Mukesh

Former Member
0 Kudos

Yes, you can. As this affords having references to the UI elements, it can only be done inside method wdDoModifyView().

I don't understand your question about the ArrayList etc.

Armin

suresh_krishnamoorthy
Active Contributor
0 Kudos

Hi,

I think you want pass some values from one iview to other iview. see this thread

Regards

Suresh

Former Member
0 Kudos

Hi Fahad,

You can use the Hashmap to store the context attributes using key and value. And in the next view you can retrieve the values using the KEy in Haspmap

Hope this helps,

Saravanan K

Former Member
0 Kudos

But How that hashmap will be visible in next view,because I am declaring the hashmap in the code of my first view

Thanks

Former Member
0 Kudos

HI,

You can define the hashmap name using a context variable. so that u can bind this context variable to diff views, and you can use the same hashmap in diff views to retrieve values

Regards,

Saravanan K

Message was edited by: Saravanan K

suresh_krishnamoorthy
Active Contributor
0 Kudos

Hi Fahad,

Pass Hashmap as parameter from one iview other iview through plug in.

Under Java Native Type you will find that type(hashmap).

Regards

Suresh

Former Member
0 Kudos

Can you please tell me how can I associate a context variable that is not declared with an input field in table.Also after this association with context variables,if I m putting the values in a context variable of HashMap type,can I avoid the server hitting of table elements when the row of table changes?

Former Member
0 Kudos

Hi Fahad,

Based on ur question, i realize you've applied template to create table with a node.You ask whether it is possible to insert a context attribute to the table. If my assumption fails, Kindly detail your problem

Regards,

Saravanan K

Former Member
0 Kudos

What I am trying to do is creating a table and associating

the table cell editors with context variables in the program(without declaring in context tab).After that, when user enters some values in this table, I want to store all values in a hashmap in a local HashMap variable and atlast assign this to the hashmap variable that is declared in the context tab, so that I can pass these values to the next view.I am trying to do this because I thinks it willnot goto server every time when the user changes the row in table.

Former Member
0 Kudos

I tried with a simple program using HashMap context variable in the context tab.But I m getting null pointer exception.Why it happens?Is any initialization of context variable of type HashMap is needed?If needed, how can I do that.Please give me a solution