Retrieving Form data

classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Retrieving Form data

dbirtwell
It's been a while since I've  been here and even looked at the Ratpack framework.

I'm porting my old Ratpack application to handle the 0.9.0-SNAPSHOT version and am having trouble getting data from a simple html form. I looked at the Books example quickly, but it is using jquery and boostrap.

I just want to simplify things to use a simple html form, but using the following fails when used in the post handler

  Form form = context.parse(Form.class)

with the following:

No signature of method: ratpack.groovy.handling.internal.DefaultGroovyContext.parse() is applicable for argument types: (java.lang.Class) values: [interface ratpack.form.Form]

When I look (print out) at the request parameters in the scope of post("/submit"), I don't see the form's params. The request doesn't look like it stores the request parameters ... is there another way to get them?

What am I missing? Boy, Ratpack has changed a bit since I last used it ;-)

The below code snippet doesn't the post parameters as a "property":

                        request.properties.each { prop, val ->
                          println prop + " :: " + val
                        }

The form is created as follows:

<form action="/submit" method="post" accept-charset="utf-8">

  <label for="name">Name:</label>
  <input type="text" name="name">
  <br><br>
 
  <label for="item_type">Type:</label>
  <input type="text" name="item_type">
  <br><br>

  <label for="item_location_1">Location 1:</label>
  <input type="text" name="item_location_1">
  <br><br>
   
  <label for="item_location_2">Location 2:</label>
  <input type="text" name="item_location_2">
  <br><br>
 
  Description:
  <br>
  <textarea name="description" id="description" rows="3" cols="25"></textarea>
 
  <p>
    <button type="submit">Save</button>
  </p>
 
</form>
rus
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

rus

I guess one question is why 0.9.0-SNAPSHOT and not 0.9.4?

If you use the latest version do you still get the same problem?

With example-books I don't think jquery and bootstrap make a difference to the post. It's still just a form post.

On 14 May 2014 21:49, "dbirtwell [via Ratpack Forum]" <[hidden email]> wrote:
It's been a while since I've  been here and even looked at the Ratpack framework.

I'm porting my old Ratpack application to handle the 0.9.0-SNAPSHOT version and am having trouble getting data from a simple html form. I looked at the Books example quickly, but it is using jquery and boostrap.

I just want to simplify things to use a simple html form, but using the following fails when used in the post handler

  Form form = context.parse(Form.class)

with the following:

No signature of method: ratpack.groovy.handling.internal.DefaultGroovyContext.parse() is applicable for argument types: (java.lang.Class) values: [interface ratpack.form.Form]

When I look (print out) at the request parameters in the scope of post("/submit"), I don't see the form's params. The request doesn't look like it stores the request parameters ... is there another way to get them?

What am I missing? Boy, Ratpack has changed a bit since I last used it ;-)

The below code snippet doesn't the post parameters as a "property":

                        request.properties.each { prop, val ->
                          println prop + " :: " + val
                        }

The form is created as follows:

<form action="/submit" method="post" accept-charset="utf-8">

  <label for="name">Name:</label>
  <input type="text" name="name">
  <br><br>
 
  <label for="item_type">Type:</label>
  <input type="text" name="item_type">
  <br><br>

  <label for="item_location_1">Location 1:</label>
  <input type="text" name="item_location_1">
  <br><br>
   
  <label for="item_location_2">Location 2:</label>
  <input type="text" name="item_location_2">
  <br><br>
 
  Description:
  <br>
  <textarea name="description" id="description" rows="3" cols="25"></textarea>
 
  <p>
    <button type="submit">Save</button>
  </p>
 
</form>


If you reply to this email, your message will be added to the discussion below:
http://forum.ratpack.io/Retrieving-Form-data-tp417.html
To start a new topic under Ratpack Forum, email [hidden email]
To unsubscribe from Ratpack Forum, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

dbirtwell
>> I guess one question is why 0.9.0-SNAPSHOT and not 0.9.4?

The github ratpack-standalone example uses it:

https://github.com/ratpack/example-ratpack-standalone-groovy-script/blob/master/ratpack.groovy

I just tried 0.9.4 and got the following at startup:

Caught: java.lang.RuntimeException: Ratpack requires Groovy 2.3.0-rc-2+ to run but the version used is 2.2.1

I guess I'll have to update my groovy runtime and try again. I'll let you know what I see.

I haven't used Groovy much lately (I was looking into Scala and Scalatra ... didn't go too far, though).

Thanks!

Dave
rus
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

rus

Ahh ok, I'll update that project.

I recommend using the example-books build file for reference or create a new app using lazybones.

Let me know how you get on after upgrading your groovy version.

On 14 May 2014 23:18, "dbirtwell [via Ratpack Forum]" <[hidden email]> wrote:
>> I guess one question is why 0.9.0-SNAPSHOT and not 0.9.4?

The github ratpack-standalone example uses it:

https://github.com/ratpack/example-ratpack-standalone-groovy-script/blob/master/ratpack.groovy

I just tried 0.9.4 and got the following at startup:

Caught: java.lang.RuntimeException: Ratpack requires Groovy 2.3.0-rc-2+ to run but the version used is 2.2.1

I guess I'll have to update my groovy runtime and try again. I'll let you know what I see.

I haven't used Groovy much lately (I was looking into Scala and Scalatra ... didn't go too far, though).

Thanks!

Dave


If you reply to this email, your message will be added to the discussion below:
http://forum.ratpack.io/Retrieving-Form-data-tp417p419.html
To start a new topic under Ratpack Forum, email [hidden email]
To unsubscribe from Ratpack Forum, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

dbirtwell
BTW - my pages don't render with 0.9.4 and Groovy 2.3.0 (and Java 7). It seems to just try to output the screen as a file in FireFox (like it is JSON data).

I guess something changed between 0.9.0 and 0.9.4.

The version I was porting/revising used an old snapshot from July of 2013.

The github project I'm trying to port is from here:

https://github.com/dbirtwell/trackmystuff_ratpack_with_db

I wanted to simply port this, but if you look, some of the RatPack syntax has changed since then (I'm not complaining that it changed, it IS beta and I'm sure it changed for the better).

I guess I'll try to look at the example-books closer.

I though I would be able to update my old code in an hour of free time I had at work ... but I guess not.

When I figure it out, I'll update my project in GitHub and repost the link.

Thanks,

Dave
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

dbirtwell
YIKES ... switched back to my old version of Groovy, and the 0.9.0 version of RatPack and my pages render.
Still can't get the Form.

Not sure if it is Groovy or RatPack thatcaused my issue. It's possible that my RatPack syntax is not compatible with 0.9.4. I was just hacking through to update my old code (which was an early try at RatPack las summer).

I'm on XP at work.

Oh well, time for me to head home.

I'll try later.

Dave
rus
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

rus

If I get a chance I'll take a look at your code today

On 14 May 2014 23:49, "dbirtwell [via Ratpack Forum]" <[hidden email]> wrote:
YIKES ... switched back to my old version of Groovy, and the 0.9.0 version of RatPack and my pages render.
Still can't get the Form.

Not sure if it is Groovy or RatPack thatcaused my issue. It's possible that my RatPack syntax is not compatible with 0.9.4. I was just hacking through to update my old code (which was an early try at RatPack las summer).

I'm on XP at work.

Oh well, time for me to head home.

I'll try later.

Dave


If you reply to this email, your message will be added to the discussion below:
http://forum.ratpack.io/Retrieving-Form-data-tp417p422.html
To start a new topic under Ratpack Forum, email [hidden email]
To unsubscribe from Ratpack Forum, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

dbirtwell
rus:

Thanks ... if you look at the code, realize I was working with Java 6 at the time and had some firewall-related issues, so I had the RatPack and persistence ORM (GStorm) locally and didn't originally use Groory Grab/Grapes. Also, it might not be very efficient code, as it was my 1st RatPack experience and I'm only a Groovy hack (an even less proficient with Gradle, which is much nicer than plain Ant or Maven). I'm also mainly a server-side Java developer.

I just set up a project with lazybones. I was easy but it looks like by default it uses the RatPack 0.7.0 snapshot. From the command line when using gradle to build I see:

Download https://oss.sonatype.org/content/repositories/snapshots/org/ratpack-framework/netty/ratpack-core/0.7.0-SNAPSHOT/ratpack-core-0.7.0-20130313.113415-29.jar
Download https://oss.sonatype.org/content/repositories/snapshots/org/ratpack-framework/netty/ratpack-groovy/0.7.0-SNAPSHOT/ratpack-groovy-0.7.0-20130313.113509-11.jar

Also, how do I easily "untangle" JavaRx from the example-books project.

I wish there was a very basic CRUD app (possible with mocked persistence) in the RatPack examples upon which one could add what they like.

After one gets comfortable with that app, they could add the bells an whistles, session management, injection, etc.

Just my 2c, which is probably worth .01c, as I'm a RatPack/Groovy newbie.

Thanks again,

Dave
rus
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

rus
I'm not sure how Lazybones was trying to pull 0.7.0-SNAPSHOT, that's very strange.  Did you have Lazybones already installed?  Did you have internet access for it to pull the latest templates down?

I'll send you a PR soon as I can.  Take your point about having a simpler example app without any bells and whistles.


On 15 May 2014 15:52, dbirtwell [via Ratpack Forum] <[hidden email]> wrote:
rus:

Thanks ... if you look at the code, realize I was working with Java 6 at the time and had some firewall-related issues, so I had the RatPack and persistence ORM (GStorm) locally and didn't originally use Groory Grab/Grapes. Also, it might not be very efficient code, as it was my 1st RatPack experience and I'm only a Groovy hack (an even less proficient with Gradle, which is much nicer than plain Ant or Maven). I'm also mainly a server-side Java developer.

I just set up a project with lazybones. I was easy but it looks like by default it uses the RatPack 0.7.0 snapshot. From the command line when using gradle to build I see:

Download https://oss.sonatype.org/content/repositories/snapshots/org/ratpack-framework/netty/ratpack-core/0.7.0-SNAPSHOT/ratpack-core-0.7.0-20130313.113415-29.jar
Download https://oss.sonatype.org/content/repositories/snapshots/org/ratpack-framework/netty/ratpack-groovy/0.7.0-SNAPSHOT/ratpack-groovy-0.7.0-20130313.113509-11.jar

Also, how do I easily "untangle" JavaRx from the example-books project.

I wish there was a very basic CRUD app (possible with mocked persistence) in the RatPack examples upon which one could add what they like.

After one gets comfortable with that app, they could add the bells an whistles, session management, injection, etc.

Just my 2c, which is probably worth .01c, as I'm a RatPack/Groovy newbie.

Thanks again,

Dave


If you reply to this email, your message will be added to the discussion below:
http://forum.ratpack.io/Retrieving-Form-data-tp417p424.html
To start a new topic under Ratpack Forum, email [hidden email]
To unsubscribe from Ratpack Forum, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

dbirtwell
I used the lazybones 0.6 binary from https://bintray.com/pledbrook/lazybones-templates/lazybones

I've since abandoned using lazybones and am using the example-books as a starting point. I removed the JavaRX and database stuff for now.

BTW, I had to remove SpringLoaded from the dependency list in build,gradle

  // Causes a problem
  // springloaded "org.springsource.springloaded:springloaded-core:1.1.4"

and added ivy to my dependency list, as gradle complained at runtime, I didn't know which version to use, so I used one I found in an online post about adding the ivy dependency.

  // Added manually
  compile "org.apache.ivy:ivy:[email protected]"

I replaced the assets with mine an have only wired up a create action (I call it "new") and am able to retrieve the form information in the post handler ... right now ONLY if I post the form as follows in my new.html:

<form action="" method="post" accept-charset="utf-8">

I plan to create a mock object to hold a list of my Item objects and this mock class will perform all the CRUD actions.

When I finish this, I will put it on GitHub.

You guys can feel free clean it up and use it as a simple no-database example of a simple CRUD app, if you wish.

Thanks,

Dave
rus
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

rus

There should be no reason to have to remove spring loaded. What problem did it cause? Also, the version in example-books is 1.1.5 so not sure how you had to remove 1.1.4

Can you also post the error that meant you needed to include ivy? Seems very strange. You haven't got a rouge grab in there somewhere have you?

On 15 May 2014 19:16, "dbirtwell [via Ratpack Forum]" <[hidden email]> wrote:
I used the lazybones 0.6 binary from https://bintray.com/pledbrook/lazybones-templates/lazybones

I've since abandoned using lazybones and am using the example-books as a starting point. I removed the JavaRX and database stuff for now.

BTW, I had to remove SpringLoaded from the dependency list in build,gradle

  // Causes a problem
  // springloaded "org.springsource.springloaded:springloaded-core:1.1.4"

and added ivy to my dependency list, as gradle complained at runtime, I didn't know which version to use, so I used one I found in an online post about adding the ivy dependency.

  // Added manually
  compile "org.apache.ivy:ivy:[email protected]"

I replaced the assets with mine an have only wired up a create action (I call it "new") and am able to retrieve the form information in the post handler ... right now ONLY if I post the form as follows in my new.html:

<form action="" method="post" accept-charset="utf-8">

I plan to create a mock object to hold a list of my Item objects and this mock class will perform all the CRUD actions.

When I finish this, I will put it on GitHub.

You guys can feel free clean it up and use it as a simple no-database example of a simple CRUD app, if you wish.

Thanks,

Dave



If you reply to this email, your message will be added to the discussion below:
http://forum.ratpack.io/Retrieving-Form-data-tp417p426.html
To start a new topic under Ratpack Forum, email [hidden email]
To unsubscribe from Ratpack Forum, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

dbirtwell
>> There should be no reason to have to remove spring loaded. What problem did it cause? Also, the version in example-books is 1.1.5 so not sure how you had to remove 1.1.4

I revised my gradle build to use 1.1.5 and still have an issue. Below is the following error:


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':configureRun'.
> Could not resolve all dependencies for configuration ':springloaded'.
   > Could not resolve org.springsource.springloaded:springloaded-core:1.1.5.
     Required by:
         :trackmystuff_wip:unspecified
      > Could not GET 'http://repo.springsource.org/repo/org/springsource/spring
loaded/springloaded-core/1.1.5/springloaded-core-1.1.5.pom'. Received status code 401 from server: Unauthorized

below id my complete build.gradle file, including the commented out areas. Remember, I'm just learning Gradle

==== Begin contents ==>

buildscript {
  repositories {
    maven { url "http://oss.jfrog.org/artifactory/repo" }
    jcenter()
  }
  dependencies {
    classpath 'io.ratpack:ratpack-gradle:0.9.4'
  }
}

apply plugin: "ratpack-groovy"
apply plugin: "idea"
apply plugin: "eclipse"

repositories {
  maven { url "http://oss.jfrog.org/artifactory/repo" }
  jcenter()
  maven { url "http://repo.springsource.org/repo" }
  maven { url "https://nexus.codehaus.org/content/repositories/snapshots/" }
}

dependencies {
  // springloaded "org.springsource.springloaded:springloaded-core:1.1.5"
  //compile "io.ratpack:ratpack-h2:0.9.2-SNAPSHOT"
  //compile "io.ratpack:ratpack-jackson:0.9.2-SNAPSHOT"
 
  // Added manually
  compile "org.apache.ivy:ivy:[email protected]"
  testCompile "org.spockframework:spock-core:0.7-groovy-2.0", {
      exclude module: "groovy-all"
  }
  testCompile "org.gebish:geb-spock:0.9.2"
  // Required for mocking multi arg constructor e.g. BookService
  testRuntime "org.objenesis:objenesis:1.2"
  testCompile "org.seleniumhq.selenium:selenium-firefox-driver:2.37.1"
  //compile "io.ratpack:ratpack-remote:0.9.2-SNAPSHOT"
  //testCompile "io.ratpack:ratpack-remote-test:0.9.2-SNAPSHOT"
  //compile "io.ratpack:ratpack-codahale-metrics:0.9.2-SNAPSHOT"
  //compile "io.ratpack:ratpack-rx:0.9.2-SNAPSHOT"
}

// The Groovy that rest-assured drags in via ratpack-groovy-test is toxic, prevent it from coming in
// This should be fixed upstream in Ratpack
configurations.testCompile.dependencies.find { it.name == "ratpack-groovy-test" }.exclude(group: "org.codehaus.groovy")

Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

dbirtwell
BTW, how do I use one of my Groovy classes in the template. The class lives in:

src\main\groovy\ratpack\example

and is imported in my Ratpack.groovy script. I can access it there, but if I do something like the below

<%
def itemList = new ArrayList()
%>

The template does not fail, but if I do

<%
def itemList = new ArrayList()

def item = new Item()
o
o
o

%>

The template has issues which manifests as routing gets messed up (not being found). It seems like the template cannot find my Groovy class.

Do I need to register my own classes?

Thanks,

Dave


rus
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

rus
The Spring Loaded problem is that you are getting a 401 from Spring's Maven repository.

I've had a quick go at updating your project to the latest Ratpack version and this is what I have
https://github.com/rhart/trackmystuff_ratpack_with_db

It's still not quite what I would do but you can see the changes and what the api changes are.

You also shouldnt be doing so much "code" in your templates, they are the view.  Try doing it at the server and giving as the model.

Hope this helps.
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

dbirtwell
Thanks. I'll have a look at what you did.

I will also look at putting data in the model.

What the correct way to do this in RatPack?

Thanks again for your help!!!

Dave
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

dbirtwell
Never mind, it looks like you already did it in the example.

Thanks!
rus
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

rus
In reply to this post by dbirtwell

Take a look at the root handler in my example. Notice how the list of items is supplied as the model to the template.

Also notice how I'm doing all database interaction off the main thread as it's blocking io

On 15 May 2014 23:26, "dbirtwell [via Ratpack Forum]" <[hidden email]> wrote:
Thanks. I'll have a look at what you did.

I will also look at putting data in the model.

What the correct way to do this in RatPack?

Thanks again for your help!!!

Dave


If you reply to this email, your message will be added to the discussion below:
http://forum.ratpack.io/Retrieving-Form-data-tp417p431.html
To start a new topic under Ratpack Forum, email [hidden email]
To unsubscribe from Ratpack Forum, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

dbirtwell
rus:

Thanks a ton. The persistence is much cleaner than I did, but I have 1 question on that ... how would you recommend one to shut down the connection, or free resources on RatPack shutdown?

BTW I tried this with Groovy 2.3.0 and Gradle 1.12 and everthing worked fine!

I like the fact that you showed how to use "blocking" and now understand how to populate the mode (and remove logic from the view).

Also, you mentioned that this is not the way you would have done it ... how would you do this simple proof-of-concept with the following limitations?

1) Simple views without additional javascript libraries. No pagination, etc.
2) No session management or data caching.
3) Simple ORM with a single table (in the real world, this would have used a few tables with PKs in the main Item table so as not to replicate the type, locations, etc).
4) No searching, as to keep it simple.

I know it needs to have some tests added as well and will add some, as soon as I learn some modern Groovy testing techniques.

I was attempting to learn Scala recently, but learning both the Syntax and  FP all at once was hurting my head. So I figured, I go back to Groovy.I plan to get more proficient with Groovy and then try some of its FP techniques.

And then, what would you add if you wanted to make it a full-blown application ... other than go to Grails (I might possibly move this to Grails with all the bells and whistles as an exercise)

I'm just curious, as I want to learn to develop full front-end to back-end apps in Groovy.

Thanks again for all your help and attention. I hope this thread can help others as well.

I believe RatPack has really improved a lot since I 1st looked at it.

Dave
rus
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

rus
dbirtwell wrote
how would you recommend one to shut down the connection, or free resources on RatPack shutdown?
There's an open issue for this https://github.com/ratpack/ratpack/issues/67  Meanwhile you could prob just add a JVM shutdown hook.


dbirtwell wrote
Also, you mentioned that this is not the way you would have done it ... how would you do this simple proof-of-concept with the following limitations?
With the shutdown hook and logic removed from the view I think this is fine actually.


dbirtwell wrote
I know it needs to have some tests added as well and will add some, as soon as I learn some modern Groovy testing techniques
Check out example books and the manual for testing

dbirtwell wrote
And then, what would you add if you wanted to make it a full-blown application ... other than go to Grails (I might possibly move this to Grails with all the bells and whistles as an exercise)
It depends on what the application needs to do really.  For a simple app this is full-blown :)  What were you thinking here?  Maybe security I guess.
You can also easily build "full-blown" apps with Ratpack, you don't need to move to Grails for that.  It really does depend on what you're doing.
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving Form data

dbirtwell
rus:

Thanks!

I'm going to look at the books example and read up a bit on tests and add some.

I'm going to play a bit more with RatPack before moving to Grails.

I agree with you that there are a lot of things one can do with RatPack without the need for a full-stack Grails app.

Ok, I've created enough chatter on this one thread

Later,

Dave
12