You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by 남기혁 <ge...@secsm.org> on 2001/02/21 15:39:16 UTC

addEventListener

I have a problem in Event handler registration.

I want to add an event handler to some node, say, "someNode" using Java
Binding.

but, after parsing, the return value of parser.getDocument() (parser is an
instance of DOMParser),

say, document, is a Document's instance.

In addition the return value of
"document.getElementsByTagName("head").item(0)"

is an instance of Node, not of NodeImpl where EventTarget interface is
implemented.

Therefore the addEventListener method is not found or can't be accessed

So I got an error.

The following is the code that I used.

I'm xerces newbie so I'm not sure that is correct or not.

//
Node testTarget = document.getElementsByTagName("head").item(0);
EventListener TestEventListener = new EventListenerImpl();
testTarget.addEventListener( "mutation", TestEventListener, false );
//

And I got an error like the following

//
ScriptingTest.java:108: cannot resolve symbol
symbol  : method addEventListener
(java.lang.String,org.w3c.dom.events.EventListener,boolean)
location: interface org.w3c.dom.Node
testTarget.addEventListener( "mutation", TestEventListener, false );
          ^
1 error
//

Please help me, I've never been answered all the question that I posted this
mailing list. :-(

-- Nam



Re: addEventListener

Posted by Arnaud Le Hors <le...@us.ibm.com>.
"j80m " wrote:
> 
> But, I found something strange.
> 
> In DOM2 Events, MutationEvent interface, initMutationEvent(~)
> 
> public void initMutationEvent(   String typeArg,
>                                                 boolean canBubbleArg,
>                                                 boolean cancelableArg,
>                                                 Node relatedNodeArg,
>                                                 String prevValueArg,
>                                                 String newValueArg,
>                                                 String attrNameArg);

Where did you get that from? This is out of date. This was changed
before the DOM Level 2 spec becomes a Recommendation. See
http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-MutationEvent

> But In Xerces (org.apache.xerces.dom.events.MutationEventImpl),
> 
> public void initMutationEvent(   String typeArg,
>                                                 boolean canBubbleArg,
>                                                 boolean cancelableArg,
>                                                 Node relatedNodeArg,
>                                                 String prevValueArg,
>                                                 String newValueArg,
>                                                 String attrNameArg
>                                     *****  short attrChangeArg);
> 
> I'm just curious why attrChangeArg parameter is added.

That's in line with the latest spec.
-- 
Arnaud  Le Hors - IBM Cupertino, XML Strategy Group

Re: addEventListener

Posted by 남기혁 <ge...@secsm.org>.
Thanks, Alan & Stephane.

I'm a bit surprised at such an quick responses.

Well, I should've introduced myself as a Java newbie.

I fixed my code like the following, and got no compile errors.

NodeImpl testTarget =
(NodeImpl)document.getElementsByTagName("head").item(0);

But, I found something strange.

In DOM2 Events, MutationEvent interface, initMutationEvent(~)

public void initMutationEvent(   String typeArg,
                                                boolean canBubbleArg,
                                                boolean cancelableArg,
                                                Node relatedNodeArg,
                                                String prevValueArg,
                                                String newValueArg,
                                                String attrNameArg);

But In Xerces (org.apache.xerces.dom.events.MutationEventImpl),

public void initMutationEvent(   String typeArg,
                                                boolean canBubbleArg,
                                                boolean cancelableArg,
                                                Node relatedNodeArg,
                                                String prevValueArg,
                                                String newValueArg,
                                                String attrNameArg
                                    *****  short attrChangeArg);

I'm just curious why attrChangeArg parameter is added.

Thanks in advance.

----- Original Message -----
From: "Alan Martin" <vo...@banksian.co.uk>
To: <xe...@xml.apache.org>
Sent: Thursday, February 22, 2001 12:16 AM
Subject: Re: addEventListener


>
> > I'm xerces newbie so I'm not sure that is correct or not.
>
> So am I, but I know Java.  ^_^
>
> > //
> > Node testTarget = document.getElementsByTagName("head").item(0);
> > EventListener TestEventListener = new EventListenerImpl();
> > testTarget.addEventListener( "mutation", TestEventListener, false );
> > //
>
> How about casting to (NodeImpl),  addEventListener isn't defined in the
Node
> interface,  perhaps its a bug,  but thats not your problem. :)
>
> > Please help me, I've never been answered all the question that I posted
> this
> > mailing list. :-(
>
> Yeah but its free, so quit whining. ;)
>
> Voxol
> -Use the source Luke
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org



Re: addEventListener

Posted by Arnaud Le Hors <le...@us.ibm.com>.
Alan Martin wrote:
> 
> > I'm xerces newbie so I'm not sure that is correct or not.
> 
> So am I, but I know Java.  ^_^
> 
> > //
> > Node testTarget = document.getElementsByTagName("head").item(0);
> > EventListener TestEventListener = new EventListenerImpl();
> > testTarget.addEventListener( "mutation", TestEventListener, false );
> > //
> 
> How about casting to (NodeImpl),  addEventListener isn't defined in the Node
> interface,  perhaps its a bug,  but thats not your problem. :)

There is no bug. You need to cast to EventTarget. See
org.w3c.dom.events.EventTarget.
-- 
Arnaud  Le Hors - IBM Cupertino, XML Strategy Group

Re: addEventListener

Posted by Alan Martin <vo...@banksian.co.uk>.
> I'm xerces newbie so I'm not sure that is correct or not.

So am I, but I know Java.  ^_^

> //
> Node testTarget = document.getElementsByTagName("head").item(0);
> EventListener TestEventListener = new EventListenerImpl();
> testTarget.addEventListener( "mutation", TestEventListener, false );
> //

How about casting to (NodeImpl),  addEventListener isn't defined in the Node
interface,  perhaps its a bug,  but thats not your problem. :)

> Please help me, I've never been answered all the question that I posted
this
> mailing list. :-(

Yeah but its free, so quit whining. ;)

Voxol
-Use the source Luke