You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-dev@incubator.apache.org by Bob Buffone <rb...@nexaweb.com> on 2006/08/01 18:37:40 UTC

RE: Looking for demo code for server side...

David,

Answers are in the message dialog, hope this helps.

Bob

-----Original Message-----
From: David Dabbs [mailto:david@dabbs.net] 
Sent: Monday, July 31, 2006 4:23 PM
To: xap-dev@incubator.apache.org
Subject: Looking for demo code for server side...

I've dug into the demos and they are informative, to a point. However,
I'm
looking for something that describes the component lifecycle for a
non-trivial application. I'll trace out a scenario with some questions. 

Let's say I'm using Java servlets. My _initial_ UI is specified
declaratively in index.xap, so I presume that my index.html/jsp will
follow
the "bootstrap shell" seen in the demos. The initial app is served from
"/apps/Test/index.xap". According to RequestService, any requests must
be
relative to the app context (e.g. index.xap) so any subsequent calls
would
be to URLs such as /apps/Test/srv/foo or /apps/Test/srv/bar.jsp.

After the initial UI appears, the user can enter some input, click a
button
and a table will refresh with their search results.... 

Q: I presume that all client-side service consumers use RequestService
via
the session, yes?

A: Client events are sent through the RequestService and the results are
automatically processed when the event handler is a server side
resource. 

For example:
	<button onCommand="myServlet?foo=bar"/>

When the button is clicked, XAP will make the request to the server and
process the results.  If the event is processed by client side code then
you can determine if the results are to be processed or you want to
handle the results.

<button onCommand="mco:myMco.handleEvent"/>

function handleEvent(clientEvent){
	//Handle the event yourself.  Usually the result will not be
xModify.
	clientEvent.getClientSession().getRequestService().
				request("myServlet?foo=bar");

	//XAP process the event.  The result of the result will be
xModify.
	clientEvent.getClientSession().getRequestService().
				requestAndProcess("myServlet?foo=bar");
}

Q: Is it preferable for all consumers of server services to use one
parameterized "service URL" or separate function-specific URLs? Or does
this
boil down to taste/style/maintainability?

A: Whether or not you send requests to a single servlet or multiple
servlets is a matter of taste/style/maintainability.


Q: If in addition to the data update I also want to download some
additional
UI code, I can see how XModify could handle the UI spec. But then the
server
would need to maintain some state so that this UI spec is not downloaded
again, yes? Also, by what means does any js/"handler code" required by
the
new UI elements get downloaded?

A: The xModify allows developers to transition from one state to the
next. The server doesn't need to maintain the state because it is not
the initiator or the transition.  For instance: you may want to open a
dialog from a button.  A call to the opendialog.xal page will be made
that defines the dialog.  If the dialog needs to be populated with
information from a form in the UI then that information needs to be sent
to the server so the UI can be prepopulated.  If the dialog is closed
and the "Open Dialog" button is clicked again another request will be
made an the dialog will be opened.  If you don't want to make requests
then a Macro could be created to perform the xModify from the client.

<button onCommand="macro:openDialogMacro.execute();"/>


If these sorts of questions are addressed by a document or sample
application, a pointer would be greatly appreciated!

Thank you,

David