• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

html events to reflect on DOM and to be accessed in JAVA

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
good day, we're having this problem wherein we have an html form and what we want to do is to change the values in the form and be able to reflect it in the DOM of that html. we also want to access this particular DOM in the java side. as of now, we have this mini sample where we are doing this:

---------------------------------------------------------------------
File file = new File("htmlFile.htm");
DocumentBuilder builder;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
Document document = builder.parse( file );
NodeList nodelist = document.getElementsByTagName("INPUT");
final Element element = (Element)nodelist.item(0);
EventTarget RecEvent = (EventTarget)element;
RecEvent.addEventListener("click", new EventHandler(), false);

Button EXTRAbutton = new Button(shell, SWT.PUSH);
EXTRAbutton.addSelectionListener( new SelectionAdapter()
{ public void widgetSelected( SelectionEvent e ) {
System.out.println(element.getAttribute("VALUE")) ;
} } );
-------------------------------------------------------------------------
and the html file is:

<head>

script type = "text/javascript"
function changeOnKlick () {
document.getElementById("10").setAttribute("value", "hello");
}
/script

/head
body
form
INPUT id = "10" TYPE="button" NAME="5" VALUE="click" onKlick="changeOnKlick()" /
/form/body
--------------------------------------------------------------------------
what we want to do is to change the value attribute of the button (id = 10) and at the same time, be able to access that change from our java code (that is the purpose of the EXTRAbutton in the java code) however we only succeed in changing the value of the button in the javascript part but pparently in the java code, we're still accessing the original DOM and the tree was not changed. we need help to do that. thank you very much. any help would be greatly appreciated. thanks.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me see if I can make some sense out of that. You have an HTML page and you load it into a browser. The browser, internally, makes it into a DOM which you can manipulate with Javascript, as in the second part of your example.

Now, you are also parsing this HTML page into another DOM in a Java program which is running somewhere else. And you are wondering why changes to the DOM in the browser don't show up as changes to the other DOM in the Java program? Or were you asking how to simulate the Javascript in the HTML page (which modifies the browser's DOM) by some Java code that does the same modifications to its DOM? It isn't clear to me what you are asking.
 
christine clarin
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Clapham:
Let me see if I can make some sense out of that. You have an HTML page and you load it into a browser. The browser, internally, makes it into a DOM which you can manipulate with Javascript, as in the second part of your example.

>> yes this is exactly what we are doing.

Now, you are also parsing this HTML page into another DOM in a Java program which is running somewhere else. And you are wondering why changes to the DOM in the browser don't show up as changes to the other DOM in the Java program?

>> well, sort of. we were thinking that the same DOM will be accessed in the JAVA program since what we are loading here is the same html file (but seems like it doesn't, right? or does it?)

Or were you asking how to simulate the Javascript in the HTML page (which modifies the browser's DOM) by some Java code that does the same modifications to its DOM?

>> yes this is it exactly! If the first option is not able to do this, we would like to ask on how we can access the html elements and change its value in the DOM (and consequently into an XML file) with java (and also be able to access these same values in the same java program as well).

Actually, to give you a clearer view, this is what we are doing: we have an xml file which we get our values from and use xsl to show the values in an html form shown in a browser within a java swt window. we are successful in doing this but we cant do it the other way around where in we want to change the values in the html form, and then find where this exact element is in the XML we have and change it (like in save).

 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you need to read a DOM tutorial or a whole book about XML with Java that includes several DOM chapters.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic