Scala, Stripes simple example

Here’s the sample Stripes application using Scala.

The skeletal implementation of Stripes ActionBean for the purposes of our project holding the context:

package com.dimitrisli.scalastripeswebapp.controller

import net.sourceforge.stripes.action.{ActionBeanContext, ActionBean}
import reflect.BeanProperty


class BaseActionBean extends ActionBean {

  @BeanProperty var context: ActionBeanContext = _

}

The calculator represented as a Stripe action bean:

package com.dimitrisli.scalastripeswebapp.controller

import net.sourceforge.stripes.action._
import net.sourceforge.stripes.validation.{SimpleError, ValidationErrors, ValidationMethod, Validate}
import reflect.BeanProperty


class CalculatorActionBean extends BaseActionBean {

  @BeanProperty @Validate(required=true) var numberOne: Double = _
  @BeanProperty @Validate(required=true) var numberTwo: Double = _
  @BeanProperty var result: Double = _

  @DefaultHandler
  def addition: Resolution = {
    result = getNumberOne + getNumberTwo
    new ForwardResolution("/index.jsp");
  }

  def division: Resolution = {
    result = getNumberOne / getNumberTwo
    new ForwardResolution("/index.jsp");
  }

  @ValidationMethod(on=Array("division"))
  def avoidDevideByZero(errors: ValidationErrors): Unit =
    if (getNumberTwo == 0)
      errors.add("numberTwo", new SimpleError("Dividing by zero is not allowed."))
}

Our view represented by a JSP will be excluded due to formatting issues in WordPress (look below for the Github repository).

The web.xml setting up the Stripe’s dispatcher servlet, filter and all the necessary mappings will also not be presented due to the same xml formatting issues (look below for the Github repository).

This project’s code can be found in this Github repository

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s