Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 04-08-2009
Member
 
Join Date: Apr 2008
Posts: 26
Need a working struts2 Ajax example

Hello,

I need an working dropdown example of struts 2 Java with Ajax.
I am using ejb3.0 in my project. I have been through the google search & it takes me to the old Struts 1 documents & its really not helpful for struts 2 application developers.

Need a working struts2 Ajax example.

Thanks
Reply With Quote
  #2  
Old 04-08-2009
Member
 
Join Date: Apr 2008
Posts: 38
Re: Need a working struts2 Ajax example

Please have a look at here.

http://swik.net/struts2+Ajax

I think here you will have a good results for Java Struts 2 + Ajax
Reply With Quote
  #3  
Old 04-08-2009
Member
 
Join Date: Apr 2008
Posts: 32
Re: Need a working struts2 Ajax example

Login Form using Ajax

Here is a Login form in Ajax that may give you an Idea. Still searching for a dropdown example.

Create an action mapping in the struts.xml file. Here is the code to be added in the struts.xml:

Code:
<action name="showAjaxLoginForm">
       <result>/pages/ajaxlogin.jsp</result>
</action>

<action name="ajaxLogin" class="net.roseindia.Login">
       <result name="input">/pages/ajaxlogin.jsp</result>
       <result name="error">/pages/ajaxlogin.jsp</result>
       <result>/pages/ajaxloginsuccess.jsp</result>
</action>
Develop a Login Form Using Ajax : The GUI of the application consists of a login form (ajaxlogin.jsp). The "ajaxlogin.jsp" displays the login page to the user. This jsp page uses the <s:div> tag, this tag creates a content area that can load its content using Ajax tags, optionally refreshing. Here we also use the <s:submit> tag that is used to update element (s) or submit a form with the help of Ajax.

Whenever an error occurs then the <s:actionerror> and <s:fielderror> tags execute and display an error message the login form is submitted.

Here is the code of ajaxlogin.jsp file:

Code:
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
  <head>
    <s:head theme="ajax" debug="true"/>
    </script>
  </head>
  <body>
    <s:div id="loginDiv" theme="ajax">
    <div style="width: 300px;border-style: solid">
      <s:form action="ajaxLogin"  validate="true">
        <tr>
          <td colspan="2">
            Login
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <s:actionerror />
            <s:fielderror />
          </td>
        </tr>  
          <s:textfield name="username" label="Login name"/>
          <s:password name="password" label="Password"/>
          <s:submit theme="ajax" targets="loginDiv" notifyTopics="/ajaxLogin"/>    
      </s:form>
    </div>
    </s:div>
  </body>
</html>
Develop an action class that handles the login request and checks for the user authentication. If the user name and password is "Admin" then it returns SUCCESS otherwise ERROR object.

Code:
import com.opensymphony.xwork2.ActionSupport;
import java.util.Date;


/**
 * <p> Validate a user login. </p>
 */
public  class Login  extends ActionSupport {


    public String execute() throws Exception {
        System.out.println("Validating login");
    if(!getUsername().equals("Admin") || !getPassword().equals("Admin")){
            addActionError("Invalid user name or password! Please try again!");
            return ERROR;
    }else{
      return SUCCESS;
    }
  }


    // ---- Username property ----

    /**
     * <p>Field to store User username.</p>
     * <p/>
     */
    private String username = null;


    /**
     * <p>Provide User username.</p>
     *
     * @return Returns the User username.
     */
    public String getUsername() {
        return username;
    }

    /**
     * <p>Store new User username</p>
     *
     * @param value The username to set.
     */
    public void setUsername(String value) {
        username = value;
    }

    // ---- Username property ----

    /**
     * <p>Field to store User password.</p>
     * <p/>
     */
    private String password = null;


    /**
     * <p>Provide User password.</p>
     *
     * @return Returns the User password.
     */
    public String getPassword() {
        return password;
    }

    /**
     * <p>Store new User password</p>
     *
     * @param value The password to set.
     */
    public void setPassword(String value) {
        password = value;
    }

}
I hope this helps you.
Reply With Quote
  #4  
Old 04-08-2009
Member
 
Join Date: Apr 2008
Posts: 49
Re: Need a working struts2 Ajax example

hey I think this tutorial on Amazon may help you with Struts2 & Ajax functionality.
Struts 2 Design and Programming: A Tutorial (A Tutorial series) (Paperback)
It costs $32 only.

I think this may be helpful for your development purpose.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Need a working struts2 Ajax example"
Thread Thread Starter Forum Replies Last Post
Ajax collapsible panel not working properly jEEMOOT Software Development 6 26-02-2011 09:55 AM
jQuery AJAX vs. Adobe AIR AJAX Class Agaev Windows Software 5 06-07-2010 01:59 PM
PHP Vs AJAX Happy46 Software Development 3 03-09-2009 07:27 PM
Ajax code not working in Firefox Mayur_Jain Software Development 4 02-05-2009 02:40 PM
What is AJAX in Asp.net ? Braze Software Development 5 14-01-2009 06:35 PM


All times are GMT +5.5. The time now is 11:43 AM.