Posts Tagged "Struts2"
Struts2 Iterating through a List of List
This is a simple example demonstrating how to use the iterator tag in struts2 to iterate through a list of objects which contains another list of objects.
Assume that we have a class called City which contains a list of phone numbers:
public class City {
private String name;
private List<PhoneNumber> phoneNumbers;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<PhoneNumber> getPhoneNumbers() {
return phoneNumbers;
}
public void setPhoneNumbers(List<PhoneNumber> phoneNumbers) {
this.phoneNumbers = phoneNumbers;
}
}
Read More
Struts2 – Object-Graph Navigation Language
OGNL stands for Object-Graph Navigation Language. It’s a powerful technology integrated into the Struts2 framework. What it basically does is to glue string based HTTP inputs and outputs into Java beans. In other words it is responsible for converting string based values inside http-requests into java-beans. The following is from the book manning Struts2 I have been reading lately. It clearly describes the relation between the presentation layer and the business layer and what OGNL does.
As you can see, we have a form in an html file called inputFrom.html. OGNL later maps the name of these fields to existing java bean objects. After the values are set inside the action class, they are retrieved from the object and displayed inside “ResultPage.jsp”. Once again OGNL is responsible for retrieving the values inside “user.age”.
One thing you should notice is that the name value inside the form is the name of an object called “user” inside the action class, which is of type “User”. If this object doesn’t exist or if you don’t have setters and getters functions with standard naming OGNL will not be able to set the values inside the object.
Struts2 – Accessing variables from JSP files
Here is a simple tutorial on how to access different types of variables such as Strings, Lists, costume Objects from a .jsp file.
Fist We will create a simple class called User. This class is later used to create objects that are passed to the .jsp file:
package user;
public class User {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Read More
Eclipse 3.4.x + Struts2 + Tomcat 6.x

There are many Struts2 tutorials on the web for the beginners, but it was really difficult for me to find an easy to understand tutorial to help me configure my local environment and start a simple struts project. In this post I show how to configure your local environment to use struts2 with eclipse IDE version 3.4.x.
Struts 2 in Action

I have always been looking forward to learn more about struts2. I have read some tutorials on the Internet, which were really useful, but the problem with the problem with them was that they didn’t really go into the details. I have started reading the book “Struts 2 in Action”. It shows you the big picture and the details of struts2 actions, interceptors, OGNL etc. Overall I really liked this book. I should mention that the only downside I realized when I was reading this book was the fact that it doesn’t contain enough sample code. This website should give you more information about this book, it also contains some samples from different chapters.