FormSubmitEvent not being fired?

[nobr]Hi there,

as FormSubmitEvent subclasses HypertextEvent (and there is no "FormSubmitListener") I am expecting HypertextListeners to receive FormSubmitEvents. However the listener in the following Program is never being fired. What am I doing wrong?

import javax.swing.*;

import javax.swing.event.*;

import javax.swing.text.*;

import java.net.*;

import java.awt.event.*;

import java.beans.*;

publicclass Bug{

publicstaticvoid main( String[] args )throws Exception{

System.setProperty("java.awt.Window.locationByPlatform","true" );

new Bug().run();

}

private JEditorPane editor;

publicvoid run()throws Exception{

JFrame f =new JFrame("bug" );

f.setSize( 800, 600 );

editor =new JEditorPane();

editor.setEditable(false);// editable editors never fire hyperlinkUpdates

JScrollPane scroll =new JScrollPane(editor);

scroll.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

f.getContentPane().add(scroll);

editor.addHyperlinkListener(new HyperlinkListener(){

publicvoid hyperlinkUpdate( HyperlinkEvent ev ){

System.err.println( ev.getEventType() +": " + ev.getURL() );

}

});

editor.setPage(new URL( null,"file:bug.html" ) );

f.setVisible(true);

}

}

This is bug.html:

<html>

<body>

<h1>FormSubmitEvents are not being fired</h1>

<form name="some form">

<input size="20" name="arg" value="some text">

<br>

<input type="submit" value="submit button">

</form>

more text

</body>

</html>

I also tried to add the listerner in response to the propertyChangeEvent ("page"), but that does not work either?

I have seen that there are "FormViews". Do I have to add the listener there? But how do I gain access to those views?[/nobr]

[3433 byte] By [HolgerKa] at [2007-10-1 14:04:47]
# 1

[nobr]Hi ,

Your programm is work well.

I just copy your code and execute , I nothing to find out except one that is in the URL constructor my change is.

editor.setPage( new URL( "file://D:/eclipse/dws/FTest/bin/bug.htm" ) );

for checking purpose I add a action for your Bug.html file . it work prefectly. I us jdk1.4.1_01

see the bellow two html file is

Bug.html is

<html>

<body>

<h1>FormSubmitEvents are not being fired</h1>

<form name="some form" action="O2.html">

<input size="20" name="arg" value="some text">

<br>

<input type="submit" value="submit button">

</form>

more text

</body>

</html>

O2.html is

<pre>

Hai

How r u?

What u want?

Is it work?

Ok

Fine

</pre>

[/nobr]

LittleDanya at 2007-7-10 17:24:45 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...
# 2
Have you figured this out? I am beginning to wonder if we must built the listener ourselves. Please post your solution, if you found one.Thanks,Tim
TimNa at 2007-7-10 17:24:45 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...
# 3

Ok. I got it.

JEditorPane htmlPane;

// Obvious code clipped for brevity...

HTMLEditorKit ek = new HTMLEditorKit();

HTMLDocument doc = (HTMLDocument)ek.createDefaultDocument();

// gotta do this or you'll never get the events

ek.setAutoFormSubmission(false);

htmlPane = new JEditorPane();

htmlPane.setEditorKit(ek);

// now we will get the FormSubmitEvent

htmlPane.addHyperlinkListener(new HyperlinkListener()

{

/**

* Called when a hypertext link is updated.

*

* @param e the event responsible for the update

*/

public void hyperlinkUpdate(HyperlinkEvent e)

{

//just to be sure...we may have regular links on the HTML page...

if(e instanceof FormSubmitEvent)

{

FormSubmitEvent evt = (FormSubmitEvent)e;

System.out.println(evt.getData());

}

}

});

I searched for a while on the site but never found this information, however I am sure I have seen it here before. The solution looks too familiar to be guessed...maybe I saw it on another site...?

SOSNs

SickOfScreenNamesa at 2007-7-10 17:24:45 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...