struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Gainty <mgai...@hotmail.com>
Subject RE: Javascript issues
Date Mon, 12 Jul 2010 22:04:55 GMT

ajax controls allow asynchronous population of div tags..there needs to be some sort of notify/listener
capability to triggger the listener to wakeup and populate the div tag

when the event is being notified e.g.


<script type="text/javascript">
   function handler(widget, node) {

     <!-- go do something in the Action class and populate the Action bean -->
     alert('I will handle this myself!');
  node.innerHTML = "%{Action.Bean}%"; //the contents of the div tag get populated here
   }
</script>

<s:url var="ajaxTest" value="/AjaxTest.action" />

<body>

<!-- the handler 
<sx:div
        id="once"
        cssStyle="border: 1px solid yellow;"

 

martin
 -----------------------------------------------------------------------------------------------
    

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten
wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist
unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet
keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen
wir keine Haftung fuer den Inhalt uebernehmen.

Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire
prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe
quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information
seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les
email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune
responsabilité pour le contenu fourni.



 

> Date: Mon, 12 Jul 2010 12:57:47 -0400
> From: jcafaro10@gmail.com
> To: user@struts.apache.org
> Subject: Javascript issues
> 
> I'm trying to incorporate some ajax stuff with struts2 but I'm running 
> into problems.
> 
> I have this action:
> public class AjaxUserBrowser extends ActionSupport
> {
> private List<User> users;
> 
> public String execute()
> {
> System.out.println("AJAX USER BROWSER");
> setUsers(getPortfolioService().getUsers());
> return SUCCESS;
> }
> 
> public PortfolioService getPortfolioService( ) 
> {
> return new PortfolioService();
> }
> 
> public void setUsers(List<User> users)
> {
> this.users = users;
> }
> 
> public List<User> getUsers()
> {
> return users;
> }
> }
> 
> It's very simple. It doesn't really do anything. 
> 
> Then I have this resulting jsp page:
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
> pageEncoding="ISO-8859-1"%>
> <%@ taglib prefix="s" uri="/struts-tags"%>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
> <script src="ajax-user-browser.js" type="text/javascript" />
> <title>Title</title>
> </head>
> <body>
> <h5>Artist Browser Control</h5> 
> <s:form action="AjaxRetrieveUser">
> <s:select name="username" list='users' listKey="username" 
> listValue="username" label="Select an artist" value="defaultUsername" 
> onchange="fetchUser();"/> 
> </s:form> 
> <hr/>
> <h5>Artist Information</h5> 
> <div id='console'>
> <p>Name: <s:property value="defaultUser.firstName"/> <s:property 
> value="defaultUser.lastName"/></p>
> <s:iterator value="defaultUser.portfolios">
> <p>PortfolioName: <s:property value="value.name" /></p>
> </s:iterator>
> </div>
> </body>
> </html>
> 
> When I click the link to the action, nothing appears on the resulting 
> page. The action fires (print statement is printed) but no resulting 
> page is shown. If I view the source, the html is right, and if I take 
> out the <script> line, the page is shown but doesn't do anything obviously
> 
> Here is the javascript file:
> var req=null;
> var console=null;
> var READY_STATE_UNINITIALIZED=0;
> var READY_STATE_LOADING=1;
> var READY_STATE_LOADED=2;
> var READY_STATE_INTERACTIVE=3;
> var READY_STATE_COMPLETE=4;
> 
> function sendRequest ( url, params, HttpMethod ) {
> 
> if ( !HttpMethod ){
> HttpMethod="GET";
> }
> req=initXMLHTTPRequest(); 
> 
> if ( req ) {
> req.onreadystatechange=onReadyState;
> req.open(HttpMethod, url, true );
> req.setRequestHeader ( "Content-Type", 
> "application/x-www-form-urlencoded");
> req.send (params);
> }
> }
> 
> function initXMLHTTPRequest(){
> var xRequest=null;
> if (window.XMLHttpRequest) {
> xRequest=new XMLHttpRequest();
> } else if ( window.ActiveXObject ){
> xRequest = new ActiveXObject("Microsoft.XMLHTTP");
> }
> return xRequest;
> }
> 
> 
> function onReadyState() {
> var ready=req.readyState;
> var jsonObject=null;
> 
> if ( ready == READY_STATE_COMPLETE ){
> jsonObject=eval( "("+ req.responseText +")" );
> toFinalConsole ( jsonObject );
> }
> }
> 
> function toFinalConsole(jsonObject){
> if (console!=null){
> removeAllChildren ( console );
> var div = document.createElement("p");
> var txt=document.createTextNode("Name: " + 
> jsonObject.artist.firstName + " " + jsonObject.artist.lastName );
> div.appendChild ( txt );
> console.appendChild(div);
> 
> //mess of Javascript references because we didn't mediate the JSON 
> interpretation of our maps, etc.
> var portfolios = jsonObject.artist.portfolios.entry;
> var portfolioCount = portfolios.length;
> for ( var index = 0; index < portfolioCount; index++ ) {
> var portfolio = portfolios[index];
> txt=document.createTextNode("Portfolio Name: " + 
> portfolio['string'] );
> div = document.createElement("p");
> div.appendChild ( txt );
> console.appendChild(div);
> }
> }
> }
> 
> function removeAllChildren( node ){
> var childCount = node.childNodes.length;
> for ( var count = 1; count <= childCount; count++) {
> node.removeChild ( node.childNodes[0] );
> }
> }
> 
> function fetchUser()
> {
> console=document.getElementById('console');
> var selectBox = document.getElementById('AjaxRetrieveUser_username');
> var selectedIndex = selectBox.selectedIndex;
> var selectedValue = selectBox.options[selectedIndex].value
> sendRequest("AjaxRetrieveUser.action", "username=" + selectedValue , 
> "POST");
> }
> 
> Maybe there's an error in the javascript? Is there a debugger or something?
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
 		 	   		  
_________________________________________________________________
The New Busy think 9 to 5 is a cute idea. Combine multiple calendars with Hotmail. 
http://www.windowslive.com/campaign/thenewbusy?tile=multicalendar&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_5
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message