Pages Navigation Menu

Coding is much easier than you think

Struts-2 Updates

Ajax implementation in Struts 2 without jQuery plugin

Posted by in Ajax, Struts-2 | 2 comments

  AJAX is a technique for creating better, faster, and more interactive web applications. With AJAX, your JavaScript can communicate directly with the server, using the JavaScript XMLHttpRequest object. With this object, your JavaScript can transfer data with a web server, without reloading the page.   This post elaborates on how to implement Ajax in Struts 2 application.   ** UPDATE: Struts 2 Complete tutorial now available here.   Action class   package com.simplecode.action; import...

read more

How to Call Struts2 action from java script

Posted by in Struts-2

How to Call Struts2 action from java script

  Action Class   package com.simplecode.action; import com.opensymphony.xwork2.ActionSupport; public class MyAction extends ActionSupport { public String trueCall() { return SUCCESS; } public String falseCall() { return SUCCESS; } }   ** UPDATE: Struts 2 Complete tutorial now available here.   Jsp Pages   File : confirmBox.jsp   <%@taglib prefix="s" uri="/struts-tags"%> <html> <head> <title>Calling Action from java...

read more

Dynamically add, remove list of objects from jsp Using Struts2

Posted by in Struts-2 | 26 comments

Dynamically add, remove list of objects from jsp Using Struts2

  In this article we shall learn on how to dynamically add, remove list of objects from jsp Using Struts2.   File : User.java (Model Class)   package com.simplecode.action; import java.util.Collection; public class User { int regNo; String name; Collection<Address> addresses; public Collection<Address> getAddresses() { return addresses; } public void setAddresses(Collection<Address> addresses) { this.addresses = addresses; } public int getRegNo() { return...

read more

Datetime picker in struts 2 using jquery

Posted by in Struts-2 | 2 comments

Datetime picker in struts 2 using jquery

  Zip file – Jquery DatePicker   Last time when I worked out how to get the dojo datetimepicker Well, it faced some issues like, I could not customize the size of the text box, and also its appearance. As an alternative I found out a plugin Struts2- Jquery which provide a lots of customizing features.   ** UPDATE: Struts 2 Complete tutorial now available here.   To create a date time pick component in struts 2, please follow this two steps :   1. Add struts2-jquery-plugin-3.6.1.jar in...

read more

Exception handling in Struts 2

Posted by in Struts-2

Exception handling in Struts 2

  Zip file – Struts2Exception.zip   The Struts 2 framework provides some easy way to handle any uncaught exceptions. It works on exception interceptor which is part of default-stack in struts-default.xml file.   There are two ways to handle uncaught exceptions in Struts2: Global exception handling: specifies exception mappings which apply to all action classes in a Struts2. Exception handling per action: specifies exception mappings which apply to a specific action class. Both methods require...

read more

Autocompleter Textbox & dropdown in Struts 2

Posted by in Struts 2 Tutorial, Struts-2 | 17 comments

Autocompleter Textbox & dropdown in Struts 2

  To create a Autocompleter component in struts 2, please follow this two steps :   1. Add struts2-dojo-plugin.jar in your class path. 2. Include the “struts-dojo-tags” tag and its header(shown below) in your jsp page   <%@ taglib prefix="sx" uri="/struts-dojo-tags" %> <html> <head> <sx:head /> </head>   ** UPDATE: Struts 2 Complete tutorial now available here.   Action class   AutoCompleteAction.java   package...

read more

Difference between # , $ and % signs in Struts2

Posted by in Struts 2 Tutorial, Struts-2 | 4 comments

Difference between # , $ and % signs in Struts2

  Use of #   OGNL is used to refer to objects in the ActionContext as follows: myObject: object in the ValueStack, such as an Action property #myObject: object in the ActionContext but outside of the ValueStack… #myObject: ActionContext object that has been created using the Struts2 data tags with the default action scope (e.g., <s:set name=”data” value=”Some data” />, referenced by<s:property value=”#data” />) #parameters.myObject: request parameter #request.myObject:...

read more

Common Support class for Action classes in Struts 2

Posted by in Struts 2 Tutorial, Struts-2

Common Support class for Action classes in Struts 2

  When you are about to create a complex application in struts 2, it is better to create a Base action class for all your actions and make this class extend ActionSupport and implement all necessary interfaces such as SessionAware, ParameterAware, HttpServletRequest, HttpServletResponse etc and implement all other common logic for your actions in this class. So now when you are about to create an action class, just extending this support class will suit all your need in action class.   ** UPDATE: Struts 2 Complete tutorial now...

read more

iterator tag example in Struts 2

Posted by in Struts 2 Tutorial, Struts-2 | 9 comments

iterator tag example in Struts 2

  Struts 2 Iterator will iterate over a value. An iterable value can be any of: java.util.Iterator,java.util.Collection. In this tutorials, we will create a list and use Iterator tag to loop over it and get the iterator status with IteratorStatus.   Using IteratorStatus object one can get information about the status of the iteration, such as: index: current iteration index, starts on 0 and increments in one on every iteration count: iterations so far, starts on 1. count is always index + 1 first: true if index == 0 last: true if...

read more

If, Else, ElseIf Conditional/Control tag example in Struts 2

Posted by in Struts 2 Tutorial, Struts-2

If, Else, ElseIf Conditional/Control tag example in Struts 2

  Struts 2 If, ElseIf and Else tags are used to perform basic condition checking. These are the following scenario in real world application to check the condition. 1. Condition checking using Boolean variable. 2. Condition checking using String object. 3. Condition checking using collection object / bean object 4. Condition checking using integer data type   ** UPDATE: Struts 2 Complete tutorial now available here.   Now see the example on these scenario one by one.   1. Condition checking using Boolean...

read more