Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
JSP - A mailing list about Java Server Pages specification and reference
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
Ajax Form Submit

Ajax Form Submit

2007-02-01       - By Siva Gurusamy

 Back
Reply:     1     2  

HI,

I am having a problem in using ajax in Struts 2 Application.

Can someone explain me how to resolve this issue.

I have a form and an ajax div in the page. On submit of the form I wanted to
reload ajax div. But result was, after doing submit form, 'undefined' text
was appeared in targets (resultDivId) for a second and then browsers url got
changed to form submit url. Hence, the result which needs to appear in
targets(resultDivId) appeared in entire browser.

My Code:

JSP:
<%@(protected) prefix="s" uri="/struts-tags" %>
<html>
<head>
   <title>Ajax Examples</title>
   <!--// START SNIPPET: common-include-->
   <s:head theme="ajax"/>
   <!--// END SNIPPET: common-include-->
</head>

<body>
        <div id="createResult"></div>

        <s:form id="createId" action="createajax"
namespace="/" method="POST" theme="ajax">
          <s:textfield label="AccountName"
name="accountName"/>
          <s:submit value="Save" name="Save"
resultDivId="createResult" notifyTopics="topicCreated" theme="ajax"
errorText="Error" showErrorTransportText="true"/>
          <!--s:submit action="!cancel"
value="Cancel" name="Cancel"
            onclick="form.onsubmit=null"/-->
        </s:form>
 
        <h1>Users</h1>
         <s:div
                id="userlists"
               cssStyle="border: 200x solid blue"
               href="ajaxList.action"
               theme="ajax"
          delay="1"
               errorText="There was an fatal error"
               showErrorTransportText="true"
          listenTopics="topicCreated"
               loadingText="Loading users...">Loading...
         </s:div>

</body>
</html>

Struts.xml
   <package name="example" extends="struts-default" namespace="/">
    <interceptors>
      <interceptor-stack name="ajaxStack">
        <interceptor-ref name="createSession" />
        <interceptor-ref name="exception"/>
               <interceptor-ref name="alias"/>
               <interceptor-ref name="servlet-config"/>
               <interceptor-ref name="prepare"/>
               <interceptor-ref name="i18n"/>
               <interceptor-ref name="chain"/>
               <interceptor-ref name="debugging"/>
               <interceptor-ref name="model-driven"/>
               <interceptor-ref name="fileUpload"/>
               <interceptor-ref name="static-params"/>
               <interceptor-ref name="params"/>
               <interceptor-ref name="conversionError"/>
               <interceptor-ref name="validation">
                   <param
name="excludeMethods">input,back,cancel,browse</param>
               </interceptor-ref>
               <interceptor-ref name="workflow">
                   <param
name="excludeMethods">input,back,cancel,browse</param>
               </interceptor-ref>
      </interceptor-stack>

    </interceptors>

    <default-interceptor-ref name="defaultStack"/>

    <action name="createajax"
class="com.app.view.action.UserAction" method="create">
      <result type="freemarker">createerror.ftl</result>
      <interceptor-ref name="ajaxStack"/>
       </action>
</package>

UserAction.create method

  public String create()   {
    // This is just preparing the form prior to saving the new
user
    actionType = CREATE;
    System.out.println("-- -----> Going to create new user
(name)=" + accountName);
    User u = new User();
    u.setUserId(userId);
    u.setAccountName(accountName);

    try {
      userService.createUser(u);
    } catch (Exception e)   {
      e.printStackTrace();
      System.out.println("Adding error to
ActionError...");
      //addActionError(e.toString());
    }

    return SUCCESS;
  }

createerror.ftl:
<@(protected) />
<@(protected) />


Thanks
siva





-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.