Forums Register Login

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

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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).

 
+Pie Number of slices to send: Send
Sounds like you need to read a DOM tutorial or a whole book about XML with Java that includes several DOM chapters.
I like tacos! And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1357 times.
Similar Threads
sysdate function
assign values to form elements dynamically?
fake path error in jsp
Sort by price and sort by provence
Check file size with Javascript before uploading
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:39:38.