loading java applet on DOM load - java

I searched for it a lot but probably I am searching wrong strings. A Java applet is feeding live bits into my pages, java applet accesses the input fields on my page and places the information
<input type="hidden" id="F1" value="Nothing Yet">
and then it calls a javascript functionon the page say LivePicker() and then it simply picks up a value
var ClockVal = document.getElementById("F1").value;
document.getElementById("ICSCLOCK").innerHTML = ClockVal;
The problem I am facing is, this works fine but sometimes in firebug console it give errors like LivePicker is not defined, while LivePicker would be working perfectly fine on the page while sometimes it will give F1 is not defined, while my clock would be working fine. All of these errors appear at page load.
Java applet places the data sequentially, it first place the data and then calls the js function to process it. That works perfectly fine on test pages with minimum HTML and JS but when I integrate it to my application, which uses a lot of components from YUI and a lot of my own JS code (which is now minified obviously), it give these errors. One thing I would like to add, before minification, these errors were a lot likely but after minification of JS and CSS, the page load time is reduced to half and the appearence of these errors are reduced to half as well.
I am suspecting this is due to, on page load, applet tries to manipulate the DOM which is not ready yet. Is there anything, which could stop the applet to wait until the DOM is fully loaded? I tried window.onload and onDOMReady function of YUI, they seem to make no effect at all.
Can any one help please?

you could try using setTimeout to delay execution
https://developer.mozilla.org/en/DOM/window.setTimeout
or the jQuery library could also help out with the ready event on the document object
http://docs.jquery.com/Events/ready#fn

The browser should delay executing the window.onload code until after
the DOM tree is created and after all other external resources are fully loaded and the page is displayed in the browser.
The window.onload should work. Your applet must be running before the onload event.
As a test, can you do the following and see if it changes anything:
create a hidden "set" field in the page with value "false";
on window.onload set the value for the "set" field to "true";
in your applet check the "set" field;
only start doing things in your applet if the "set" field is defined and has a value of "true";
One other thing, don't do a busy waiting in your applet to test for the "set" field. Your applet should take no action if the field is undefined or false. You can reactivate it on window.onload if needed.

This problem was resolved using dpb suggestions in slightly different way. This blog post I wrote should explain every bit to those who are facing similar problem.
Controlling Java applet from Javascript especially if you make round-trips to the web page from applet

Related

Using XHTML, Java Server Faces, PrimeFaces, Java, and JQuery when adding new elements to XHTML page nothing is generated in browser

Error is this
"UI Layout Initialization Error
The center-pane element does not exist.
The center-pane is a required element."
Nothing is displayed on screen when I add any new elements to the XHTML Page.
Basically I have been learning the in's and out's of an Open Source Application.
We are trying to determine the feasibility of using this technology in future projects, so we undertook the task of dissecting the Open Source Project.
So, we decided we would break the technology to see how we could then, fix it.
We were able to break it by adding a simple item. We added a hidden Input to the XHTML Main page.
The pages are quite complex with Ajax, Servlets, JSP pages, XHTML, etc.. so the interaction of those things has made it a bear to figure out why it was not working when adding new elements...
The element I added is this
<h:inputHidden id="tabcnt" value="#{repositoryHandler.iTabCnt}" />
If you see in this code the part #{repositoryHandler.iTabCnt}
That means it is a server side variable that we are accessing in our XHTML
Page.
The problem ended up being that the Variable which was a member of -
public class RepositoryHandler, did not have getters and setters..
After I fixed that issue, then Bob's your Uncle!! problem solved!!

Selenium Webdriver.load.strategy unstable

I'm having problems loading my page with webdriver. My current (problematic) solution involves using the unstable load with firefox, but I'm open to other solutions.
The Core Problem
The root of all my problems comes from the fact my page will never fully load when I call it normally with webdriver, and thus will never preform the 2nd step, it's just always loading. It loads fine when you just go to the site with a normal browser. I've tried out a few work arounds that work intermittently, including opening the driver to google, and then going to the page which sometimes makes it load, and with
IJavaScriptExecutor js = (IJavaScriptExecutor)Driver;
js.ExecuteScript("return window.stop");
as suggested by this question, which sometimes makes it continue without loading. But neither of those work consistently at all (probably <50% of the time)
The best I've got so far is using the unstable load strategy. However that has its own different problems, all of which only happen sometimes.
1) Sometimes it doesn't wait for the page to load at all, and I get an "Unable to locate element:" exception within milliseconds of loading the page, despite the fact that I have a wait set up:
new WebDriverWait(cdriver, 30).until(ExpectedConditions.visibilityOf(cdriver.findElement(By.id(myId))));
Thread.sleep(3000); solves that problem, but I've read that is a sloppy way to do things.
2) If I get passed that step, my test should click one link, then click another and continue on with the test. However, it often gets stuck after that first click. So if my code is like this:
Thread.sleep(3000);
element1.click();
System.out.println("clicked!");
element2.click();
The first click (which doesn't load a new page, by the way, just a pop up on the same page) will work, but then the system will never print out "clicked!", it's stuck in the same way would be loading the page initially (without the unstable load thing). If/when it makes it over that hurdle, I think the rest of the test is fine.
Any ideas 1) why it works sometimes but not others. 2) how to fix it 3) how to just get my page to load in the first place
Thank you!
Try the following approach:
Don't wait for visibility of element on the page - in your case By.id(myId).
The element can become visible much earlier than the page is fully loaded, before all java scripts are loaded and fired etc.
Wait for some element on the page to be clickeable instead. For example you can wait until link becomes clickeable in this way:
By locatorOfLink1 = By.xpath(....); // By.id, By.name, By.linkText etc.
wait.until(ExpectedConditions.elementToBeClickable(locatorOfLink1));
If the above will not help for problem #2 (the webdriver gets stuck after the click), then send ENTER key to the link instead of the click:
element1.sendKeys(Keys.ENTER);

How can i get page URL in single-approver-definition.xml in Kaleo workflow in Liferay?

How can i get the page URL in single-approver-definition.xml in the e-mail template that is used to send an e-mail to the content creator once the reviewer approves or rejects the submission. The existing xml is as follows:
<template>
Your submission has been reviewed and the reviewer has applied the following:
${taskComments}.
</template>
I tried ${serviceContext.getAttribute("contentURL")} and it didn't work.
I want to be able to do - Your submission for ${pageURL} has been reviewed and the reviewier has applied the following: \n ${taskComments}.\n
Any suggestions will be appreciated.
I don't get what variable exactly you want to process in your notification. As I can only assume, you are using it for Web Contents and all interesting variables are stored in two places.
Workflow context variables - they are available directly. Few examples like:
${taskComments}
${entryType}
${userId}
${userName}
...
ServiceContext variables - they are available using $serviceContext. Few examples:
$serviceContext.getAttributes().get("version")
$serviceContext.getAttributes().get("articleId")
${serviceContext.getPortalURL()}
...
For all interesting variables check this url https://www.liferay.com/web/igor.beslic/blog/-/blogs/workflow-in-action-kaleo-workflow-context-variables Some could change already, however most of them is working fine for current version.
Content changes might be made on a page, they can also be triggered through Control Panel (or the API for that matter). When you're in a workflow, you typically don't have this context any more - if you find it somehow I'd not rely on it to be there. A workflow is unrelated to the UI and pages.
Also, an article might be submitted on one page, where it might be replaced/removed before it's even approved. In that case the link wouldn't help.
What might work is to check the concept behind "Web Content Display Pages" (if your article has them configured and you deal with web content). But the mechanics will vary depending on the actual content type you're dealing with. And content that goes through workflow might not be displayed on any page at all (e.g. when submitted through Control Panel) or on many different pages (either explicitly - Web Content Display - or implicitly - Asset Publisher).
#tomic basically provides pointers to what you have, I'm only reasoning why your initial problem is problematic to solve at best - it's not fully specifiable.

Can page rendering run simultaneously with JavaScript?

I have an overridden GWT DialogBox that has as a widget overridden PagingScrollTable.
I have something like this in my code:
1) DialogBox dialog = new ...
2) dialog.center();
3) Window.alert("Hello");
In IE I would see alert after loading of table’s header but before loading of table’s content (about 1000 rows). But javascript is single-threaded language so how can it be?
May it be a browser issue or issue of my code?
Thanks!
Javascript may be single-threaded, but the browser isn't, and page rendering is not done by the Javascript engine, so there's no conflict that Javascript can be running while the page is rendering.
(in fact, you can add the async attribute on the <script> tag to tell the browser explicitly to do this, although sadly this attribute isn't fully supported in all browsers yet)
Javascript is asynchronous (and it runs inside a thread in the browser so it's not in lock-step with the page loading the way you might think it is. Once the javascript itself is loaded, it need only be triggered by an event to run, or, the fact that it's loaded is enough to run it. '' tag contents are processed by the browser instantly - so if you have code that isn't wrapped in a 'function' that you bind to 'unload' or something similar - it'll just run whenever it shows up in the DOM.

Clear HTTP Session

I am trying to clear everything on my HTML form when I visit it from a hyperlink entry.
Any ideas? My development language is java.
are you using session-scoped data? if so, close your browser and open it again.
I'm not sure the application is, but one way to accomplish this would be to use JavaScript. For example, if it is acceptable to clear the form every time that page is visited you could write a quick function that clears the form when the page is loaded (i.e., using the onload event).
If you only want to clear the form when the page is hit from that link you could add a param to the URL (e.g., clearForm=true) and use JavaScript to pick up the query string and clear the form when that parameter is present.
This is, of course, a purely client-side solution. For a server-side solution it would be helpful to know what framework you are using.

Categories