Model changed but b:submitToRemote does not update as expected

View: New views
9 Messages — Rating Filter:   Alert me  

Model changed but b:submitToRemote does not update as expected

by Stefan-93 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I submit a form by g:submitToRemote, but the update DIV of the page  
gets updated, but does not reflect the
changed model. If I reload the page complete, all changes appear.

On the other hand, if I g:submitToRemote again, the last change  
appears and so on.

Do I have to ask the model to invalidate and reload itself just before  
I do

        render( template:'/metaItem/itemList', bean:q )

Here, objects related to q changed.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Model changed but b:submitToRemote does not update as expected

by Stefan-93 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Really no one?

Am 07.07.2008 um 20:21 schrieb Stefan:

> I submit a form by g:submitToRemote, but the update DIV of the page  
> gets updated, but does not reflect the
> changed model. If I reload the page complete, all changes appear.
>
> On the other hand, if I g:submitToRemote again, the last change  
> appears and so on.
>
> Do I have to ask the model to invalidate and reload itself just  
> before I do
>
> render( template:'/metaItem/itemList', bean:q )
>
> Here, objects related to q changed.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>   http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Model changed but b:submitToRemote does not update as expected

by Stefan-93 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hm, my post was probably hard to read. New trial:

- g:submitToRemote submits my form as expected and the respective  
controller gets called
- The DIV specified by the 'update' attribute of g:submitToRemote gets  
updated (verified by injecting a Date in the DIV )
- The respective controller adds something to the current metaItem:  
mi.addToItem( clonedItem ).save()
- The (AJAX) updated DIV does not show the added item 'clonedItem'
   - If I reload the page -> 'clonedItem' appears
   - If I submit g:submitToRemote <n>-times, I always see the the  
model state <n>-1
     - Thus, the DIV section does not show 'clonedItem' if updated once

May someone help out?

Am 08.07.2008 um 03:26 schrieb Stefan:

> Really no one?
>
> Am 07.07.2008 um 20:21 schrieb Stefan:
>
>> I submit a form by g:submitToRemote, but the update DIV of the page  
>> gets updated, but does not reflect the
>> changed model. If I reload the page complete, all changes appear.
>>
>> On the other hand, if I g:submitToRemote again, the last change  
>> appears and so on.
>>
>> Do I have to ask the model to invalidate and reload itself just  
>> before I do
>>
>> render( template:'/metaItem/itemList', bean:q )
>>
>> Here, objects related to q changed.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Model changed but b:submitToRemote does not update as expected

by Peter Ledbrook-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>        render( template:'/metaItem/itemList', bean:q )

What's the code up to this point? What does the template look like?

Cheers,

Peter

--
Software Engineer
G2One, Inc.
http://www.g2one.com/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Model changed but b:submitToRemote does not update as expected

by Stefan-93 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Am 08.07.2008 um 09:45 schrieb Peter Ledbrook:

>>       render( template:'/metaItem/itemList', bean:q )
>
> What's the code up to this point? What does the template look like?

The action:

        def axCloneAndReturn  = {
               
                def currentItem = Item.get( params.id )
                def mi = MetaItem.get( currentItem.metaItem.id )
               
                def clonedItem = currentItem.makeClone()
               
                mi.addToItem( clonedItem ).save()
               
                render( template:'/metaItem/itemList', bean:mi )
        }



Template '_ itemList.gsp':

<g:set var="metaItem" value="${it}" />
               
               
<div id='itemList'>

        ${message(code:'metaItem.addItem')}:
        <g:link controller="itemUD" params="['metaItem.id': metaItem?.id]"  
action="create">U/D</g:link>
        | ${new Date()}

        <g:each in="${Item.findAllByMetaItem( metaItem )}" var="item">

                <g:render template="/item/show" bean="${item}" />

        </g:each>
</div>



And '_show.gsp':

<g:set var="citem" value="${it}" />

<div style='width: 450px; clear: both; border: 1px solid #DDDDDD;  
margin-top: 20px; padding: 5px;'>
       
        <div style='position: relative; top: -15px; margin-left: 5px; margin-
bottom: -5px;'>

                <g:form controller='item' action='axCloneAndReturn'  >
                        <input type='hidden' name='id' value='${citem?.id}'>
                        <g:submitToRemote update="itemList" controller='item'  
action='axCloneAndReturn' value='ax $
{message(code:"metaItem.clone")}' />
                </g:form>

        </div>

        ... printing some properties ...

</div>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Model changed but b:submitToRemote does not update as expected

by Peter Ledbrook-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>        <g:each in="${Item.findAllByMetaItem( metaItem )}" var="item">

The extra item hasn't been flushed to the database by this stage, so
it won't be picked up by a query. Either pass "flush: true" when
saving the meta item, or use "mi.items" in the above tag. I would go
for the latter.

Cheers,

Peter

--
Software Engineer
G2One, Inc.
http://www.g2one.com/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Model changed but b:submitToRemote does not update as expected

by Stefan-93 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thx Peter! For what reasons items do not flush by default?

Because the concept is, that a controller operates on the current  
model state
and finally generates a new model state?

I assumed, that each model change reflects - at least for the current  
controller -
immediately. Obviously, I'm wrong. Too bad ;-)

Am 08.07.2008 um 18:40 schrieb Peter Ledbrook:

>>       <g:each in="${Item.findAllByMetaItem( metaItem )}" var="item">
>
> The extra item hasn't been flushed to the database by this stage, so
> it won't be picked up by a query. Either pass "flush: true" when
> saving the meta item, or use "mi.items" in the above tag. I would go
> for the latter.
>
> Cheers,
>
> Peter
>
> --
> Software Engineer
> G2One, Inc.
> http://www.g2one.com/
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Model changed but b:submitToRemote does not update as expected

by Peter Ledbrook-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2008/7/8 Stefan <3358-27@...>:
> Thx Peter! For what reasons items do not flush by default?
>
> Because the concept is, that a controller operates on the current model
> state
> and finally generates a new model state?

In a simple Grails application, the Hibernate session is kept open
while the view is rendered. This is so that your GSP pages and tags
can access lazy collections on domain instances without throwing
exceptions. The session is automatically flushed when it closes, but
of course this doesn't happen until the view has finished rendering.
Also be aware that data is not persisted to the database until the
session is flushed - the session acts like a cache in that respect.

Of course, you can flush the session manually whenever you like and
Grails makes it fairly easy to do so.

Hope that helps,

Peter

--
Software Engineer
G2One, Inc.
http://www.g2one.com/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Model changed but b:submitToRemote does not update as expected

by Stefan-93 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thx Peter! This sounds very reasonable.

Am 08.07.2008 um 22:16 schrieb Peter Ledbrook:

> 2008/7/8 Stefan <3358-27@...>:
>> Thx Peter! For what reasons items do not flush by default?
>>
>> Because the concept is, that a controller operates on the current  
>> model
>> state
>> and finally generates a new model state?
>
> In a simple Grails application, the Hibernate session is kept open
> while the view is rendered. This is so that your GSP pages and tags
> can access lazy collections on domain instances without throwing
> exceptions. The session is automatically flushed when it closes, but
> of course this doesn't happen until the view has finished rendering.
> Also be aware that data is not persisted to the database until the
> session is flushed - the session acts like a cache in that respect.
>
> Of course, you can flush the session manually whenever you like and
> Grails makes it fairly easy to do so.
>
> Hope that helps,
>
> Peter
>
> --
> Software Engineer
> G2One, Inc.
> http://www.g2one.com/
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


LightInTheBox - Buy quality products at wholesale price