Play Framework 2.0 quicktip: ¿cómo obtener un valor POST desde un controller?


Suena tonto, pero me llevó varios minutos y no lo encontré en la documentación online. Creo que es algo bastante común.

Quiero acceder a un valor POST simple desde un controller en Play Framework 2.0…

En este caso el atributo “filter”:

String filter = request().body().asFormUrlEncoded().get(“filter”)[0];

Eso es todo.

Tip Play Framework 2.0: how to get a single POST value?

Sounds silly, but I spent some minutes on it and couldn’t find anything in the online documentation. I think it’s quite common.

I want to get a single POST value from controller in Play Framework 2.0

In this case the attribute is called “filter”:

String filter = request (). Body (). AsFormUrlEncoded (). Get (“filter”) [0];

That’s it.

———————————————————–

Play Framework Main Site: http://www.playframework.org/

Play Framework Latam Blog: https://playlatam.wordpress.com/

Play Framework Google Groups:

Source: http://blog.palamago.com.ar/2012/04/tip-play-framework-2-0-como-obtener-un-valor-post-desde-un-controller/

One response to this post.

  1. Posted by alangreid on 10 April, 2012 at 19:26

    Another way I found is calling form().bindFromRequest().get(“firstName”) for instance. It was a nightmare to find and it’s really silly not just have a params() method that does the trick…

    Reply

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

%d bloggers like this: