Sunday, November 16, 2008

Struts 2.0 and Scala

Recently I tried to do some Scala code with Struts 2.0. Unfortunately Scala can't handle nested annotations (yet) so some stuff will be quite hard. You can download the whole project here. Nevertheless, let's get started:

The core is the Scala code which looks like:
    1 import com.opensymphony.xwork2.ActionSupport;
2
3 package edu.ucsd.extension {
4 class HelloWorldAction extends ActionSupport {
5 @scala.reflect.BeanProperty
6 private var name: String = "bubba"
7
8 val SUCCESS = "success";
9
10
11 override def execute(): String = {
12 SUCCESS;
13 }
14 }
15 }



The nifty thing about scala is that the annotation @scala.reflect.BeanProperty saves you all the getters and setters. The sad thing is I couldn't figure out how to access the SUCCESS constant from the parent class so I made it a constant inside scala with didregarding the scala naming conventions. You could also leave the execute method out since the parent class' default implementation returns SUCCESS but I wanted to show it anyway.

The rest of the app relies on zeroconf and code behind -- so there is no configuration and once compiled you can access this action as helloWorld (zeroconf) -- the success will render helloWorld-success.jsp (code behind)


2 Comments:

Anonymous Anonymous said...

Greetings,

This is a question for the webmaster/admin here at gman.eichberger.de.

Can I use part of the information from this blog post above if I provide a backlink back to your website?

Thanks,
Peter

7:20 AM

 
Anonymous Anonymous said...

Hi there,

Thanks for sharing the link - but unfortunately it seems to be down? Does anybody here at gman.eichberger.de have a mirror or another source?


Thanks,
James

6:18 AM

 

Post a Comment

<< Home