Skip to main content

Posts

Showing posts with the label struts2

Struts 2 - result type input error Resolved

Some times when coding through Struts 2 we get a input error specifying that result type input missing. But we haven't applied any validation on it. That some times creates a havoc among developers and they start complaining about the error as Struts 2 doesn't give the proper error. Struts 2 in Action I was also facing the same problem until I found the hole in my coding. As we all know that input type result is required when validate framework is applied. This is obvious as it will return to the input page defined in the input type result if some validation fails. But when we haven't applied any validation and this error is displayed what can be the problem. The problem can be: You have created a field on the jsp let it be hidden field and you are implementing the ModelDriven interface. But you forgot to add the jsp hidden field variable in the pojo class . This will surely generate this error. The solution to this problem is to declare a variable in the pojo

Struts 2.1.2 Released

Yesterday when I was searching for something on Google. I found that Apache had released the latest version of Struts 2 which is Struts 2.1.2 , and promoted it to Beta on 26 March 2008 Struts 2 in Action You can download it from Struts Download Page

Struts 2 Hello World Example

I had seen many new deveopers struggling against struts2 hello world example. So I decided to write a small example. Below are the required libraries to run this example which are easily availabel struts2-core-2.1.8.1 xwork-core-2.1.6 commons-logging-1.0.4 commons-logging-api-1.1 freemarker-2.3.8 ognl-2.7.3 commons-fileupload-1.2 The structure of the applictaion which I am following is (Eclipse IDE) Struts2Demo |---src | |----org | | |----vinod | | | |----action | | | | |----HelloWorld।java |---struts.xml |---WebContent | |---jsp | |---HelloWorld।jsp |---index.jsp |---WEB-INF | |---lib | |---web.xml Struts 2 in Action It is true that different IDE's use different structure, but at last when war is build they follow same structure. Lets start... HelloWorld.java import com.opensymphony.xwork2.ActionSupport; public class HelloWorld extends ActionSupport { String greetings = null; public String execute() throws Exception { setGreetings("Hel

Deadly Combination

Yes, Deadly combination!! It doesn't means that there would some super stars of the film who would go the devil place and finish him. No No !! I am talking about the deadly combination used in the development of the web sites. I am talking about the tools used for the Java development. Any guesses so far.... Yes, they are Struts2 , Spring , and Hibernate I am currently working all these tools. I am amazed to see the power of all the three technologies and how they makes the life of a developer like me, so easy. All of three would make your project a huge success. Now talking about Struts2 ... It is great framework with the inbuilt Ajax tags that would help many developers. Many new features of the struts2 are marvelous. Hibernate ... I already told in my last post about this. Hibernate would provide you a greater facility for your data persistence. its in built architecture that is fully object oriented which makes it a powerful tool. And yes, not to forget about the HQL (Hi

Changing default style of <s:actionerror/> / <s:actionmessage/> tag

In struts 2 when you put <s:actionerror /> tag it displays the errors in the following way: <ul> <li>error 1</li> <li>error 2</li> </ul> But sometimes it seems to be very ugly when displaying the dot (.) in the action errors or action messages Below is a normal code that displays the tags in your customized way. You can specify your own css for this <s:if test="hasActionErrors()"> <s:iterator value="actionErrors"> <span class="errorMessage"><s:property escape="false" /> </span> </s:iterator> </s:if> Alternatively you can change the file in the "/template/simple/actionerror.ftl” and put it in the /web-directory/struts/simple if using simple theme Similar for <s:actionmessage /> tag. Enjoy Struts

Session Check Interceptor

There must be some way to check that the current session is valid or invalid. This can be done using interceptors in struts in a very easy way. Here I am giving an example how to resolve this. First of all we will make an interceptor named SessionCheck.java. package com.demo.interceptors; import java.util.Collections; import java.util.Map; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.ActionProxy; import com.opensymphony.xwork2.config.entities.ResultConfig; import com.opensymphony.xwork2.interceptor.Interceptor; public class SessionCheck implements Interceptor { public void init() { } public void destroy() { } public String intercept(ActionInvocation invocation) throws Exception { ActionProxy proxy; proxy = invocation.getProxy(); Map session = ActionContext.getContext().getSession(); Map results = proxy.getConfig().getResults(); // We are checking that the user that is set at logi

Struts 2 Ajax drop down Example

Struts 2 has emerged as boon for developers. But the documentation available is very small. So I had decided to give a brief demonstration of the ajax used in struts 2.1.8.1 Libraries used: commons-beanutils-1.7.0.jar commons-fileupload-1.2.jar commons-logging-1.1.jar commons-logging-api-1.1.jar freemarker-2.3.8.jar struts2-core-2.1.8.1.jar struts2-dojo-plugin-2.1.8.1.jar xwork-core-2.1.6.jar In this example when u select from one drop down the other will populate accordingly. You can use it as it is or play with it. Enjoy !! index.jsp <%@ taglib prefix="s" uri="/struts-tags" %> <s:action name="ListingAction" executeResult="true"></s:action> listing.jsp <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix="sx" uri="/struts-dojo-tags"%> Listing detail.jsp <%@ taglib prefix="s" uri="/struts-tags"

Struts2

Struts 2 is a new framework for the java developers. It is a combination of Struts 1 + Webworks formally known as Struts Ti. It is available with the enhanced quality of code and helps developers to work in a more organized way. In built Ajax functionality is a boon for the developers. When I started working on the Struts 2. I felt that it may be very hard to learn but not actually. It is far easier then I thought. I haven’t work on other frameworks like Tapestry, Wicket, Spring etc. but I know what I am doing is good enough for me. All frameworks provide there own way of style of coding which are good in there respect. In built Interceptors provided a great functionality that helps in lots of situations. The one I like is a WaitAndExecute Interceptor. It is very helpful in situations when your action takes lots of time to execute. This interceptor displays a default page when your action is executing at background. Lots of more features are there for developers like Ajax funct