Home » Eclipse Projects » Remote Application Platform (RAP) » Read data from custom widget.
Read data from custom widget. [message #122413] |
Tue, 24 February 2009 07:43  |
Eclipse User |
|
|
|
Originally posted by: haglund86.hotmail.com
Hello.
I have created a custom widget which is built on qooxdoo and consists of
two lists. I can populate one of the lists from the java code, but how
do I read data from the list to the RAP application?
I have looked at the google maps example and they are using the function
readData in the LCA-file. But the example was to complex for me to fully
understand.
So my question is how do I read a variable from the javascript?
I would appreciate if someone could post an simple example of a custom
widget that reads data from the qooxdoo code.
|
|
| | | | |
Re: Read data from custom widget. [message #122552 is a reply to message #122544] |
Wed, 25 February 2009 05:14   |
Eclipse User |
|
|
|
Hi Erik,
I do not understand why you call writer.call(); from LCA#readData? The
LCA#readData method is called to get the data from the JavaScript.
LCA#renderChanges is the place to call the JavaScript function.
Best,
Ivan
Erik Haglund wrote:
> When I use the function call:
>
> writer.call();
>
> from readData in the LCA-file I get an infinity loop (probably because
> req.send() in the qooxdoo code triggers the readData function in the
> LCA-file again and so on). This is taking alot of resources. Is it
> possible to get around this problem?
>
> Regards
> Erik
> Ivan Furnadjiev skrev:
>> Hi Erik,
>> in your LCA#renderChanges method you can use:
>> JSWriter writer = JSWriter.getWriterFor( widget );
>> writer.call(......) or writer.callStatic(......) depend on your
>> function.
>>
>> Check the existing RAP LCAs for more details.
>> Best,
>> Ivan
>>
>> Erik Haglund wrote:
>>> Hi thank you for the example code.
>>> However I have a problem related to this topic.
>>>
>>> I wan't to be able to call my qooxdoo function and read my variable
>>> at a given time.
>>> So how do I call a function in qooxdoo from the LCA?
>>>
>>> /Erik
>>> Ivan Furnadjiev skrev:
>>>> Hi Erik,
>>>> here is a simple code that put in the request the value of your
>>>> variable "this.myParam" and send the request to the server:
>>>> ------------
>>>> var widgetManager = org.eclipse.swt.WidgetManager.getInstance();
>>>> var req = org.eclipse.swt.Request.getInstance();
>>>> var id = widgetManager.findIdByWidget( this );
>>>> req.addParameter( id + ".myParam", this.myParam );
>>>> req.send();
>>>> -------------
>>>> In your LCA#readData, you can read this parameter from the request:
>>>> -------------
>>>> String value = WidgetLCAUtil.readPropertyValue( widget, "myParam" );
>>>> if( value != null ) {
>>>> // do something if the parameter is found }
>>>>
>>>> Hope that this will help.
>>>> Best,
>>>> Ivan
>>>>
>>>> Erik Haglund wrote:
>>>>> Hello.
>>>>> I have created a custom widget which is built on qooxdoo and
>>>>> consists of two lists. I can populate one of the lists from the
>>>>> java code, but how do I read data from the list to the RAP
>>>>> application?
>>>>>
>>>>> I have looked at the google maps example and they are using the
>>>>> function readData in the LCA-file. But the example was to complex
>>>>> for me to fully understand.
>>>>>
>>>>> So my question is how do I read a variable from the javascript?
>>>>> I would appreciate if someone could post an simple example of a
>>>>> custom widget that reads data from the qooxdoo code.
|
|
|
Re: Read data from custom widget. [message #122563 is a reply to message #122552] |
Wed, 25 February 2009 06:18   |
Eclipse User |
|
|
|
Originally posted by: haglund86.hotmail.com
Thank you for your reply.
Unfortunately this did not fix my problem with the infinity loop.
To give you a clear view of what I am doing:
LCA file:
public void renderChanges(Widget widget) throws IOException
{
JSWriter writer = JSWriter.getWriterFor(widget);
try {
writer.call("readItem", null);
} catch (IOException e) {
e.printStackTrace();
}
}
public void readData(Widget widget)
{
Dnd dnd = (Dnd) widget;
String location = WidgetLCAUtil.readPropertyValue(dnd, "listan" );
System.out.println(location);
}
javascript file:
readItem: function()
{
var test = "FREDD";
var widgetManager = org.eclipse.swt.WidgetManager.getInstance();
var req = org.eclipse.swt.Request.getInstance();
var id = widgetManager.findIdByWidget( this );
req.addParameter( id + ".listan", test );
req.send();
},
This code will perform a infinite loop of calls to the readItem function
in the javascript file.
Ivan Furnadjiev skrev:
> Hi Erik,
> I do not understand why you call writer.call(); from LCA#readData? The
> LCA#readData method is called to get the data from the JavaScript.
> LCA#renderChanges is the place to call the JavaScript function.
> Best,
> Ivan
>
> Erik Haglund wrote:
>> When I use the function call:
>>
>> writer.call();
>>
>> from readData in the LCA-file I get an infinity loop (probably because
>> req.send() in the qooxdoo code triggers the readData function in the
>> LCA-file again and so on). This is taking alot of resources. Is it
>> possible to get around this problem?
>>
>> Regards
>> Erik
>> Ivan Furnadjiev skrev:
>>> Hi Erik,
>>> in your LCA#renderChanges method you can use:
>>> JSWriter writer = JSWriter.getWriterFor( widget );
>>> writer.call(......) or writer.callStatic(......) depend on your
>>> function.
>>>
>>> Check the existing RAP LCAs for more details.
>>> Best,
>>> Ivan
>>>
>>> Erik Haglund wrote:
>>>> Hi thank you for the example code.
>>>> However I have a problem related to this topic.
>>>>
>>>> I wan't to be able to call my qooxdoo function and read my variable
>>>> at a given time.
>>>> So how do I call a function in qooxdoo from the LCA?
>>>>
>>>> /Erik
>>>> Ivan Furnadjiev skrev:
>>>>> Hi Erik,
>>>>> here is a simple code that put in the request the value of your
>>>>> variable "this.myParam" and send the request to the server:
>>>>> ------------
>>>>> var widgetManager = org.eclipse.swt.WidgetManager.getInstance();
>>>>> var req = org.eclipse.swt.Request.getInstance();
>>>>> var id = widgetManager.findIdByWidget( this );
>>>>> req.addParameter( id + ".myParam", this.myParam );
>>>>> req.send();
>>>>> -------------
>>>>> In your LCA#readData, you can read this parameter from the request:
>>>>> -------------
>>>>> String value = WidgetLCAUtil.readPropertyValue( widget, "myParam" );
>>>>> if( value != null ) {
>>>>> // do something if the parameter is found }
>>>>>
>>>>> Hope that this will help.
>>>>> Best,
>>>>> Ivan
>>>>>
>>>>> Erik Haglund wrote:
>>>>>> Hello.
>>>>>> I have created a custom widget which is built on qooxdoo and
>>>>>> consists of two lists. I can populate one of the lists from the
>>>>>> java code, but how do I read data from the list to the RAP
>>>>>> application?
>>>>>>
>>>>>> I have looked at the google maps example and they are using the
>>>>>> function readData in the LCA-file. But the example was to complex
>>>>>> for me to fully understand.
>>>>>>
>>>>>> So my question is how do I read a variable from the javascript?
>>>>>> I would appreciate if someone could post an simple example of a
>>>>>> custom widget that reads data from the qooxdoo code.
|
|
|
Re: Read data from custom widget. [message #122606 is a reply to message #122563] |
Wed, 25 February 2009 08:05  |
Eclipse User |
|
|
|
Hi Erik,
with your code it is normal to go into infinity loop. I will suggest the
following:
1. When there is a change in the your JavaScript variable - send the new
value to the server with the code in readItem function.
2. Store the new value in your server-side Dnd widget in LCA#readData.
2. When you need to access this value just get it from your server-side
Dnd widget directly.
Best,
Ivan
Erik Haglund wrote:
> Thank you for your reply.
> Unfortunately this did not fix my problem with the infinity loop.
>
> To give you a clear view of what I am doing:
> LCA file:
>
> public void renderChanges(Widget widget) throws IOException
> {
>
> JSWriter writer = JSWriter.getWriterFor(widget);
> try {
> writer.call("readItem", null);
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> public void readData(Widget widget)
> {
> Dnd dnd = (Dnd) widget;
> String location = WidgetLCAUtil.readPropertyValue(dnd, "listan" );
> System.out.println(location);
> }
>
> javascript file:
> readItem: function()
> {
> var test = "FREDD";
> var widgetManager = org.eclipse.swt.WidgetManager.getInstance();
> var req = org.eclipse.swt.Request.getInstance();
> var id = widgetManager.findIdByWidget( this );
> req.addParameter( id + ".listan", test );
> req.send();
> },
>
>
> This code will perform a infinite loop of calls to the readItem
> function in the javascript file.
>
>
> Ivan Furnadjiev skrev:
>> Hi Erik,
>> I do not understand why you call writer.call(); from LCA#readData?
>> The LCA#readData method is called to get the data from the
>> JavaScript. LCA#renderChanges is the place to call the JavaScript
>> function.
>> Best,
>> Ivan
>>
>> Erik Haglund wrote:
>>> When I use the function call:
>>>
>>> writer.call();
>>>
>>> from readData in the LCA-file I get an infinity loop (probably
>>> because req.send() in the qooxdoo code triggers the readData
>>> function in the LCA-file again and so on). This is taking alot of
>>> resources. Is it possible to get around this problem?
>>>
>>> Regards
>>> Erik
>>> Ivan Furnadjiev skrev:
>>>> Hi Erik,
>>>> in your LCA#renderChanges method you can use:
>>>> JSWriter writer = JSWriter.getWriterFor( widget );
>>>> writer.call(......) or writer.callStatic(......) depend on your
>>>> function.
>>>>
>>>> Check the existing RAP LCAs for more details.
>>>> Best,
>>>> Ivan
>>>>
>>>> Erik Haglund wrote:
>>>>> Hi thank you for the example code.
>>>>> However I have a problem related to this topic.
>>>>>
>>>>> I wan't to be able to call my qooxdoo function and read my
>>>>> variable at a given time.
>>>>> So how do I call a function in qooxdoo from the LCA?
>>>>>
>>>>> /Erik
>>>>> Ivan Furnadjiev skrev:
>>>>>> Hi Erik,
>>>>>> here is a simple code that put in the request the value of your
>>>>>> variable "this.myParam" and send the request to the server:
>>>>>> ------------
>>>>>> var widgetManager = org.eclipse.swt.WidgetManager.getInstance();
>>>>>> var req = org.eclipse.swt.Request.getInstance();
>>>>>> var id = widgetManager.findIdByWidget( this );
>>>>>> req.addParameter( id + ".myParam", this.myParam );
>>>>>> req.send();
>>>>>> -------------
>>>>>> In your LCA#readData, you can read this parameter from the request:
>>>>>> -------------
>>>>>> String value = WidgetLCAUtil.readPropertyValue( widget, "myParam" );
>>>>>> if( value != null ) {
>>>>>> // do something if the parameter is found }
>>>>>>
>>>>>> Hope that this will help.
>>>>>> Best,
>>>>>> Ivan
>>>>>>
>>>>>> Erik Haglund wrote:
>>>>>>> Hello.
>>>>>>> I have created a custom widget which is built on qooxdoo and
>>>>>>> consists of two lists. I can populate one of the lists from the
>>>>>>> java code, but how do I read data from the list to the RAP
>>>>>>> application?
>>>>>>>
>>>>>>> I have looked at the google maps example and they are using the
>>>>>>> function readData in the LCA-file. But the example was to
>>>>>>> complex for me to fully understand.
>>>>>>>
>>>>>>> So my question is how do I read a variable from the javascript?
>>>>>>> I would appreciate if someone could post an simple example of a
>>>>>>> custom widget that reads data from the qooxdoo code.
|
|
|
Goto Forum:
Current Time: Sun May 04 05:25:54 EDT 2025
Powered by FUDForum. Page generated in 0.04800 seconds
|