1

Temat: Przerzucenie obiektu osoby do hiddenField

Cześć!

Napisałem swoją pierwszą, prosta aplikacje emulującą portal z recenzjami do gier. To co z czym mam problem że mam klasę domenową Recenzja która należy ( belongsTo ) Person ( jako autor recenzji ) generowanej z Acegi Plugin ( obie klasy zamieszczam poniżej ). Kiedy chce utworzyć nowa Recenzje ( po przez Create ), aplikacja twierdzi wiele rzecz, ale najczęściej ten error wywala:

Failed to convert property value of type java.lang.String to required type Person for property autor; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [Person] for property autor: no matching editors or conversion strategy found

Chce by aplikacja wzięła i użyła z Acegi zmiennej loggedInUserInfo(field:'username'),by dać recenzjom poprawnego autora jako usera, oczywiście, jako hiddenField. Może ktoś mi pomóc?

class Person {
    static transients = ['pass']
    static hasMany = [authorities: Authority, recenzje: gameaddict.Recenzja, komentarze: gameaddict.Komentarz ] // Każdy użytkwnik może wrzucic wiele recenzji i komentarzy
    static belongsTo = Authority
        /** Username */
    String username
    /** User Real Name*/
    String userRealName
    /** MD5 Password */
    String passwd
    /** enabled */
    boolean enabled

    String email
    boolean emailShow

    /** description */
    String description = ''

    /** plain password to create a MD5 password */
    String pass = '[secret]'

    static constraints = {
        username(blank: false, unique: true)
        userRealName(blank: false)
        passwd(blank: false)
        enabled()
    }

        String toString(){
        username
        }
}



package gameaddict

class Recenzja {
    static hasMany = [ komentarze : Komentarz ]
    static belongsTo = [autor: Person]
    String tytul
    Date dateCreated
    Date lastUpdated
    String tresc

    static mapping = {
        tresc type: "text"
    }

    static constraints = {
        tytul()
        autor()
        tresc(maxSize:50000)
        dateCreated()
        lastUpdated()
    }   
    
}

No i oczywiście samo wywołanie w formularzu do stworzenia Recenzji. wink

<tr class="prop">
                                <g:select name="autor" from="${Person.list()}" optionKey="id" value="${recenzjaInstance?.autor?.id}" />
                            </tr>

Ktoś może mi z tym pomóc?

Ostatnio edytowany przez wyrdhamster (2010-06-11 08:00:34)

2

Odp: Przerzucenie obiektu osoby do hiddenField

<g:select name="autor.id" from="${Person.list()}" optionKey="id" value="${recenzjaInstance?.autor?.id}" />

Stawiam, że brakuje id w nazwie pola.