Thanks for the overview Frank. I'm using struts 2 and will lookup how to writeup AJAX requests to get this done.
Thanks a bunch, Session > Is this Struts1 or Struts2? That will (potentially) change the mechanics > a little, but in theory, sure, it's easy to do. Assume Struts1 for a > moment... > > 1. User triggers event on the page that does the delete. This causes a > Javascript function to be executed. 2. That function makes an AJAX > request, using your favorite library. 3. Action is invoked (AJAX just > requests a URL after all, which is what a Struts action mapping is) and > does its work. 4. Action forwards to a JSP as is typical. This JSP can be > something as simple as this: > > <% if (request.getAttribute("deleted") != null) { %> > <%=request.getAttribute("nodeID")%> <% } else { %> NOT DELETED <% } %> > > Assuming the action put the "deleted" attribute in request if the delete > was accomplished, as well as the ID of the ndoe that was deleted, that's > all there is to it. > > 5. The response is returned to the client, and being an AJAX request, some > Javascript function that you specified at the time the call was made, the > AJAX callback function, is executed. Passed to it will be the response > from the server. So, you simply do a quick check to see which string got > returned, and if its != "NOT DELETED", call whatever delete method likely > exists for the tree widget your using (most provide this), passing it the > response from the server, which is in fact the ID of the node to delete. > No need to rebuild the tree, no need to re-render the page, no need to > return an updated set of data, just delete the one node you need to. > > That's all there is to it. Now, you don't even need the JSP if you don't > want to have it, you can write the same response out from the Action, but > using a JSP, even for something as trivial as this, tends to be more > flexible and easier to toy with. AJAX always works this way, basically, > so if your talking Struts2 you may do some things slightly different > because there's some built-in AJAX support that might hide some of this > from you and make it easier, but basically it's the same underlying flow. > > Frank > > -- Frank W. Zammetti Founder and Chief Software Architect Omnytex > Technologies http://www.omnytex.com AIM/Yahoo: fzammetti MSN: > [EMAIL PROTECTED] Author of "Practical Ajax Projects With Java > Technology" (2006, Apress, ISBN 1-59059-695-1) and "JavaScript, DOM > Scripting and Ajax Projects" (2007, Apress, ISBN 1-59059-816-4) Java Web > Parts - http://javawebparts.sourceforge.net Supplying the wheel, so you > don't have to reinvent it! > > Session A Mwamufiya wrote: >> The jsp page sends a delete request to the struts action that >> determines whether or not the object associated with the node can be >> deleted from the database. The struts action removes the object from >> the database if all is well, and at this point, I would like to have >> the struts action notify the jsp that it can remove the node from the >> tree. Is there a way to set it up so that the jsp page gets a return >> value from the action and javascript within the jsp page removes the >> node accordingly? >> >> Thanks, Session >> >> >>> 3. Generate JavaScript in the Ajax result that removes the node (and >>> re-renders the tree if necessary; I don't know how all that works) >>> and execute it. >>> >>> --- Chris Pratt <[EMAIL PROTECTED]> wrote: >>> >>>> You can use the Rhino JavaScript interpreter to execute JavaScript >>>> from Java, but I don't think that's actually what you are looking >>>> for. >>>> >>>> It sounds like you are asking "How to I run some JavaScript in the >>>> client's browser when something changes on the server?" And the >>>> short answer is, you can't. At least not directly. >>>> >>>> Remember, the web uses a Request/Response model where the Browser >>>> makes a request and the server returns a response, so there is no >>>> simple way for the server to initiate something happening in the >>>> browser. >>>> >>>> Two options I can see are: >>>> >>>> 1. Have the browser make an AJAX request and the server can return >>>> the new DOM tree without the removed node >>>> >>>> 2. Have the browser resubmit the request and the new page can be >>>> built without the removed node. >>>> >>>> (*Chris*) >>>> >>>> On 9/6/07, Session A Mwamufiya <[EMAIL PROTECTED]> wrote: >>>>> Hi, >>>>> >>>>> Does anyone have an example of how to call a >>>> javascript function from a java class? I want to call a javascript >>>> function that removes a node from a tree after a java class >>>> removed it from the database. >>>>> Thanks, Session >>>>> >>>>> >>>>> >>> --------------------------------------------------------------------- >>> >>>>> To unsubscribe, e-mail: >>>> [EMAIL PROTECTED] >>>>> For additional commands, e-mail: >>>> [EMAIL PROTECTED] >>>>> >>>> >>> --------------------------------------------------------------------- >>> >>>> To unsubscribe, e-mail: [EMAIL PROTECTED] For >>>> additional commands, e-mail: [EMAIL PROTECTED] >>>> >>>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [EMAIL PROTECTED] For >>> additional commands, e-mail: [EMAIL PROTECTED] >>> >>> >>> >> >> >> --------------------------------------------------------------------- To >> unsubscribe, e-mail: [EMAIL PROTECTED] For additional >> commands, e-mail: [EMAIL PROTECTED] >> >> >> >> >> > > > --------------------------------------------------------------------- To > unsubscribe, e-mail: [EMAIL PROTECTED] For additional > commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]