on 01-20-2006 8:31 AM
Hello,
Suppose I have two views which reside at the same component. Is it possible to access (using code) to the context of View B afrom view A without mapping the context through the controller? If yes, Can I please see some code example?
Regards,
Roy
Hi Roy,
You cannot access the <b>context</b> of a view from another view. As Nagarajan pointed out you can only <b>pass</b> data between them as plug parameters or through mapping.
Hope this helps,
Best Regards,
Nibu.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Roy,
It is possible to use the context value between two views without using a component controller.Through the <b>fire plug methods</b> u can easily pass the values between two views.
while creating outbound and inbound plugs create the parameters also for them.
<b>in the 1 view implementation on button action:
onAction()</b>
{
String name = wdContext.currentContextElement().get<att>();
wdthis.wdfireplugto2view(name);
}
<b>In the second view implementation:
onplugfrom1view()</b>{
wdContext.currentContextElement().setRes(name);
}
This should solve ur problem
Regards,
Nagarajan.
Message was edited by: Nagarajan Kumarappan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Nagarajan,
Thank you but this is not what I meant, perhaps I wasn't clear in my specific need, I apologize.
Dear Nibu,
The reason I am asking it is because I have few views and I would like to create another view which gathers data from all the other views and present it in a printable way. The current controller already contains many mappings and I didn't wanted to overload more on it. I guess the only solution is creating another custom controller and pass all the data to the printable view through it. I thought I could avoid it by simply get to each view's context directly. If you have a better idea than the one I just plotted feel free to share.
Best Regards,
Roy.
Hi Roy,
well, it <b>IS</b> possible. You can provide direct access to the context of <i><b>any</b></i> view or controller from <i><b>anywhere</b></i> and even make the interface public so that you're able to invoke functions of view A from view B (callback functions).
Although this hurts the MVC concept, it can be very useful. And it's even not complicated at all.
So here we go:
1) Create a public java class within the same package than your views reside in, and name it "ContextWrapper", for example.
File -> New -> Other -> Java -> Class
2) Paste the following code within this class:
private static IWDNode ContextWrap;
private static Object ClassWrap;
public static void setWrappers (IWDNode pContextWrap, Object pClassWrap)
{
ContextWrap = pContextWrap;
ClassWrap = pClassWrap;
}
public static IWDNode getContextWrapper ()
{
return ContextWrap;
}
public static Object getClassWrapper ()
{
return (ClassWrap);
}
3) Save the java class. Note: with the "save" toolbar button, not with the "save all metadata" toolbar button!
4) From the view which context should be accessed, paste the following code within the wdDoInit function:
ContextWrapper.setWrappers(wdContext, this);
5) To access this context within another view or controller, use the following code:
IWDNode mappedContext = ContextWrapper.getContextWrapper();
Note that you can't use the typed access any more, but that shouldn't be a problem.
6) To invoke callback functions, use the following code (example with a view named "MainView");
MainView viewRef = (MainView) ContextWrapper.getClassWrapper();
viewRef.CallbackFunction();
Where "CallbackFunction" is any public function defined within the MainView.
I hope I could help you!
Regards
Mathias
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.