Re: Ajax, WW and Velocity

Trupti <[email protected]> Sun, 10 Dec 2006 13:55:49 CST
Newsgroups gmane.comp.java.open-symphony.webwork
Message-ID <2914600.1165780579371.JavaMail.os-j2ee@opensymphony01.managed.contegix.com>
I am not using a div tag . I am using a select tag. That works fine , I mean the first select is auto populated whn the page loads. I select a value from the first drop-down , which then populates the second drop-down based on this value , using ajax ( xmlhttprequest object sending request to server n the rest...) . Now when I select a value in this second drop-down , what I need is it populate the velocity place holders in the same page. I am not sending the response to a different velocity template. For some reason, that doesnt work. I call the setter methods for the functions, however the change in values is not reflected in the template. How do I get it to parse the template again when I change the value in the drop-down?? 

Heres my code..
************************************* test.vm*******************************************************
<head>
<title>View Ticket History</title>
<script type="text/javascript" src="scripts/runticket.js"></script>
<link rel="stylesheet" type="text/css" href="styles/runticket.css" />
</head>

<body>
<form name="siteTickets">

<table align="center" style="font-weight:bold;font: small-caps 900 12px verdana;color:#006699" >

<tr align="center">
<td class="textstyle"> Sites :</td>
<td>
<select id="sitesList" name="sitesList" onchange="sitesListOnChange()">
<option name="default" value="default">&nbsp;&nbsp;--Select Sites from List--&nbsp;</option>
#foreach ($siteName in $sitesList)
<option value="$siteName">$siteName</option>
#end
</select>
</td>

<td class="textstyle"> RunTickets :</td>
<td>
<select id="runTicketsList" name="runTicketsList" onchange="runTicketListOnChange()">
<option name="default" value="default">&nbsp;&nbsp;--Select RunTicket from List--&nbsp;</option>
</select>
</td>
</tr>	
</table>
<input type="hidden" name="selectedRT" value="$selectedRT" />
<input type="hidden" name="selectedSite" value="$selectedSite" />
<input type="hidden" name="view" value="$view"/>
</form>

<div id="contentViewer" style="visibility:hidden">
<h3 style="color:#72A4D2"> Archived RunTicket </h3>
<form name="runTicketform" action="/megs/runTicket.action?serial=$serial&view=$view&status=update" method="post" >
#parse("/includes/runTicket.vm")
<div class="buttonRow">
	<div class="buttons">
		<input type="submit" name="submitrt" value= "Update RunTicket" />
		</form>				
	</div>		
</div> 
</div>
</body>

****************************************************************************************************

**********************************runTicket.vm**************************************************
<div>
<div>
	<div class="tblRow" style="margin-top:3px">
		<div class="cellHeader">Field Location:</div>
		<div class="cellData" id="fieldLocation">$location</div>
		<div class="cellHeader">Lease Company: </div>
		<div class="cellData" >$location</div>
	</div>
	<div class="tblRow">
		<div class="cellHeader">For Account Of:</div>
		<div class="cellData" id="accnt">$accountOf</div>
		<div class="cellHeader">Consignee: </div>
		<div class="cellData">	
		<input id="consignee" name="consignee" type="text" onfocus="setfocuscolor(this.id)" onblur="setblurcolor(this.id)" />
		</div>
	</div>
</div>
</div>
**************************************************************************************************
The values $location , $accountOf..are not set when I select the value in the second drop-down. Here is the Action Class..........

******************************************RunTicketHistoricalAction.java*******************
package com.moblize.management.servlets;

import java.io.PrintWriter;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Date;
import java.util.ArrayList;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.moblize.management.utils.BeanUtil;
import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionSupport;
import com.moblize.management.ejb.session.Chart;
import com.moblize.management.ejb.session.RunTicket;


public class RunTicketHistoricalAction extends ActionSupport 
{
    private String view;    
    private String host ="";
    private String serialNumber = "";
    private String site="";
    private String ip="";
    private String port="";
    private String location;
    private String date ="";  
    private String levelInch ="";
    private String levelBarr="";    
    private String dataList;
    private HttpServletRequest request = null;
    private HttpServletResponse response = null;    
    private Vector sitesList = null;
    private String selectedSite = null;
    private String selectedRT = null;
    private String tag;
    private String timestamp;
    
    public String getSerial() 
	{
        return serialNumber;
    }

    public void setSerial(String serialNumber) 
	{
        this.serialNumber = serialNumber;
    }
    
    public String getView()
    {
        return view;
    }

    public void setView(String view)
    {
        this.view = view;
    }

    

    public String getSite() 
	{
        return site;
    }

    public void setSite(String site) 
	{
        this.site = site;
    }
    
    public String getLocation() 
	{
        return location;
    }

    public void setLocation(String location) 
	{
        this.location = location;
    }
    
    public String getDate() 
	{
        return date;
    }

    public void setDate(String date) 
	{
        this.date = date;
    }    
      
    public Vector getSitesList() throws Exception
    {
    	return sitesList;
    }  
    
    public String getSelectedSite() 
	{
        return selectedSite;
    }

    public void setSelectedSite(String selectedSite) 
	{
        this.selectedSite = selectedSite;
    }
    
    public String getSelectedRT() 
	{
        return selectedRT;
    }

    public void setSelectedRT(String selectedRT) 
	{
        this.selectedRT = selectedRT;
    }
    
    public String execute() throws Exception 
    {
    	
      	
    	request = ServletActionContext.getRequest();	 	
	 	String selectedSite = request.getParameter("selectedSite");	
	 	String selectedRT = request.getParameter("selectedRT");	 	
	 	Map app = ActionContext.getContext().getApplication();	
	 	app.put("view", view);
	 	
	 	if(selectedSite != null && selectedRT == null) 
                    //populate the second drop-down
	 	{
	 		//generate xml response RTList	 		
	 			 	
	 		response = ServletActionContext.getResponse();
			response.reset(); 
			response.setContentType("text/xml");		   
			response.setHeader("Cache-Control", "no-cache");	
			PrintWriter op = response.getWriter();
			op.flush();
			op.write(RTList.toString());
			return "ticketlist";     //empty vm
			
	 	}
	 	else if (selectedSite != null && selectedRT != null)
	 	{	 		
	 		//set location , levelinch other properties...
                       // based on both dropdown values
	 		app.put("location", "Adams");
	 		app.put("levelInch", "35.67");
	 		
			response = ServletActionContext.getResponse();
			response.reset(); 
			response.setContentType("text/xml");		   
			response.setHeader("Cache-Control", "no-cache");	
			PrintWriter op = response.getWriter();
			op.flush();
			
			op.write(ticketData); 
			return "ticketlist";  //empty vm
	 		
	 	}
	 	
	 	return SUCCESS;
	 	
    }   
      
       
  }

********************************************************************************************
After I select the second drop-down , the web page shows values as $location , $accountOf...etc, they are not beign set, as the vm is already parsed I am guessing and is not merged or somethin..with the new Context?? .What am I missing here??

Thanks for your help :)
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=52867&messageID=106477#106477

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]