codabat (8) [Avatar] Offline
#1
Hi,
i'm trying to do "course manager" tutorial. But after have create scaffold controller, creating tag from tags form I obtain the error http 400 (bad request). The creation others entity works correctly...
Have you any ideas?
Thank you

Lorenzo
ken.rimple (246) [Avatar] Offline
#2
Re: Course manager http bad request (error 400)
I'll need more information from you. Can you:

A) copy/paste the entire stack trace into a response from the console and the log stack trace from the web page, if any.
B) tell us what version of Roo you're using
C) send us the roo.log file as well - so I see what commands you've entered

One problem that is well known is creating a field called 'tag' - if the entity is tag, you can use tag.name (name being the field) and see if that works. There is something strange (likely with Hypersonic SQL) about the name 'tag'.

Ken
codabat (8) [Avatar] Offline
#3
Re: Course manager http bad request (error 400)
You get to the heart of issue. I renamed "tag" in "name", and now the application work fine!
But I observed the property "name" is rendered in last position in the form... also menu displays the items in different order (TAG, student, instructor). is It possible to control the order? Could it depend of the configuration of persistence.xml?
I'm using HIBERNATE provider and mysql database. I'm deploying in Cloudfoundy and I'm using Spring roo 1.2.2 with Spring Tool Suite 3.1.
I noticed that in entiy class where relationships are declared "mappedBy" its form does not allow you to enter values ​​(and rightly so), but because the select option allows you to select values, creating user confusion?
Thank you very much Ken!
Merry Christmas

Lorenzo
codabat (8) [Avatar] Offline
#4
Re: Course manager http bad request (error 400)
Hi Ken,
I noticed that also the finder by "course type and rundate between" causes a bad request error. Have you got experience this problem?
My work enviroment is:
Roo 1.2.2
STS 3.1
CluoudFoundry (for deployment).
Below you can look my log.roo
Thank you very much for your attention.
Lorenzo

My log.roo:

// Spring Roo 1.2.2.RELEASE [rev 7d75659] log opened at 2012-12-02 21:17:02
project --topLevelPackage org.rooinaction.coursemanager --projectName coursemanager --java 6 --packaging WAR
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log closed at 2012-12-02 21:17:05
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log opened at 2012-12-02 21:17:15
jpa setup --database MYSQL --provider HIBERNATE
entity jpa --class ~.model.Course --testAutomatically
field string --fieldName name
field number --fieldName listPrice --type java.math.BigDecimal
field string --fieldName description
field number --fieldName maximumCapacity --type java.lang.Integer
field date --fieldName runDate --type java.util.Date --persistenceType JPA_DATE --dateFormat SHORT
enum type --class ~.model.CourseTypeEnum
enum constant --name SEMINAR
enum constant --name CREDIT
enum constant --name CONTINUING_EDUCATION
focus --class ~.model.Course
field enum --fieldName courseType --type ~.model.CourseTypeEnum --enumType STRING
perform tests
perform tests
! ls target
! dir target
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log closed at 2012-12-05 20:47:35
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log opened at 2012-12-08 14:54:10
focus --class ~.model.Course
field string --fieldName name --sizeMin 1 --sizeMax 60 --column course_name
field string --fieldName description --notNull --sizeMax 1000
field number --fieldName listPrice --type java.math.BigDecimal --decimalMin 0.0 --decimalMax 99999.99 --digitsFraction 2 --digitsInteger 5 --notNull
field number --fieldName maximumCapacity --type java.lang.Integer --min 1 --max 9999 --notNull --column max_capacity
field date --fieldName runDate --type java.util.Date --dateTimeFormatPattern dd/MM/yyyy
field enum --fieldName courseType --type ~.model.CourseTypeEnum --enumType STRING --notNull
finder list
finder list --filter name
finder add --finderName findCoursesByNameLike
finder list --depth 2 --filter courseType,runDate
finder list --depth 2 --filter user
finder list --depth 2 --filter name
finder list --depth 2 --filter courseType
finder add --finderName findCoursesByCourseTypeAndRunDateBetween
repository jpa --interface ~.db.CourseRepository --entity ~.model.Course
entity jpa --class ~.model.TrainingProgram --testAutomatically
field string --fieldName name
field set --fieldName courses --type ~.model.Course --cardinality ONE_TO_MANY --mappedBy trainingProgram
focus --class ~.model.Course
field reference --fieldName trainingProgram --type ~.model.TrainingProgram --cardinality MANY_TO_ONE
entity jpa --class ~.model.Tag --testAutomatically
field string --fieldName tag --sizeMin 1 --sizeMax 25 --notNull
field string --fieldName description --sizeMax 250 --notNull
field set --fieldName courses --type ~.model.Course --cardinality MANY_TO_MANY
focus --class ~.model.Course
field set --fieldName tags --type ~.model.Tag --cardinality MANY_TO_MANY --mappedBy courses
// [failed] focus --class ~.model.Tag
// [failed] focus --class ~.model.Tag
// [failed] focus --class ~.model.Tag
hint nt
hint
// [failed] focus --class ~.model.Tag
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log closed at 2012-12-09 23:39:29
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log opened at 2012-12-09 23:40:08
entity jpa --class ~.model.Tag --testAutomatically
field string --fieldName tag --sizeMin 1 --sizeMax 25 --notNull
field string --fieldName description --sizeMax 250 --notNull
field set --fieldName courses --type ~.model.Course --cardinality MANY_TO_MANY
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log opened at 2012-12-12 14:04:07
entity jpa --class ~.model.Person --abstract --inheritanceType TABLE_PER_CLASS
field string --fieldName firstName --sizeMin 1 --sizeMax 30
field string --fieldName lastName --sizeMin 1 --sizeMax 30
field string --fieldName middleNameOrInitial --sizeMin 1 --sizeMax 30
// [failed] field string --fieldName middleNameOrInitial --sizeMin 1 --sizeMax 30 --notNull
field string --fieldName addressLine1 --sizeMin 1 --sizeMax 60 --notNull
field string --fieldName addressLine2 --sizeMin 1 --sizeMax 60
field string --fieldName city --sizeMin 1 --sizeMax 40 --notNull
field string --fieldName stateCode --sizeMin 2 --sizeMax 2 --notNull
field string --fieldName postalCode --sizeMin 1 --sizeMax 10 --notNull
field string --fieldName emailAddress --sizeMax 80 --notNull
entity jpa --class ~.model.Student --extends ~.model.Person --testAutomatically
field string --fieldName emergencyContactName --sizeMin 1 --sizeMax 30 --notNull
field string --fieldName emergencyContactInfo --sizeMin 1 --sizeMax 80 --notNull
field string --fieldName dietaryRestrictions --sizeMax 30
entity jpa --class ~.model.Instructor --extends ~.model.Person --testAutomatically
field string --fieldName taxNumber --sizeMin 9 --sizeMax 9 --notNull
field boolean active --notNull
entity jpa --class ~.model.Offering
entity jpa --class ~.model.Offering --testAutomatically
field date --fieldName offerDate --notNull --type java.util.Date
field string --fieldName locationName --sizeMin 1 --sizeMax 80 --notNull
focus --class ~.model.Course
field set --fieldName offers --type ~.model.Offering --cardinality ONE_TO_MANY --mappedBy course
focus --class ~.model.Offering
field reference --fieldName course --type ~.model.Course --cardinality MANY_TO_ONE
focus --class ~.model.Course
focus --class ~.model.Offering
focus --class ~.model.Instructor
field set --fieldName offerings --type ~.model.Offering --cardinality ONE_TO_MANY --mappedBy instructor
focus --class ~.model.Offering
field reference --fieldName instructor --type ~.model.Course --cardinality MANY_TO_ONE
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log closed at 2012-12-14 02:16:16
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log opened at 2012-12-14 22:50:35
entity jpa --class ~.model.Registration --testAutomatically
focus --class ~.model.Student
field set --fieldName registrations --type ~.model.Registration --cardinality ONE_TO_MANY --mappedBy student
focus --class ~.model.Course
field set --fieldName registrations --type ~.model.Registration --cardinality ONE_TO_MANY --mappedBy course
focus --class ~.model.Registration
field reference --fieldName course --type ~.model.Course --cardinality MANY_TO_ONE
// [failed] field reference --fieldName course --type ~.model.Student --cardinality MANY_TO_ONE
field reference --fieldName student --type ~.model.Student --cardinality MANY_TO_ONE
field boolean --fieldName paymentMade
field boolean --fieldName attended
// [failed] database reverse engineer --schema springrooinaction --includeTables "invoice payment" --package ~.mode --testAutomatically
hint
addon list
// [failed] database reverse engineer --schema springrooinaction --includeTables "invoice payment" --package ~.mode --testAutomatically
addon search --requiresDescription "#jdbcdriver,driverclass:com.mysql.jdbc.Driver"
addon search --requiresDescription "#jdbcdriver,driverclass:com.mysql.jdbc.Driver"
// [failed] database reverse engineer --schema springrooinaction --includeTables "invoice payment" --package ~.mode --testAutomatically
// [failed] database introspect --schema no-schema-required
// [failed] database introspect --schema no-schema-required
// [failed] database reverse engineer --schema springrooinaction --includeTables "invoice payment" --package ~.mode --testAutomatically
osgi start --url file:///C:Userslvannucci.m2 epositorymysqlmysql-connector-java5.1.22mysql-connector-java-5.1.22.jar
database reverse engineer --schema springrooinaction --includeTables "invoice payment" --package ~.mode --testAutomatically
database reverse engineer --schema springrooinaction --includeTables "invoice payment" --package ~.model --testAutomatically
database reverse engineer --schema springrooinaction --includeTables "invoice payment" --package ~.model --testAutomatically
database reverse engineer --schema springrooinaction --includeTables "invoice payment" --package ~.model --testAutomatically
database reverse engineer --schema springrooinaction --includeTables "invoice payment" --package ~.model --testAutomatically
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log closed at 2012-12-15 01:28:37
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log opened at 2012-12-15 01:29:03
database reverse engineer --schema springrooinaction --includeTables "invoice payment" --package ~.model --testAutomatically
focus --class ~.model.Offering
field set --fieldName registrations --type ~.model.Registration --cardinality ONE_TO_MANY --mappedBy offering
focus --class ~.model.Registration
field reference --fieldName offering --type ~.model.Offering --cardinality MANY_TO_ONE
focus --class ~.model.Instructor
field set --fieldName offering --type ~.model.Offering --cardinality MANY_TO_MANY
focus --class ~.model.Offering
field set --fieldName instructors --type ~.model.Instructor --cardinality MANY_TO_MANY --mappedBy offerings
entity jpa --class ~.model.Invoice --testAutomatically
entity jpa --class ~.model.Payment --testAutomatically
focus --class ~.model.Invoice
field set --fieldName payments --type ~.model.Payment --cardinality ONE_TO_MANY
focus --class ~.model.Payment
field reference --fieldName invoice --type ~.model.Invoice --cardinality MANY_TO_ONE
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log closed at 2012-12-15 18:08:27
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log opened at 2012-12-15 18:18:35
entity jpa --class ~.model.Invoice --testAutomatically
entity jpa --class ~.model.Course --testAutomatically
service --entity ~.model.Course --interface ~.service.CourseService
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log closed at 2012-12-16 17:17:20
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log opened at 2012-12-23 18:06:52
web mvc setup
web mvc controller --class ~.web.TestDriveController
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log opened at 2012-12-24 15:24:08
web mvc all --package org.rooinaction.coursemanager.web
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log closed at 2012-12-24 15:43:47
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log opened at 2012-12-24 16:33:09
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log closed at 2012-12-24 19:14:23
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log opened at 2012-12-25 18:36:53
web mvc finder add --formBackingType ~.model.Course --class ~.web.CourseController
MikB (202) [Avatar] Offline
#5
Re: Course manager http bad request (error 400)
FYI, I for one am not going to read that.

It's far more useful first of all to make a edited Roo script that creates the project and if still that long post it at some place like pastebin.com.
Possibly also add your code changes as a diff patch or post the whole project somewhere if that is possible, which I assume it would be in this case as this is not an in house project.

All in the spirit of making it easy for us fellow readers to also become interested in your problem and in the case of Ken Rimple, simply making as easy as possible for him to help you out, now when you got his ear.

From my perspective: Did you write any tests?
ken.rimple (246) [Avatar] Offline
#6
Re: Course manager http bad request (error 400)
There is an easy answer here - Roo only supports finders against Active Record entities - those without repositories.

see:

https://jira.springsource.org/browse/ROO-2694
codabat (8) [Avatar] Offline
#7
Re: Course manager http bad request (error 400)
Hello,
thanks for the advice MikB, I apologize for the previous post.
I have read, Ken, your link. But, I did not understand.
findCoursesByCourseTypeAndRunDateBetween is implemented in Entity (Active Record) and is not declared with the repository pattern, as written in your book.
Maybe I'm not understanding.
To simplify your support, you can find my svn project at the following address:
https://subversion.assembla.com/svn/course_manager/
You can check out without credentials.

Thanks a lot
codabat (8) [Avatar] Offline
#8
Re: Course manager http bad request (error 400)
Hi Ken,
maybe it could be of your interest. The http error "bad request" (400), using the finder ... depends on how it is constructed the view from spring roo.

Creating scaffolds for ByCourseTypeAndRunDateBetween finder, Spring roo creates the view findCoursesByCourseTypeAndRunDateBetween.jspx and generating a date field creates two references: course_minrundate_date_format and course_maxrundate_date_format used to set the dateTimePattern (see in my svn https://www.assembla.com/code/course_manager/subversion/nodes/trunk/src/main/webapp/WEB-INF/views/courses/findCoursesByCourseTypeAndRunDateBetween.jspx?rev=3)

But in the method CourseController_Roo_Controller_Finder

CourseController.findCoursesByCourseTypeAndRunDateBetweenForm

that generates the search form calls the addDateTimeFormatPatterns (uiModel);
But the method addDateTimeFormatPatterns (uiModel) is used to set the dataTimePattern for views default CRUD for the entity Course. The method addDateTimeFormatPatterns, in fact, sets the variable course_rundate_date_format. So when you click on find button is sent to find the date in the format dd-MM-yyyy instead of dd / MM / YYYY, causing http error 400.

My first solution was to create a method (addDateTimeMinMaxFormatPatterns) in CourseController, to set the two variables and move the method findCoursesByCourseTypeAndRunDateBetweenForm directly in CourseController.

Going forward in reading your book, I could set the attribute "z" to "user-managed" and rename the two variables to "course_rundate_date_format" and leave the code generated by Spring Roo.

I do not know if what I write can be considered a bug, but it is certainly a limit of Spring roo.

I hope it will be of interest to you.

Thank you for your attention.

Lorenzo