Hey man, did u see the email i send? with my class and struts.xml??

tks
----- Original Message ----- From: "JP Cafaro" <jcafar...@gmail.com>
To: "Struts Users Mailing List" <user@struts.apache.org>
Sent: Monday, July 12, 2010 2:38 PM
Subject: Re: Javascript issues


I think the problem has to do with this line:

<script src="ajax-user-browser.js" type="text/javascript" />

When I use firefox, and view the source, I can click on the link to
ajax-user-browser.js and it can't find the resource.  I think this is
because it's under my WEB-INF directory.  I moved ajax-user-browser.js
to a folder "js" on the same level as WEB-INF and changed the line to:

<script src="../js/ajax-user-browser.js" type="text/javascript" />

but it still doesn't work! Nothing shows up on the page. However when I view the source this time, I can click the link and I do see the code for the javascript. Please help!



JP Cafaro wrote:
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-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



--------------------------------------------------------------------------------



No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.830 / Virus Database: 271.1.1/2998 - Release Date: 07/12/10 03:36:00


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to