CreamTec

AjaxSwing => Community Technical Support => : subes June 30, 2009, 07:29:58 AM

: beginOperation and endOperation in 2.5.0 Beta
: subes June 30, 2009, 07:29:58 AM
Hi,

we have been using the following piece of code to fix some synchronization issue with fields getting values set from a model:

:
public void synchronizeGUI(){
/*
 * SwingUtilities.invokeLater is used to delay the synchronization until the controls are visible
 * in the UI. This fixes a problem with tabbed windows where the values are only getting added
 * to the fields after the window updates.
 *
 * The delay fixes this problem for Swing, but AjaxSwing has to be notified about the execution
 * being delayed in EDT. To do so, we have to use AjaxSwingManager.beginOperation() and
 * AjaxSwingManager.endOperation(). Only after endOperation is called, AjaxSwing updates the
 * web content and shows the fields with correct values. Those methods do nothing, if not in AjaxSwing.
 */
AjaxSwingManager.beginOperation();
SwingUtilities.invokeLater(new Runnable(){
public void run() {
DisplaySyncManager.synchronizeGUI();
AjaxSwingManager.endOperation();
    }
});
}

This fix worked for 2.4.2 but stopped working in 2.5.0 Beta (just verified to be sure).
Have there been any changes to the way beginOperation() and endOperation() work?
: Re: beginOperation and endOperation in 2.5.0 Beta
: Support Team July 01, 2009, 12:04:35 AM
There hasn't been any changes to beginOperation/endOperation. The only relevant changes are with thread context class loader, but that shouldn't have effect. I've tested beginOperation/endOperation on our demos and it works. Can you please attach the log file?

And when you say it stopped working, what exactly is happening? Does AjaxSwing start rendering before endOperation() is called, so your updates are not picked up?
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 01, 2009, 04:30:13 AM
It is rendering before endOperation, thats why the fields that get filled by DisplaySyncManager.synchronizeGUI() don't show the values.
Atleast thats my guess. ^^

I've attached both the log file of 2.4.2 and the one of 2.5.0 for comparison.

The moment when the effect occurs is the last dual beginOperation/endOperation block.
I also added a trace message when DisplaySyncManager.synchronizeGUI() is called.

I tried removing the inner beginOperation/endOperation so only the second one actually runs, but that did not help.
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 01, 2009, 04:30:51 AM
eh, files attached in this post ^^
: Re: beginOperation and endOperation in 2.5.0 Beta
: Support Team July 01, 2009, 08:49:24 AM
In the log file it is very clear that rendering of windows occurs after the call to endOperation(), so it appears that AjaxSwing is working correctly. Be advised that begin/end operation are not cumulative, so the first call to endOperation() completes the entire operation. I've created an enhancement request on this, but again, from the log it doesn't seem to be an issue.

So we may be dealing with a different bug. What happens if you refresh the browser - do you see updated values?

What components specifically do not get updated correctly?

Is there multithreading inside synchronizeGUI()? What does it do?

There were some speed optimizations on rendering internal frames, menus and tables. Is your trace level set to 10?
I looked thru the log files from 2.4.2 and 2.50 and they actually appear to be almost identical.
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 01, 2009, 10:12:32 AM
In the log file it is very clear that rendering of windows occurs after the call to endOperation(), so it appears that AjaxSwing is working correctly. Be advised that begin/end operation are not cumulative, so the first call to endOperation() completes the entire operation. I've created an enhancement request on this, but again, from the log it doesn't seem to be an issue.
This was no issue in 2.4.2 and I also tested removing the inner begin/end block with no effect.

So we may be dealing with a different bug. What happens if you refresh the browser - do you see updated values?
The values stay empty.

What components specifically do not get updated correctly?
All components are empty.

Is there multithreading inside synchronizeGUI()? What does it do?
There is no Multithreading in it, it just puts the values from the model into the textfields.

There were some speed optimizations on rendering internal frames, menus and tables. Is your trace level set to 10?
I looked thru the log files from 2.4.2 and 2.50 and they actually appear to be almost identical.
Last log files were with trace level 9. I've set trace level to 10, removed the inner begin/end and attached new log files.
: Re: beginOperation and endOperation in 2.5.0 Beta
: Support Team July 01, 2009, 06:39:40 PM
There are some minor differences in the logs but nothing that would explain why the values are not showing up correctly.

First, if after refreshing the page you are still not seeing correct values in the components, this suggests that the issue is not with multithreading/synchronization, but rather with something else.

Can you verify that the values are actually set to the controls? Maybe you can call a get() right after set() to double check that the value has been set. It's hard to provide meaningful explanation without seeing your code and being able reproduce the problem.

Is there some other code that would reset the controls?

Which components are failing (class name)?

From the log files it seems that 3 controls are picked up for AJAX update - JLabel, JPanel and SelectionArea. Are these the controls you are setting values to?

If non of this helps, we may have to issue a patch for you to try with some of the changes reverted. Which JDK version are you using?
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 02, 2009, 05:03:22 AM
I would like to try the patch. As I said, the code works fine with Swing and AjaxSwing 2.4.2.

I am using JDK 1.5.0_12.

I've attached screenshots that show the difference. As you can see, almost all fields get changed some way but AjaxSwing 250 does not pick up those changes.
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 02, 2009, 05:19:58 AM
Well, I even tried delaying the endOperation for 1 sec. It is taking effect in the GUI.
But AjaxSwing 2.5.0 still does not show it correctly...

:
public void synchronizeGUI(){
    AjaxSwingManager.beginOperation();
    SwingUtilities.invokeLater(new Thread(){
public void run() {
DisplaySyncManager.synchronizeGUI();
    }
    });
   
    if (AjaxSwingManager.isAjaxSwingRunning()) {
    new Thread(){
    @Override
    public void run() {
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ClientAgent.getCurrentInstance().setUpdateBrowser(true); //From DemoFrame.java
AjaxSwingManager.endOperation();
    }
    }.start();
    }
    }

Well, im still seaching for other possible reasons.
: Re: beginOperation and endOperation in 2.5.0 Beta
: Support Team July 02, 2009, 08:44:16 AM
Can you email your source file(s) to support@creamtec.com?  There must be something about this dialog that's different from others, which is what probably makes it break.

: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 02, 2009, 08:49:07 AM
It's not that easy. This is not a frame but a framework that creates frames and does some other stuff. So I can't just send you the code. ^^
I'll keep on trying to isolate the problem but I didn't have much luck as of now.

As long as this problem is not resolved we will not be able to upgrade to 2.5.0.

Different about the dialog is that it is tabbed. Normal frames work fine.
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 02, 2009, 09:16:10 AM
I'm starting from scratch again with this bug, removing the ajaxswing fix and trying to change other stuff.
It seems this workaround was just a dirty hack...

Thank you for your help, I will tell more when I know more.
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 03, 2009, 04:15:55 AM
Ok, I've created a sample that shows the current variation of the problem.
The sample code sets the text of components during tab change.

Relevant for the execution is isShowing.
Under Swing it works fine. In AjaxSwing 2.4.2 and 2.5.0 the second tab always keeps its content empty.

My current implementation of the new fix is the same as in the sample. See attachment.

The trace output shows that only when I resize the window, I get the showing event and also somehow both textfields are showing.
Though I need a window update on tab change and the isShowing behaviour of Swing. :D
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 03, 2009, 10:33:00 AM
I just rechecked.
With the sample I posted the behaviour is the same in 2.5.0 and 2.4.2.
But when trying our framework code, the initial tab stays empty until a postback is done in 2.5.0 (so no real change from the initial problem).
So after clicking a button the fields get their content.

Though the implementation of the sample shows the behaviour of the framework simplified.
: Re: beginOperation and endOperation in 2.5.0 Beta
: Support Team July 06, 2009, 11:19:18 PM
Thank you for your post. Your TabTest has helped us to identify and fix the problem, which we treated as a bug in AjaxSwing. The root problem was that you were changing the label text in ComponentEvent listener. That event was not firing at the right time in AjaxSwing, it was firing during rending so the changes to the component were not picked up.

We've changed AjaxSwing to fire those events during update phase, and your TabTest works now. I'll post an update when we release Beta2, and once you get it your code should work. You shouldn't even have to use beginOperation/endOperation.
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 07, 2009, 03:16:48 AM
thanks :)
: Re: beginOperation and endOperation in 2.5.0 Beta
: Support Team July 12, 2009, 12:19:47 PM
We have released AjaxSwing 2.5.0 Beta2, which contains fixes for this issue and all problems you have reported on JDesktopPane rendering. Please download and verify that the fixes work for you.
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 13, 2009, 10:39:07 AM
Ok, first I occasionally get the following Exception with Beta2 (not limited to one specific application, also happens on resize sometimes):

:
2009/07/13 14:32:09:846 : [com.creamtec.ajaxswing.ClientAgentImpl$ClientAgentDelegate] Failed with exception
java.lang.ArrayIndexOutOfBoundsException: 6
at com.creamtec.ajaxswing.gui.html.DefaultJComponentUpdater.updateWindow(DefaultJComponentUpdater.java:542)
at com.creamtec.ajaxswing.gui.html.DefaultJComponentUpdater.updateComponent(DefaultJComponentUpdater.java:173)
at com.creamtec.ajaxswing.gui.ComponentProcessor.processComponent(ComponentProcessor.java:70)
at com.creamtec.core.awt.ContainerIterator.processComponent(ContainerIterator.java:82)
at com.creamtec.core.awt.ContainerIterator.iterate(ContainerIterator.java:62)
at com.creamtec.ajaxswing.gui.WindowUpdater.updateComponentTreeData(WindowUpdater.java:433)
at com.creamtec.ajaxswing.gui.WindowUpdater.updateComponents(WindowUpdater.java:225)
at com.creamtec.ajaxswing.gui.WindowUpdater.emulateRequest(WindowUpdater.java:185)
at com.creamtec.ajaxswing.core.AjaxSwingThread$1.run(AjaxSwingThread.java:193)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
java.lang.ArrayIndexOutOfBoundsException: 6
at com.creamtec.ajaxswing.gui.html.DefaultJComponentUpdater.updateWindow(DefaultJComponentUpdater.java:542)
at com.creamtec.ajaxswing.gui.html.DefaultJComponentUpdater.updateComponent(DefaultJComponentUpdater.java:173)
at com.creamtec.ajaxswing.gui.ComponentProcessor.processComponent(ComponentProcessor.java:70)
at com.creamtec.core.awt.ContainerIterator.processComponent(ContainerIterator.java:82)
at com.creamtec.core.awt.ContainerIterator.iterate(ContainerIterator.java:62)
at com.creamtec.ajaxswing.gui.WindowUpdater.updateComponentTreeData(WindowUpdater.java:433)
at com.creamtec.ajaxswing.gui.WindowUpdater.updateComponents(WindowUpdater.java:225)
at com.creamtec.ajaxswing.gui.WindowUpdater.emulateRequest(WindowUpdater.java:185)
at com.creamtec.ajaxswing.core.AjaxSwingThread$1.run(AjaxSwingThread.java:193)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Second, TabTest still does not work correctly because of isShowing giving wrong results. Try running the Sample Code and see in the log file that the isShowing results are always the same for both fields. Testing this behaviour in our framework does not work because of the above exception occuring quite early before being able to test.

Third, DesktopTest does not show the activated/deactivated title area text. Moving the window outside to left is also not fixed. Resizing the internalframes causes the above exception. The InternalFrameListener also still does not work.

Seems like Beta2 just made it worse. ^^

The forum doesn't let me upload attachments because it says the upload folder is full...
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 13, 2009, 10:51:04 AM
Forgot to mention: JComboBoxes still don't work in JInternalFrames.
: Re: beginOperation and endOperation in 2.5.0 Beta
: Support Team July 13, 2009, 11:22:06 PM
It's quite clear that you have a stale browser cache, or outdated ajaxswing.js file. Please clear the cache completely and then try again. I've just retested all your sample applications and they work. There are two minor issues:

- Internal frame titles do not seem to change
- The window gets packed to small in TabTest in Ajax mode

But all the issues you have reported are fixed, and as long as you are running with the latest ajaxswing.js you should see it working.
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 14, 2009, 02:59:23 AM
ok im testing again :)
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 14, 2009, 07:13:24 AM
Ok, good work. My bad with the cache, sorry. ^^

Though I have two things that still need to be adressed:

I've attached new samples.

1. We need a postback when a tab is changed.
TabTest has been extended with a button on the second tab that gets disabled on the showing event.
This button should normally be directly disabled and the textfield should be filled with "zwei".
On the button click, a postback is done which also allows the showing event to be processed.
and thus the textfield gets filled and the button gets disabled.
In TabTest, the text field somehow stays empty on postback. In our framework a postback works fine. So for now this fact is not really important.
What's important is, that the postback just occurs on tab change so that the button directly gets disabled.

2. We need a postback when the active window changes in a DesktopPane.
In our framework we use a taskbar with the desktoppane to allow better navigation.
DesktopTest includes a working sample of that. It shows that the taskbar is async with the active window when run in ajaxswing.

If you maybe don't want to include these additional postbacks because of reduced server load, is there a way to use the same solution as with http://creamtec.com/forums/index.php?topic=201.0 ? That would be fine aswell.
: Re: beginOperation and endOperation in 2.5.0 Beta
: Support Team July 15, 2009, 12:32:12 AM
> 1. We need a postback when a tab is changed.

Use tabbedPane.putClientProperty("ajaxswing.dynamicEventsEnabled", Boolean.TRUE) or add a change listener to the tabbed pane or the model.

> We need a postback when the active window changes in a DesktopPane.

Currently there is no support for this. You can post an enhancement request and we'll add that feature.

> If you maybe don't want to include these additional postbacks because of reduced server load, is there a way to use the same solution...

Doing more things on the client is a good idea. But the post you are mentioning actually submits to the server when the focus is lost. Depending on what actually needs to be done you can do it all the browser using JavaScript, and then add AJS_onSubmit function to your HTML element. AjaxSwing will call that function when submitting page data to the server, and then on the server you can update Swing components state to match the browser state.

That's the general idea - it's hard to recommend a more specific approach without knowing your requirements. Plus you guys need to get the license for that level of tech support :-)
 
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 15, 2009, 05:00:18 AM
I see, I should have retested TabTest in AjaxSwing before submitting it with the changelistener. ^^
Though now atleast you told me of the property to set so we don't actually have to add a dummy changelistener. Thanks.

I am gonna ask our purchase department again if they haven't forgotten about the license. :D
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 15, 2009, 06:01:08 AM
Ok, tested it. The sample works flawlessly.

But with our framework code we again have the problem that with AjaxSwing 2.5.0 the first Tab stays empty.
After a Postback via button, focuslost of a validator or tab switch to the second tab and back to the first, the first tab is filled correctly.

So with this problem we are a bit further down the road now. Though I don't have time to work on this currently. I will update the topic after I'm done with my other tasks.
: Re: beginOperation and endOperation in 2.5.0 Beta
: Support Team July 15, 2009, 09:00:55 AM
If you can make the problem reproducable with your TabTest example we'll be able to fix it or suggest a workaround.
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 17, 2009, 04:35:06 AM
Ok, a simple edit made the effect reproducable.
I removed the invokeLater and the beginOperation/endOperation.
I don't know if this is the correct reason why this does not work in our framework.
Though on the code part where I used invokeLater and beinOperation/endOperation in the framework it did not help for 2.5.0.
I could dig a bit further into the code and find out if there is some better place to implement this, but not atm.
: Re: beginOperation and endOperation in 2.5.0 Beta
: Support Team July 17, 2009, 06:01:35 PM
I have tried your updated TabTest and it seems to be working correctly. The screen comes up with the text field pre-filled for the first tab and switching updates everything correctly. Can you double check and let us know exactly what does not work.
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 20, 2009, 03:26:22 AM
Ok, I just got the clue that it might be the java version. :D
And ... in fact ... it was the java version. :D
I run 1.5.0 and did not enable that version in ajaxswing. After running the enable script for it, everything worx fine. Thank you. :)
: Re: beginOperation and endOperation in 2.5.0 Beta
: Support Team July 20, 2009, 08:35:46 AM
Wow, that's quite strange. Especially since starting from version 2.5 AjaxSwing is automatically running compatibility script whenever it detects that JDK version has changed. Are you using AjaxSwing/bin/startServer.bat to start the server?

: Re: beginOperation and endOperation in 2.5.0 Beta
: subes July 20, 2009, 09:03:44 AM
hmm, no, I've always been using asConsole.bat ^^
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes August 31, 2009, 09:39:47 AM
Really interesting...

The problem was gone for a while but is now occuring again. The fix with running enableJdk15.bat does not work.
It's really interesting, after trying several times by starting tomcat, launching the sample, restarting tomcat, launching the sample again, ...

The problem does not always occur...
I have used AjaxSwing 2.5.0 Beta2 cleanly downloaded today and Java 1.5.0_16.

This has been reported on several development computers and in our integration environment.

*EDIT*
I have cleared and deactivated the browser cache while testing this.
: Re: beginOperation and endOperation in 2.5.0 Beta
: Support Team September 08, 2009, 04:12:58 PM
I have just tried with AjaxSwing 3.0 beta and I can't reproduce the problem. We are releasing it tomorrow so it would be good for you to try with the latest codebase and let us know if you are still seeing the issue.
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes September 10, 2009, 11:19:31 AM
Ok, this now works in the sample but again not in our framework ^^

Seems like im back to step one and trying to reproduce this in a sample.
: Re: beginOperation and endOperation in 2.5.0 Beta
: Support Team September 10, 2009, 02:36:14 PM
It's not clear from the images what the problem is, but I assume it is the same issue as earlier - switching tabs does not correctly update the values in the text fields.

If you can post a test class that reproduces the issue that will be great. Otherwise we'll end up spending lots of hours trying to figure it out and we still wouldn't know if we fixed it. As of now all our test applications work correctly, but I'm sure there's something special about yours that breaks our code.
: Re: beginOperation and endOperation in 2.5.0 Beta
: subes September 11, 2009, 09:11:56 AM
No, switching tab solves the problem. :)

The postback on tab switch was a fix so that other tabs get filled correctly when switching to them. So this fixed another problem we had with the same feature.

The other problem we still have is, that when loading the window, initially the content stays empty.
To solve this as a user, you have to click a button or switch to a different tab and back to the initial tab again (thus generate a postback in some way). Somehow this problem was not present in AjaxSwing 2.4.2, but due to the fix for tab switch we upgraded to AjaxSwing 2.5.0 Beta2. :)

So AjaxSwing 2.4.2 has fine initial tab, but non working tab switches.
AjaxSwing 2.5.0 and up have empty initial tab, but properly working tab switches.
: Re: beginOperation and endOperation in 2.5.0 Beta
: Support Team September 11, 2009, 10:25:51 AM
Thank you for clarification. If you can post a sample that reproduces the problem we'll definitely find a fix for it.
: Re: beginOperation and endOperation in 2.5.0 Beta
: Dev Team October 01, 2009, 08:50:11 AM
Can't reproduce initial tab problem with AjaxSwing 3.0Beta2, also there was few problems with tabs and empty field fixed in 3.0Beta2, can you please send code that reproduce this issue, I have few ideas that might cause this problem, but can't check them with my application.
: Re: beginOperation and endOperation in 2.5.0 Beta
: Support Team December 14, 2009, 11:26:01 AM
Can you please explain in more detail the problem you are having?

Are you using some AjaxSwing APIs to turn on shadows?

Screenshots would help, but it seems that you are not even talking about AjaxSwing here.