0

I am working on ajax using struts 2 frame work. Application has two text boxes "name" and "age". On submitting , those two values should be updated using div tag on the same page itself.

<sx:div id="div2" executeScripts="true" theme="ajax">Value</sx:div>


<sx:submit targets="div2"  value="submit">

when i use "targets" attribute in sx:submit ,getting some exception. when i remove "targets" no exception has been thrown.But application needs "targets" attribute to update the div tag.Do i need to any handle exception ? I am trying this as a sample exmple , my application needs this kind of functionality. Help me.

Source code as follows :

<%@taglib  uri="/struts-tags"  prefix="s"  %>

<%@taglib uri="/struts-dojo-tags" prefix="sx" %>

<html>

<head><title>Ajax_Div_Tag_Example</title>

</head>

<body><h1>Ajax_Div_Tag_Example</h1><hr>

<sx:div id="div2" executeScripts="true" theme="ajax">Value</sx:div>

<s:form action="resultAction">

<s:textfield name="name" label="Name"></s:textfield>

<s:textfield name="age" label="Age"></s:textfield>

<sx:submit value="submit" targets="div2"> </sx:submit>

</s:form>

</body>

</html> 

struts.xml

<action  name="resultAction"  class="ActionClasses.AjaxDivAction">
        <result name="success">/resultPage.jsp</result>
        </action>

resultPage.jsp

<%@taglib  uri="/struts-tags"  prefix="s"  %>

<html>

<head><title>Ajax_Div_Tag_Example</title>

</head>

<body><hr>Name : <s:property value="name"/><br>

Age : <s:property value="age"/><hr>

</body>

</html> 

AjaxDivAction.java

package ActionClasses;
import  com.opensymphony.xwork2.ActionSupport;

public class AjaxDivAction extends ActionSupport{

/**
     * 
     */
    private static final long serialVersionUID = 1L;

private String name;

private String age;

public String getAge() {

return age;

}

public void setAge(String age) {

this.age = age;

}

public String getName() {

return name;

}

Exception thrown is give below

org.apache.jasper.JasperException: An exception occurred processing JSP page /AjaxDemo.jsp at line 21

18: 
19: <s:textfield name="age" label="Age"></s:textfield>
20: 
21: <sx:submit value="submit" targets="div2"> </sx:submit>
22: 
23: </s:form>
24: 


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:519)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)

root cause

javax.servlet.ServletException: java.lang.AbstractMethodError
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
    org.apache.jsp.AjaxDemo_jsp._jspService(AjaxDemo_jsp.java:94)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)

root cause

java.lang.AbstractMethodError
    org.apache.struts2.components.ClosingUIBean.start(ClosingUIBean.java:65)
    org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:53)
    org.apache.jsp.AjaxDemo_jsp._jspx_meth_sx_005fsubmit_005f0(AjaxDemo_jsp.java:242)
    org.apache.jsp.AjaxDemo_jsp._jspx_meth_s_005fform_005f0(AjaxDemo_jsp.java:168)
    org.apache.jsp.AjaxDemo_jsp._jspService(AjaxDemo_jsp.java:82)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.32 logs.

Thanks

Jagan

Jagan
  • 4,649
  • 19
  • 60
  • 70
  • I did not understand reason for exception – Jagan Jun 30 '11 at 06:03
  • http://stackoverflow.com/questions/1194990/why-do-i-get-java-lang-abstractmethoderror-when-trying-to-load-a-blob-in-the-db – Jagan Jun 30 '11 at 08:53
  • Is it because you are using `` instead of `
    `? Not sure why you are using `` since _This tag generates an HTML div that loads its content using an XMLHttpRequest call, via the dojo framework_ according to the tag documentation at http://struts.apache.org/2.1.6/docs/dojo-div.html
    – nmc Jun 30 '11 at 13:21
  • No i don't think so.If i use
    , i have to write javascript to create XMLHttpRequest.
    – Jagan Jun 30 '11 at 13:28
  • I don't see any `href` property in your `` tag so I assume you don't need XMLHttpRequest call? – nmc Jun 30 '11 at 13:30
  • See the example. http://www.roseindia.net/struts/struts/struts2.2.1/tags/div_tag.html – Jagan Jun 30 '11 at 13:30

2 Answers2

0

First the struts2 ajax tags have been deprecated, I'll come back to this.

Not looking too long, you are missing the sx:head tag... Please see: http://struts.apache.org/2.2.1.1/docs/tag-reference.html It is the sx:head tag which inserts most of the required JavaScript. After that you'll be a lot closer.

Back to the taglib being deprecated... Simply any ajax tag library is brittle. Simple things are simple, any thing more than that becomes next to impossible. You will have far more flexibility if you invest some time in a JS library such as jQuery and it is very trivial to use the struts2-json-plugin. The audience for your UI questions will go up by several factors as your audience will not need to know anything about struts2 or even Java.

Quaternion
  • 10,380
  • 6
  • 51
  • 102
0

There was a problem with strut2-core-2.jar file.I downloaded latest version and tried.It is working fine now.

Jagan
  • 4,649
  • 19
  • 60
  • 70