You did not find the page google led you to? Read on:

Featured

I recently moved my blog from serendipity to wordpress (see here for more: moving from serendipity to wordpress). This changed all my links, what is kind of sad if you come here from a search engine, linking to the old url-style from serendipity.

Please use the search from wordpress in the top right to find your post. It’s still here, i promise, just under a different url.

time field in extjs4 returning 310008e with json datastore and jackson

Currently i am trying to connect extjs datagrid via a extjs datamodel to a rest backend in java.
It works great so far, however, i have a java.util.Date column which serializes to javascript millitime format, which can be read by the datastore with the format: ‘time’ option.

However, if you try to store an updated value of your row, the datastore will convert your date to “310008e”, which cannot be parsed into a date.

There are several options to solve this issue. One would be to write a converter for the extjs model, another one is to write a serializer class which implements JsonSerializer<T> and annotate the datefield with it.

I found this solution here: http://loianegroner.com/2010/09/how-to-serialize-java-util-date-with-jackson-json-processor-spring-3-0/
There are some other options as well, please have a look in the comments of the linked blog post.

samsung galaxy s2 cannot connect to pc via usb

Hi,
i own a galaxy S2 and some day i couldn’t connect to my pc anymore via usb. Windows/Linux, different machines, nothing worked.
On my hunt throught the internet i found some forums stating that there are problems known with the usb port of the S2, so i ordered a new one and replaced it, but that did not help either.

Finally i found this blog post: http://www.bitblokes.de/2012/04/losung-samsung-galaxy-s2-verbindet-sich-nicht-als-massenspeicher/
There it is said you have to enter the following number: *#7284# and then change from MODEM to PDA or maybe from PDA to MODEM and back.

That’s it, it does work again now. Seems to be a bug within the firmware. A pity i have not found it earlier and had to buy a new usb port w/o really having the need to.

eclipse juno, maven, spring 3 and deployment to tomcat

Hi,

i recently tried the above combination for a prototype and all of a sudden the following error appeared:

Schwerwiegend: 1.5.0/docs/api/java/lang/Error.html">Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
	at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532)
	at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514)
	at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:133)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4727)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
	at java.util.concurrent.1.5.0/docs/api/java/util/concurrent/FutureTask.html">FutureTask$Sync.innerRun(Unknown 1.5.0/docs/api/javax/xml/transform/Source.html">Source)
	at java.util.concurrent.1.5.0/docs/api/java/util/concurrent/FutureTask.html">FutureTask.run(Unknown 1.5.0/docs/api/javax/xml/transform/Source.html">Source)
	at java.util.concurrent.1.5.0/docs/api/java/util/concurrent/ThreadPoolExecutor.html">ThreadPoolExecutor.runWorker(Unknown 1.5.0/docs/api/javax/xml/transform/Source.html">Source)
	at java.util.concurrent.1.5.0/docs/api/java/util/concurrent/ThreadPoolExecutor.html">ThreadPoolExecutor$Worker.run(Unknown 1.5.0/docs/api/javax/xml/transform/Source.html">Source)
	at java.lang.1.5.0/docs/api/java/lang/Thread.html">Thread.run(Unknown 1.5.0/docs/api/javax/xml/transform/Source.html">Source)

It took me some time to figure out what happened, but somehow my project settings changed.
To fix this error go to projects properties  -> deployment assembly and add the maven dependencies there to be mapped to WEB-INF/lib.

That’s it, quick fix for a weired thing like change of the settings -.-

integrate circumflex-orm into play 2.0 using scala

If you are like me and dont want to use the proposed orm anorm in play 2.0, you may want to use circumflex-orm (http://circumflex.ru/projects/orm/index.html) i give you a quick howto on the integration.

First, create a cx.properties in the conf folder of your project:

orm.connection.driver=com.mysql.Driver
orm.connection.url=jdbc:mysql://localhost/database
orm.connection.username=un
orm.connection.password=pw

Also add the dependency to your Build.scala file:

val appDependencies = Seq(
  "ru.circumflex" % "circumflex-orm" % "2.1"
)

Then create the class and it’s object:

class Task extends Record[Long, Task] with IdentityGenerator[Long, Task] {
  def this(name: String, description: String) = {
    this()
    this.name := name
    this.description := description
  }
 
  val id = "id".BIGINT.NOT_NULL.AUTO_INCREMENT
  val name = "name".VARCHAR(255).NOT_NULL
  val description = "description".TEXT.NOT_NULL
 
  def PRIMARY_KEY = id
  def relation = Task
}
 
object Task extends Task with Table[Long, Task] {
  def apply(name: String, description: String) = new Task(name, description)
  def unapply(t : Task) = Option(t.name(), t.description())
}

For more info about the fields and the usage of circumflex, look at the docs at their homepage please.

Finally you can retrieve with get for instance, it works without any additions.

val task = Task.get(1).get
println("name" + task.name())

But to save and insert you have to promote a context:

val task = new Task("foo","bar")
  Context.executeInNew {ctx =>
    println(task.save())
}

According to a gentle guy from circumflex this should belong into a filter, which must be put somewhere in the lifecycle usage of your app.
Please have a look at the google group discussion for more information about that:
https://groups.google.com/forum/?fromgroups#!topic/circumflex-scala/ma2uCVgPx1Q
But thats a topic for another day.

Easy, isn’t it? In the end i still could use anorm, or something similar besides it, if i need some complex sql’s to get done, but, as far as i can tell, circumflex should suffice for most of them.

Update:
Well, transaction management was no topic for another day. It turned out that without the Context from circumflex cache management did not work.

It is possible to save and retrieve, but, retrieval happens from the cache, and without the transaction-management the cache does not get updatet.

So, what you have to do is write your own action class like this:

import play.api.mvc.Action
import play.api.mvc.Request
import play.api.mvc.Result
import ru.circumflex.core.Context
 
case class ScircumflexOrmActionWrapper[A](action: Action[A]) extends Action[A] {
 
  def apply(request: Request[A]): Result = {
    Context.executeInNew { ctx =>
      action(request)
    }
  }
 
  lazy val parser = action.parser
}

And then call it like that:

def index = ScircumflexOrmActionWrapper { Action {
 
	val taskDbObj = Task AS "taskDb"
	val tasks = SELECT(taskDbObj.*).FROM(taskDbObj).ORDER_BY(taskDbObj.createdAt DESC).list
 
	Ok(html.task.index(tasks))
  }}

Now you should have a working solution.

Formbinding multiple objects of the same type in play framework 2 with scala

The play docs provide small code snippets on how to use repeated values with form binding, but they make not clear on how to bind to a List of objects. In the end it’s easy.

Let’s say we have these two classes:

case class Task(name: String, description: String)
case class Tasks(tasks: List[Task])

Then we can make a Form val like this:

val taskForm: Form[Tasks] = Form(
      mapping(
          "tasks" -> list(mapping(
              "name" -> text,
              "description" -> text
          )(Task.apply)(Task.unapply))
      )(Tasks.apply)(Tasks.unapply)
  )

The html would look like this:

<tr>
  <td><input name="tasks[0].name" type="text" ></td>
  <td><textarea name="tasks[0].description" ></textarea>
  </td>
</tr>
<tr>
  <td><input name="tasks[1].name" type="text" ></td>
  <td><textarea name="tasks[1].description"></textarea>
  </td>
</tr>

And the retrieval as stated in the docs:

val tasks = taskForm.bindFromRequest.get

gives back a list of tasks with a task object inside for each table row.

I admit that my table is not a normal form, instead i use jquerys .serializeArray() on the table to submit the data via $.ajax(), but that’s a different story.

See also this question at stackoverflow from me:
http://stackoverflow.com/questions/10218814/bind-multiple-objects-in-play-framework-2-0-from-a-form/10223431#10223431

ERROR context.GrailsContextLoader while trying to save in grails

If you get the error:
ERROR context.GrailsContextLoader  – Error executing bootstraps: null
Message: null
while trying to save something in grails 2, go ahead and make use of the nice: failOnError option the save method gives you (http://grails.org/doc/2.0.x/ref/Domain%20Classes/save.html).

It will produce a much better output regarding what is wrong, in my case it showed me that i forgot to set a needed variable in my class before i tried to save it.

A nice guy in the mailing list pinpointed me to this one (http://grails.1312388.n4.nabble.com/Error-executing-bootstraps-null-with-springsecurity-plugin-td4554560.html).

play 2.0 formbind validation exception

If you get the following error: [ValidationException: Call to TraversableResolver.isReachable() threw an exception] when you try to do a formbind with play 2.0 framework:
Form<Task> tasks = taskForm.bindFromRequest();
Then you should check if your class Task has getters and setters for the variables you need, the springbind library play relies on needs them to work.

defining variables in playframework 2.0 templates

Today i found out how to define variables in play’s templates. I would say play does not go the common way, instead it uses a functional approach. So to define a new variable you have to do something like:

@defining(User.getLoggedinUser()) {user =>
  <h1>hello @user.getName(), @user.getPrename()</h1>
}

So basically the variable user references to the result of User.getLoggedinUser(), which is an object in this case and can only be used in the defined scope of the {}.

 

two pitfalls with play framework 2 templates i ran into

On my journey through the play framework 2 i ran into two pitfalls in the last days, that are easily solved.

  1. calling a template from a template with a white space (@navigation_top ()) between the template name and it’s paranthesis results in a message like: BaseScalaTemplate(play.api.templates.HtmlFormat$@3424b1d9) ()
    just showing the plain class output, to circumvent this you have to leave out the white space: @navigation_top()
  2. templates from the views package can be referenced without the package name in the template like above: @navigation_top() calls the navigation_top template and includes it.
    But if you add a subpackage and a template within you have to call it with the full package name.
    So a template navigation_top in views.navigation has to be included with:
    @views.html.navigation.navigation_top()

twitter bootstrap 2.0.2 broke play 2.0 support

I just tried to get the twitter bootstrap lib running with play 2.0, but received an error, irc guys told me that the new twitter bootstrap broke the play support. This is the message:
EcmaError: TypeError: Cannot call method “charAt” of undefined (less-1.2.1.js#338)

I worked around it by using the 2.0.1 of bootstrap, the nice guy at the irc told me that the git version of play has it fixed already.

Btw. there is a nice and short tutorial to get bootstrap running with play:
https://plus.google.com/u/0/108788785914419775677/posts/QgyUF9cXPkv