dcsimg
Ajax struts
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   meena_sailam
Posted On:   Friday, April 27, 2007 06:41 AM

Hi, Plz do help me... I'm trying an example with ajax tag lib and struts. the example was working absolutely fine with servlets but when i tried using the struts ... it simply does not work. Its not even making the call to the action class. I doubt whather it even recognises the truts config... For me , the action class is absolutly fine... There is a hitch only in the definition of baseURL attribute of the AJAX Select tag. I'm posting the jsp which makes the cal along with strutsconfig.xml and the action class, also the select tag java file. //JSP file Select Tag Demo JSP source |    More>>

Hi,

Plz do help me...

I'm trying an example with ajax tag lib and struts.

the example was working absolutely fine with servlets but when i tried using the struts ...
it simply does not work.
Its not even making the call to the action class.
I doubt whather it even recognises the truts config...

For me , the action class is absolutly fine... There is a hitch only in the definition of baseURL attribute of the
AJAX Select tag.

I'm posting the jsp which makes the cal along with strutsconfig.xml and the action class, also the select tag java file.
//JSP file


			


Select Tag Demo






Choose Your Car



src=" <%=request.getContextPath()%>/img/placeholder.gif"
width="76" height="29" />















baseUrl="/ajaxtags-1.2-beta3/BaseAjaxAction"
source="make"
target="model"
parameters="make={make}"
postFunction="resetProgress"
errorFunction="reportError"
/>



////action class

			
package org.ajaxtags.demo.action;

import java.util.List;
import java.io.PrintWriter;

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

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import org.ajaxtags.demo.CarService;
import org.ajaxtags.helpers.AjaxXmlBuilder;

/**
* Abstract class that can be extended for application-specific Struts action classes.
*
* @author Darren Spurgeon
* @version $Revision: 1.2 $ - $Date: 2005/10/05 17:52:16 $
*/
public class BaseAjaxAction extends Action {

/**
* @see Action#execute(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse)
*/
public ActionForward execute(
ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {

String xml = null;
System.out.println("hello....");
try {
String make = request.getParameter("make");

// Get maker from your service bean
CarService service = new CarService();
List list = service.getModelsByMake(make);


xml = new AjaxXmlBuilder().addItems(list, "model", "model").toString();
}
catch (Exception ex) {
// Send back a 500 error code.
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Can not create response");
return null;
}

// Set content to xml
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
PrintWriter pw = response.getWriter();
pw.write(xml);
pw.close();

return null;
}



//Struts config file


			
<?xml version="1.0" encoding="ISO-8859-1" ?>
























			
package org.ajaxtags.tags;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;

/**
* Tag handler for the select AJAX tag.
*
* @author Darren Spurgeon
* @version $Revision$ $Date$
*/
public class AjaxSelectTag extends TagSupport {

private String baseUrl;

private String source;

private String target;

private String parameters;

private String eventType;

private String postFunction;

private String emptyFunction;

private String errorFunction;

public String getBaseUrl() {
return baseUrl;
}

public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}

public String getEmptyFunction() {
return emptyFunction;
}

public void setEmptyFunction(String emptyFunction) {
this.emptyFunction = emptyFunction;
}

public String getErrorFunction() {
return errorFunction;
}

public void setErrorFunction(String errorFunction) {
this.errorFunction = errorFunction;
}

public String getEventType() {
return eventType;
}

public void setEventType(String eventType) {
this.eventType = eventType;
}

public String getParameters() {
return parameters;
}

public void setParameters(String parameters) {
this.parameters = parameters;
}

public String getPostFunction() {
return postFunction;
}

public void setPostFunction(String postFunction) {
this.postFunction = postFunction;
}

public String getSource() {
return source;
}

public void setSource(String source) {
this.source = source;
}

public String getTarget() {
return target;
}

public void setTarget(String target) {
this.target = target;
}

public int doStartTag() throws JspException {
// Required Properties
this.baseUrl = (String) ExpressionEvaluatorManager.evaluate("baseUrl", this.baseUrl,
String.class, this, super.pageContext);
this.source = (String) ExpressionEvaluatorManager.evaluate("source", this.source, String.class,
this, super.pageContext);
this.target = (String) ExpressionEvaluatorManager.evaluate("target", this.target, String.class,
this, super.pageContext);
this.parameters = (String) ExpressionEvaluatorManager.evaluate("parameters", this.parameters,
String.class, this, super.pageContext);

// Optional Properties
if (this.eventType != null) {
this.eventType = (String) ExpressionEvaluatorManager.evaluate("eventType", this.eventType,
String.class, this, super.pageContext);
}
if (this.postFunction != null) {
this.postFunction = (String) ExpressionEvaluatorManager.evaluate("postFunction",
this.postFunction, String.class, this, super.pageContext);
}
if (this.errorFunction != null) {
this.errorFunction = (String) ExpressionEvaluatorManager.evaluate("errorFunction",
this.errorFunction, String.class, this, super.pageContext);
}
if (this.emptyFunction != null) {
this.emptyFunction = (String) ExpressionEvaluatorManager.evaluate("emptyFunction",
this.emptyFunction, String.class, this, super.pageContext);
}
return SKIP_BODY;
}

public int doEndTag() throws JspException {
OptionsBuilder options = new OptionsBuilder();
options.add("source", this.source, true).add("target", this.target, true).add("parameters",
this.parameters, true);
if (this.eventType != null)
options.add("eventType", this.eventType, true);
if (this.postFunction != null)
options.add("postFunction", this.postFunction, false);
if (this.emptyFunction != null)
options.add("emptyFunction", this.emptyFunction, false);
if (this.errorFunction != null)
options.add("errorFunction", this.errorFunction, false);

StringBuffer script = new StringBuffer();
script.append("

");

JspWriter writer = pageContext.getOut();
try {
writer.println(script);
} catch (IOException e) {
throw new JspException(e.getMessage());
}
return EVAL_PAGE;
}

public void release() {
this.baseUrl = null;
this.source = null;
this.target = null;
this.parameters = null;
this.eventType = null;
this.postFunction = null;
this.emptyFunction = null;
this.errorFunction = null;
super.release();
}

}


   <<Less

Re: Ajax struts

Posted By:   Anonymous  
Posted On:   Friday, May 4, 2007 12:20 AM

HI,
try calling your action class by typing the url directly in the browser if it get called then its the problem with the baseUrl value in the script. Then try removing the starting '/' in the baseUrl.

Hope it solves your problem.

Regards,
Rakesh
About | Sitemap | Contact