On Thu, 13 May 1999, Craig R. McClanahan wrote:
> Brad Neuberg wrote:
>
> > -----Original Message-----
> > From: Craig R. McClanahan <[EMAIL PROTECTED]>
> > To: Brad Neuberg <[EMAIL PROTECTED]>; [EMAIL PROTECTED]
> > <[EMAIL PROTECTED]>
> > Date: Wednesday, May 12, 1999 2:00 PM
> > Subject: Re: calling bean-methods...
> >
> > >Brad Neuberg wrote:
> > >
> > >> On Wed, 12 May 1999, Tommy Berglund wrote:
> > >>
> > >> > I've got a problem and it would really help if someone could answer it.
> > >> > The problem is that I want to call a method in my bean when an event is
> > >> > triggered in my .jsp document. The code looks something like this...
> > >> >
> > >> > <USEBEAN name = "bean" type = "beans.bean" lifespan =
> > session></USEBEAN>
> > >>
> > >> This isn't part of the spec, but wouldn't it be nice to be able to mimic
> > >> JavaScript and add something like this to any html tag:
> > >>
> > >> <A HREF="somelink" jsp:onClick="bean.someMethod()">Look mah, a link!</a>
> > >>
> > >> Damn that would be nice.... I think the JavaScript model of generalized
> > >> event handlers (like onClick, onLoad, etc.) is a great model that should
> > >> be generalized to XML (so that you could onSomeEvent anything). Is this
> > >> part of DOM Level 2?
> > >>
> > >
> > >I can think of at least one reason it's not there -- JavaScript event
> > handlers
> > >execute inside your client (usually a web browser), whereas the JSP beans
> > live
> > >inside the server. How would bean.someMethod() get called?
> > >
> > >Craig McClanahan
> > >
> >
> > I meant to use onEvent event handlers on the server side as well. So what
> > would happen is that the server-side onEvent handler would be replaced with
> > appropriate normal html before being sent out to the client - just as is
> > what happens to JSP itself.
>
> OK, in the case you cited as an example:
>
> <A HREF="somelink" jsp:onClick="bean.someMethod(event)">Look mah, a
link!</a>
Here's how you would handle this. On the server side the line right above
would be converted into the following:
<A HREF="somelink"
onClick="sendEvent(event,'bean.someMethod(event)')">Look mah, a link</a>
sendEvent is a javascript function that would be inserted by the JSP
engine:
<SCRIPT>
function sendEvent(event, method_to_call) {
.... defined here
}
</SCRIPT>
The sendEvent javascript function sends a GET request to the server with
the following CGI query variables at the end:
?jsp_callmethod="bean.someMethod(event)"&jsp_eventid=event.id&jsp_eventtarget=event.target&jsp_eventsource=event.source
Now whenever the user clicks on that link the server side program can
respond by doing some action; you could probably wrap this with the Event
pattern so that the server side object then receives an Event object
telling it an event has occurred (it would be a JSPEventListener).
The sum result of all this is that you can truly start using HTML as your
user interface. I don't know about you but I'd rather be using HTML and
Dynamic HTML as my user interface than Swing.
>
> exactly what should happen, and when? A "click" event in the client browser
> will never get seen by the server.
>
> HTML generation on the server side is deterministic -- I don't see what
> "events" might happen that the server would need to react to, so that it can
> modify its output.
>
> The client can already influence what the server does with the parameter values
> that it sends -- which JSP already handles for you with <jsp:setProperty>, so
> propogating events from the client seems redundant (as well as not fitting into
> HTTP very gracefully :-).
>
> Craig McClanahan
>
>
>
>
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".