Struts-2 Updates
Ajax implementation in Struts 2 without jQuery plugin
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 moreHow 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 moreDynamically 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 moreDatetime 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 moreException 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 moreAutocompleter 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 moreDifference 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 moreCommon 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 moreiterator 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 moreIf, 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