• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

[Grails] Passing user object into hiddenField

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

I wirte my first, simple app emulating the gaming review portal. What I have problem with is that I have Reviews domain class that belongs to Person class ( as author of review ) genrated from Acegi Plugin ( both clases listed below ). When I want to create new Review, the app says many things, bnut mainly this error massage:


I want the app to take and use Acegi loggedInUserInfo(field:'username') variable, to give reviews proper author users, of course, as hiddenField. Could someone help me?



And here is the part of Review/Create view tha is resposible for taking the Author but is not working:

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Karol,

What about using hidden field for person id and then in submit action load the proper user object which you can use later in your review.

If you want to send the object through the form you will have to serialize and deserialize after.However this approach is not so secure, because user can modify the object before submission.


Jakub
 
Karol Litwinczuk
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kuba Zygmunt wrote:
What about using hidden field for person id and then in submit action load the proper user object which you can use later in your review.



I never mixed something like that in Grails - could you propose how this code should look like or at least give some function names to read more in manual?

Kuba Zygmunt wrote:
If you want to send the object through the form you will have to serialize and deserialize after.However this approach is not so secure, because user can modify the object before submission.



Well, it's only the learning app, so can be much more easier but can't you serialize data and then secure them by, I don't know, md5 for example?
 
Kuba Zygmunt
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will try to make an example:


and in view



in this case you save the bandwidth, you send only small int instead of the serialized object.
 
Karol Litwinczuk
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kuba Zygmunt wrote:


How could this be? WIth usage of loggedInUserInfo(field:'username')? Or maybe some SQL query? I never get taking session params...
 
Kuba Zygmunt
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you match person witch acegi user by username, then you can find person using GORM


BTW you can get information from acegi anytime so there is no need to pass user information, just find a proper person before you save a review
 
Karol Litwinczuk
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got idea just to remade Save function in Review ( Recenzja in polish ), but it doesn't work. Here is my code:


And here is error:

Error 500: Executing action [save] of controller [gameaddict.RecenzjaController] caused exception: No such property: Person for class: gameaddict.RecenzjaController Possible solutions: session
Servlet: grails
URI: /GameAddict/grails/recenzja/save.dispatch
Exception Message: No such property: Person for class: gameaddict.RecenzjaController Possible solutions: session
Caused by: No such property: Person for class: gameaddict.RecenzjaController Possible solutions: session
Class: RecenzjaController
At Line: [24]


Any ideas on that?
 
Kuba Zygmunt
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check packages and if controller and domain class are in different packages use import.
 
Karol Litwinczuk
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kuba Zygmunt wrote:check packages and if controller and domain class are in different packages use import.



The tree is like this:

/main-app-folder/...
/gameaddic/ Reviews
Person
...


That means that Controller of Review IS in package ( gameaddict ), but Person is in main folder of app ( in this case, in Controllers ) - how to make import to controller in package from main folders of app. Shouldn't they be ready to use in whole app, as they are in main controllers?
 
Kuba Zygmunt
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

if you use grails version 1.3.1 or newer then your domain classes will be in package named by your application. It is always better to use packages
 
Karol Litwinczuk
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kuba Zygmunt wrote:Hi

if you use grails version 1.3.1 or newer then your domain classes will be in package named by your application. It is always better to use packages



I use the packages. The problem is that I don't kno how to import class of Person that is otuside of app package into Review that is inside the package.
 
Kuba Zygmunt
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi it looks like your structure is a bit messed up.

try to sort out your folders like :


if you have a domain class put it in grails-app/domain/<package> like Review and Person .
If you want to have some classes which are not domain classes put them in src/groovy/<package>/

then you can import them in grails using import <package-name>.<className>

Regards
 
Karol Litwinczuk
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunetly, this doesn't work. Any other ideas? Th a main porblme is that Revies controller can't find the Perrsons obcjet, even where Persons Class are in the same packages.
 
Kuba Zygmunt
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's hard to tell, so if you could pack your grails-app, put somewhere, and provide a link ( through forum or PM ), then I could check it for you.

Jakub

--edit
I reviewed your files and couple of things you could improve.

1. Put 3 classes created by Acegi plugin into package 'gameaddict' or 'security' or even 'gameaddict.security' ( yours grail app ) so you wont have problems with finding them later. You can use a command like


2. to get info in controller about current user, add authenticateSerive and then use userDomain() method. eg.


I hope it helps

Jakub
 
reply
    Bookmark Topic Watch Topic
  • New Topic