• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

How to use Modelattribute when redirected from controller

 
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is a follow up question for: Old Question on coderanch, but since it's basicly a different question I opened a new post.

I descided to go in an other direction and seperate the forms to use their own controller, simply cause I think it's better practice.
They way I see it the wrapperform which contains the data for the General- and addresstable is called first, in the controller the generalobject is being created and saved to the db, then I redirect from that controller to the next form, where the last entry of the Genr
eraltable is queried and updated with the new entity.

But if I call the next form by the name of the jsppage the Form isn't added as a modelattribute and I get an error telling me that there is neither a bindingresult nor a modelattribute for the form.

If I put the getmethod of the next form in the previous controller en call the method instead of the jsppage, the view is shown, so I'm being redirected, but my post method dosn't work anymore.

I could fix this by using a menu to open each new form, but I don't feel like that's verry userfriendly and there's room for falsdata by the user.

How to I redirect from one controller to the next without using a menu or a button to call the new controller?

I Once again included the code.

GeneralEntity:


Invoice.jsp:


GeneralController:


InvoiceController:


GeneralRepo:


I didn't include newRecord.jsp since the first form correctly saves to the address- and generaltable
 
Master Rancher
Posts: 451
6
IntelliJ IDE Spring Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you want to redirect to an endpoint you have it return like this:
return "redirect:/endpointName";

otherwise it will return the jsp which is what it sounds like it happening.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That didn't really answer my question, not by a long shot.
I know how to redirect, my question was and remains if I redirect how come my postmethod isn't called when I submit the form.
 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are returning :
       return "invoices";

while you named your jsp page as "invoice.jsp"    
is it a typo here?
 
Saloon Keeper
Posts: 5561
143
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:if I redirect how come my postmethod isn't called when I submit the form.


I know little of the Spring mechanisms involved, but an HTTP redirect will always be a GET, not a POST. Does Spring not have some kind of forwarding mechanism that obviates the need of an HTTP-level redirect?
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a Getmethod, which bind the model with the entity and returns the form to fill the fields.
From in that form when I submit, it should call the postmethod...
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:
I know little of the Spring mechanisms involved, but an HTTP redirect will always be a GET, not a POST. Does Spring not have some kind of forwarding mechanism that obviates the need of an HTTP-level redirect?



You're kinda right, I tried forwarding instead of redirecting, but then the postmethod is directly called, whithout showing the form first.
The invoiceObject is created and saved to the db, but the user dosn't get the chance to fill in the fields.
How do I call the getmethod first to show the file, while still being able to post it afterwords, it seems to be one or the other
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!