search
top

Struts error reporting

Struts was using two different classes to report errors and messages back to the user: ActionErrors and ActionMessages. As the ActionErrors and ActionError classes were deprecated since 1.2.0. version I will talk now only about ActionMessages and ActionMessage.

From an action class when you need to send a message to the page all that must be done is to set it up using the ActionMessages class.

Struts ActionMessages example:

ActionMessages actionMessages = new ActionMessages();

actionMessages.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("my.error"));
saveMessages(request, actionMessages);

This error will be displayed in JSP using:

<logic:messagesPresent message="true">
<html:messages message="true" id="msg">
<bean:write name="msg" ignore="true"/>
</html:messages>

</logic:messagesPresent>

One issue to be mentioned here is that “my.error” is a key that will be used to look up message text in an appropriate message resources database, like Application.properties for example.

But if you do not need to report a generic error message you will have to use the following code:

ActionMessages actionMessages = new ActionMessages();
actionMessages.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("my.error"));
request.setAttribute("warnings", actionMessages);

This code will set up an error message under an arbitrary key and display it with the html:messages tag:

<html:messages name="warnings" id="message">
<bean:write name="message" />
</html:messages>

There are some differences to be noticed here.

  1. There is no message=”true” attribute present that signals to look up for an ActionMessage under the Globals.MESSAGE_KEY.
  2. There is no <logic:messagePresent> tag as it will not be validated.

If your error message gets constructed dynamically the ActionMessage class offers four constructors that allow message customization with up to four parameters.

So the message:

new ActionMessage("my.error", "p1", "p2", "p3", "p4")

where

my.error=You are not allowed to do {0}, {1}, {2} and {3}

will render

You are not allowed to do p1, p2, p3 and p4

JBoss 3.2 connection problem

I am developing an application using JBoss as a deployment server. After a redeploy the JBoss throws an error on me: org.jboss.deployment.DeploymentException: Connection refused: connect

The problem was in jboss.xml file:

<!DOCTYPE jboss PUBLIC
"-//JBoss//DTD JBOSS3.2//EN"
"http://localhost/jbossdtd/jboss_3_2.dtd">

After I have changed this to:


<!DOCTYPE jboss PUBLIC
"-//JBoss//DTD JBOSS 3.2//EN"

"http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">

everything has gone smoothly.

Struts and JBoss

I found myself the other day in a strange position developing a project on JBoss.

The project was based on Struts and after deployment it didn’t worked. The symptoms were this: the landing page was not updated to the version of the deployed project. Instead the browser was showing to me a page from a previous Struts based project.

After I sniff around on the Internet I found no solution to my problem :( . So I did it the hard way.

I start searching for a pattern in the JBoss behavior and I found that it cached all the files that were common between the two projects. That was because the last project was from CVS and had all the sources older then the first project I was working with. So I modified the index.jsp and after loading it into the browser (and sow it was the correct one) I’ve start to search on my hard drive all the files not older than 10 minutes. And there it was :D , c:\tmp\project_name\index_jsp.java.

So after I’ve deleted c:\tmp\project_name directory everything gone back to normal.

Struts is MVC2

Well, Struts uses the Model-View-Control Model 2 approach.

There is only one difference between Model 1 and Model 2, Model 2 architecture introduces a controller servlet between the browser and the JSP pages. And that is all.

Struts and other frameworks

I have started to learn Struts which is an open source framework for building web applications. There are some nice features in this framework and I am trying now to get a hold on them.

There are more frameworks out there in the Internet realm, some better then others. Here are some of them that I know:

For sure there are a lot more frameworks but this four are the ones I know. I will return with more on this subject.

Back to Java

Today I am reentering into the Java world.

I have changed my workplace. It has been nice and fun to work for InterAKT and to develop Dreamweaver extensions as I believe that I helped the company become the best in this market. The experience gained there was great. I have learned new technologies and I have become a better person, better team mate as I have polished my people skills under the tutor of some great colleagues.

But the time has come to return to the technology I like most: Java.

top