Vaadin and Scala

I’ve just discovered Vaadin, and it would be perfect for project we are starting. My team has already transitioned to Scala 2.10 for just about all of our projects. I see that Scaladin 3.0 is not a release version, but is it feature complete, even if not completely stable? We don’t mind finding and reporting bugs, but we’d rather not start in on v2.0. Thanks.

Can someone please post an update on Scaladin 3.0?

Is it under active development? Estimated completion?

Is it ok to use now (if compile)?

It’s ok to use Scaladin 3.0 even it’s not released. Scaladin 3.0 compiles and works against Vaadin 7.1. You don’t need to compile Scaladin 3.0 by yourself, you can use:

resolvers += "Scaladin Snapshots" at "http://henrikerola.github.io/repository/snapshots/"

libraryDependencies += "vaadin.scala" %% "scaladin" % "3.0-SNAPSHOT"

-Henri

You should also check out the sbt-vaadin-plugin https://github.com/henrikerola/sbt-vaadin-plugin from the same Scaladin Snapshots repo.

We have been using Scaladin 3 snapshot and Vaadin 7.1.x in our production applications for some a while now, no problems with Scaladin.

  • Matti

Thank you very much Henri and Matti, will follow your directions.

Any reason why Scaladin 3 is not released? Is it just effectively in beta?

Hey everyone,

first, thank you for your great work of making Vaadin usable in Scala!

While looking through the source I noticed that there are only a very few implicit conversions, which was suprising for a “wrapper library”. I am much interested in the rationale behind the decision not to use the
pimp my library
pattern (As also suggested by Helder Batista above). Using this pattern large parts of the wrappers could be implemented transparent to the user, so transitioning to the the library from ordinary Scala code could be done with ease. In addition to that, maintenance could be easier (just a guess) since there is no need to reproduce the inheritance tree in the wrapped classes.
I see the problem, that implicit resolution is hard to understand, especially for novices. Reducing the use of implicits to this idiomatic pattern might be feasible for beginners.

I put together a
small example
how the implementation and usage could look like - building on the “pimp my library” pattern.

Cheers,

Jonathan

Hi Jonathan,

Thank you for the interest!

The problem with the “pimp my library” pattern you demonstrate is that there are both original Java style methods and added Scala style methods directly available for the developer. With the approach we took in Scaladin, we wanted to provide pure and clean Scala API. With our approach the user would only need import stuff from org.vaadin.scala._ so it’s very clear to use.

BR,

-Henri

Hi, Thanks for Scaladin. Do you have plans to develop it further? One idea I use is this:

[code]
trait Reset { self: Property[_]
=>
def reset = value = None
}

trait TextReset extends Reset { self: Property[String]
=>
override def reset = value = “”
}

val firstNameField = add(new TextField with TextReset { caption = “First Name” })
val lastNameField = add(new TextField with TextReset { caption = “Last Name” })

val birthdayField = add(new PopupDateField with Reset { caption = “Birthday” })

def clear {
root filterRecursive(.isInstanceOf[Reset]
) map (
.asInstanceOf[Reset]
) foreach (_.reset)
}
[/code]The idea is to have a trait to mark resetable fields with and then it is very convenient to clear the form.

Hi, is it possible to use scaladin with spring?

I’m trying to create a view in scala using scaladin and integrate it with spring via springvaadinintegration addon, but I’m getting an IllegalArgumentException when I try to access the view.

In my project I have a Java UI:

@Scope("prototype")
@Component(value="ui")
@PreserveOnRefresh
public class MyUI extends UI{
       
    private DiscoveryNavigator navigator;

    @Override
    protected void init(VaadinRequest request) {
        
        navigator = new DiscoveryNavigator(this, this);
    }
}

Then I have some Java views (which work well) like this one:

[code]
@Component
@Scope(“prototype”)
@VaadinView(“main”)
public class AView extends VerticalLayout implements View{

@Autowired
private aRepository MyRepository;


@Override
public void enter(ViewChangeEvent event) {
    //view content
}

}
[/code]But when I try to access a scala view like so:

[code]
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Component
import ru.xpoft.vaadin.VaadinView
import vaadin.scala.BeanItemContainer
import vaadin.scala.Table
import vaadin.scala.VerticalLayout
import com.fdariasm.siac.repositories._
import scala.collection.JavaConverters._
import vaadin.scala.Navigator.View
import vaadin.scala.Navigator.ViewChangeEvent

@Component
@Scope(“prototype”)
@VaadinView(“scalaciudades”)
class CiudadesView () extends VerticalLayout with View{

val ciudades = List()

val table = new Table{
caption = “Ciudades”
sizeFull;
container = new BeanItemContainer(ciudades)
visibleColumns = Seq(“codCiudad”, “nombre”)
}

components += ( table )

override def enter(event: ViewChangeEvent): Unit = {}
}
[/code]I’m getting the error, the stacktrace is:

java.lang.IllegalArgumentException: Trying to navigate to an unknown state 'scalaciudades' and an error view provider not present at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:528) at ru.xpoft.vaadin.DiscoveryNavigator.navigateTo(DiscoveryNavigator.java:198) at com.vaadin.ui.UI.doInit(UI.java:630) at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:223) at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:73) at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37) at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1390) at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) Am I doing something wrong or is not possible this way?.

Hello Everybody,

I am a beginner scala, vaadin ( scaladin ) user and would love to be able to deploy a scaladin app to heroku

Is there anyone who could please help ? for example create a g8 template or any other way they see fit ?

I really Hope someone will respond.

Thank you

I am writing an app using scaladin and was wondering about the future of scaladin too.

Is there a way to make case classes work with forms without writing much code?

Yes, it’s possible:

case classs Test(
  @BeanProperty var id: Int,
  @BeanProperty var name: String
)

Thanks, Lukasz!

What is the best way in Scala world to validate models? I decided to try out java class BeanValidator:

validators += { (elem: Option[Any]
) ⇒
        Validator(new BeanValidator(classOf[Shop]
, "name")).validate(elem)
      }

but it fails with exception:

SEVERE: 
javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.

    at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:271)

    at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:110)

    at com.vaadin.data.validator.BeanValidator.getJavaxBeanValidatorFactory(BeanValidator.java:167)

    at com.vaadin.data.validator.BeanValidator.getJavaxBeanValidator(BeanValidator.java:182)

    at com.vaadin.data.validator.BeanValidator.validate(BeanValidator.java:115)

    at vaadin.scala.Validator$$anon$2$$anonfun$1.apply$mcV$sp(Validation.scala:63)

    at vaadin.scala.Validator$$anon$2$$anonfun$1.apply(Validation.scala:63)

    at vaadin.scala.Validator$$anon$2$$anonfun$1.apply(Validation.scala:63)

    at scala.util.control.Exception$Catch$$anonfun$withTry$1.apply(Exception.scala:129)

    at scala.util.control.Exception$Catch$$anonfun$withTry$1.apply(Exception.scala:129)

    at scala.util.control.Exception$Catch.apply(Exception.scala:102)

    at scala.util.control.Exception$Catch.withTry(Exception.scala:129)

    at vaadin.scala.Validator$$anon$2.validate(Validation.scala:63)

In build.sbt I have these:

"javax.validation" % "validation-api" % "1.1.0.Final",
"org.hibernate" % "hibernate-validator-annotation-processor" % "5.1.1.Final"

Maybe, You should use

hibernate-validator

dependency

Yep, added these and it worked!

I will try to use bean validators then :slight_smile:

"org.hibernate" % "hibernate-validator" % "5.1.1.Final",

  "javax.el" % "javax.el-api" % "2.2.5",

  "org.glassfish.web" % "javax.el" % "2.2.6",

Although there was a little trick to make the annotations work:

import scala.beans.BeanProperty
import javax.validation.constraints.NotNull
import javax.validation.constraints.Size
import scala.annotation.target.field

case class Shop(
  @BeanProperty var id: Option[Long]
 = None,
  @(NotNull @field)@(Size @field)(min = 1, max = 255)@BeanProperty var name: String,
  @BeanProperty var address: String) {
}

Hi, I was just trying to use org.tepi.filtertable.FilterTable.
I have compiled it and tried to just simple replace regular Table with FilterTable in some example.
But I am getting:

[error]
 \VaadinScalaUI.scala:24: inferred type arguments [org.tepi.filtertable.FilterTable]

do not conform to method add's type parameter bounds [C <: vaadin.scala.Componenton

on:

[code]
val table = new FilterTable {
addContainerProperty(“Test”, classOf[String]
, None)

}

content = new VerticalLayout {

add(table, ratio = 1)

}
[/code]Would somebody give me a hint what should I do?

Is there likely to be an update to Scaladin for Vaadin 7.5.x?

Thanks.

Hi there,

Is there a Scaladin way to use SQLContainer and TableQuery/FreeformQuery?

Thank you!