When is it acceptable to use a FRAMESET - java

In my Java EE application page, I have header.jsp, a side menu.jsp, a body.jsp and footer.jsp. The side menu contains the jQuery dynatree plugin. When a user clicks a menu item from the tree, the body should be changed with the appropriate page (also a .jsp). I am using tiles framework, where I am importing all js code in layout.jsp page. I want to achieve an effect replicating a frameset, but without actually using a frameset. I think framesets are difficult to be managed and take time to load.
Can anyone suggest how I can approach this problem? If I use AJAX to fetch each page when dynatree node is activated, then I have to manually update the page. If I use an IFRAME in body.jsp, then I have to reimport all plugin js code as the frame will not be able to access js functionality on the main page.
I want efficient html page management.

Since you are using jQuery, you should be able to use AJAX in combination with the live method of applying events (see the docs or here). This method is called "event delegation", and even though jQuery will do it for you like magic, you should understand what is happening. Depending on what version of jQuery you are using, you might use delegate instead of live - essentially the same thing.
Framesets are actually deprecated in HTML5 -- you should avoid using them because soon they will not be supported at all in newer user agents. See http://www.useit.com/alertbox/9612.html for a lengthy discussion that should hopefully dissuade you from considering that approach.
The IFRAME approach is a hack. You might be able to make it work, but you're hammering a square peg into a round hole.
Bottom line, if you don't want to directly deep link to inner pages, AJAX is the best and preferred solution. In combination with event delegation, it really is superior to any older or hacky solution. And, be sure to use the idea of "progressive enhancement" -- if someone clicks those links and has javascript turned off, the content should still load. That means you start with regular direct links, then add the fancy stuff on to it for those users that have javascript enabled. Otherwise, you close a percentage of users off from anything past your home page.
When you use AJAX for your navigation, you still need to plan for a user that doesn't understand the difference between when they click a link on your site or any other site. They'll use the browser's "back" button and end up back at Google instead of on the last page! That's because their navigation through your site does not look like unique pages to their browser. There are tools in newer browsers to deal with this, but the details are a little beyond the scope of this answer. Check out this article on MDN for more info on manipulating the browser history.
Documentation
jQuery's live - http://api.jquery.com/live/
jQuery's delegate - http://api.jquery.com/delegate/
David Walsh on event delegation - http://davidwalsh.name/event-delegate
Jakob Nielsen on Framesets - http://www.useit.com/alertbox/9612.html
MDN on Browser History Modification - https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history
jQuery for Designers blog with a sample use-case for delegate - http://jqueryfordesigners.com/simple-use-of-event-delegation/
Wikipedia article about progressive enhancement - http://en.wikipedia.org/wiki/Progressive_enhancement

Related

how to extract HTML data from a webpage which scrolls down for a fixed number of times?

I want to extract HTML data from a website using JAVA. The problem is the webpage keeps scrolling down once the user reaches the bottom of the page. Number of times it scrolls down is fixed. My JAVA code can extract only for the 1st part. How do I extract for the remaining scrolls? Is there a way to load the whole page at once with JAVA? ANy help would be appreciated :)
This might be the type of thing that PhantomJS (http://phantomjs.org/) was designed for. It will crawl entire web pages and even execute JavaScript, using a "real" browser in headless mode. I suggest stopping what you're doing with Java and take a look at PhantomJS instead. It could save you a LOT of time. :)
This type of behavior is implemented in the browser, interpreting the user's scrolling actions to load more content via AJAX and dynamically modifying the in-memory DOM in the browser. Consider that your Java runs in a web container on the server, and that web container (i.e. Tomcat, JBoss, etc) provides a huge amount of underlying code so your app doesn't have to worry about the plumbing.
Conceptually, a similar thing occurs at the client, with the DHTML web page running in its own "container" (the browser), which provides a wealth of functionality, from UI to networking, to DOM, etc. If you remove the browser from the equation and replace it with a Java program, you will need to provide the equivalent of the browser in which the DHTML/Javascript can execute.
I believe that HTMLUnit may fill the bill, but have not worked with it personally.

how can I know if the user has left the page in wicket?

I am searching for a way to know when the user leaves the page and has not saved the changes then show wicket's modal(preferable but could be a confirmation box).
Additional info:
the solution should have minimal effects in code, because I have about 30 pages that will have the behavior, actually all my web pages extends from one called LayoutPage, something similar to this
I tried with pure JavaScript solution like in this question, but the application send a lot of data via AJAX requests, so I couldn't determine a nice way to know if the data has been sent to the server
Ihen I start to look in the source code of the Form.class of Wicket. It has a nice method called isSubmitted(); I could use it if I was able to know from wicket if the user is about to quit the page.
I don't want to write a validation for each page in the system.
Simply generate your browser onbeforeunload using https://cwiki.apache.org/WICKET/calling-wicket-from-javascript.html. In the callback you can then check the state of your form or page.

Approaches to Creating Screen Capture Functionality on a Web Page

I have read the various posts here on SO regarding screen capturing, but none seem to be answering my situation.
On our website (inside a web page), essentially here is what I would like to be able to do.
User clicks on a 'capture region of screen' button
They get some sort of draggable/sizable box they can use to define the area to capture
the captured area gets converted into a (preferrably) .png
image is uploaded (or at least made available to upload - maybe saved somewhere)
I realize this is not doable with javascript alone. So, I am open to a Java or Flash solution, and/or even a commercial solution (a drop-in java applet that I can add to our site).
So, is something like this available, or any other ideas on how I might approach this?
Thanks.
Check out PhantomJS. http://www.phantomjs.org/
Actually it will re-render page on your server stack and you can save it as a png. Not same as your desired workflow, but definitely worth checking out.

What technologies to use for web app hosting web page and logic to interrogate web page

I would like to create a web application that holds a web site in the right half of the screen, and some some widgets with logic in the left half.
For example, the user might specify that they want www.somesite.com to be analysed, so that site will show in the right half of my web page. I then want the user to be able to hit something like a 'record' button on the LHS, and that will then record what they do on the RHS (in the www.somesite.com) until the 'record' button is pressed again.
My first thought was an IFrame holding the web site (www.somesite.com in this case) and an applet in the LHS. The user hits record, the applet gets hold of the DOM for the web page and adds listeners on every textbox/button etc. I am not sure how the applet would get hold of the DOM (netscape.javascript.JSObject looked promising), but instead of fighting that, I thought I would ask if there is more appropriate technology other than IFrame/Applet? Any solution would have to be Java based. The above explanation of what the web app does is a vast over-simplification; I am only after help on the technologies that could be used to achieve something like it and not on the web app itself, which is really just for illustration purposes.
Many Thanks,
Paul
Javascript/Java from your site will -not- be able to access properties of the DOM from another domain, whether in an iFrame or otherwise. This is a basic security principle that browsers implement, and rightly so.
See this Wikipedia page: http://en.wikipedia.org/wiki/Same_origin_policy

Script to take web survey for me

I had to take a surveymonkey survey today, and the format was as follows: a question was asked, then after hitting the next button, the answer was displayed as "Answer: _" along with an explanation. For kicks, I'd like to make a program that could take this survey, answering any letter, then going to the next page and reading the answer, then going back and changing the answer to the correct one, then going 2 pages ahead and repeating.
I am familiar with Java and Python, but I'm not sure how to make them be able to "know" where the button is, and how to "read" text without unnecessary image recognition.
This is just a fun project, nothing serious, but I would appreciate any ideas to get me started.
Assuming that the text was just that (text rather than images), there are a few useful tools for you:
.Net WebControl - I've scripted this before from .Net. It has the advantage of making all of the JS on the page still work. I know this isn't Java, but it is surprisingly easy to work with for this kind of task.
Selenium - It is primarily a web testing framework, but it would be easy to script it from Java to auto-submit forms.
TagSoup for Java - If the pages do not have significant javascript code that needs to run, there are many HTML parsers for Java that could potentially be used to develop a scraper.
Would it be unrealistic to make it post to the survey monkey pages? You could then do some regex's to pull "answer:__" out and look for that pattern in the original page. It would definitely be easier than trying to click things in a browser, etc. Basically, write a java app or python for that matter that does http posts to the survey pages in order and uses regex's to find the next page, etc and then use a stack to keep track of the history.
Edit if this isn't clear, let me know, I'll clarify
Edit 2: I completely forgot about HTMLUnit, my bad. It is a testing framework like suggested by jsight but specifically for Java and functions very similarly to JUnit, however, because it is designed for testing web applications, it can be used to automate interactions with other sites
You can do it using a simple image search. First screenshot the a unique part of the button and save it. This will be used as the relative reference on where you click the mouse. Then during the actual running of the application, have a screenshot of the entire screen and find a part matching the previously saved image and then let the mouse click on the appropriate location based on the button image location.

Categories