Quantcast

Data Binding trouble (datePicker)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Data Binding trouble (datePicker)

A_Grails_User
I'm in trouble with binding a date from a datePicker to a domain class. I know this has been discussed in  many posts before but I did not find the answer yet.

I try to do the following. I have a create.gsp with a form to fill in some data including a drop down for a date. Then I have a "preview" button with a "preview" action assigned. If the user clicks this button I hand the params over to a service method and I request data from a remote webservice to fill in some more command object properties. so far so good. In my preview action I'm using a command object and if I look at my debug output the date is still a date. If all data are requested, I display a create button to save the data. On the very same create.gsp I do this:

<g:if test="${cmd.city != null}">
    <g:form action="save" method="post">
        <input type="hidden" name="city" value="${fieldValue(bean: cmd, field: 'city')}"/>
        <input type="hidden" name="zipcode" value="${fieldValue(bean: cmd, field: 'zipcode')}"/>
        <input type="hidden" name="yearDate" value="${fieldValue(bean: cmd, field: 'yearDate')}"/>
                <div class="buttons">
            <input class="save" type="submit" value="Create"/>
        </div>
    </g:form>
</g:if>

On calling the save method the yearDate is a string now. But I wasn't able to bind it correctly to my domain object. What do I wrong? I really tried everything (incl. bindData, obj.properties = params, command object).

Could someone explain how to solve the issue?

Thanks
AGU
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Data Binding trouble (datePicker)

Marc Palmer Local

On 26 Sep 2008, at 19:39, A_Grails_User wrote:

>
> I'm in trouble with binding a date from a datePicker to a domain  
> class. I
> know this has been discussed in  many posts before but I did not  
> find the
> answer yet.
>
> I try to do the following. I have a create.gsp with a form to fill  
> in some
> data including a drop down for a date. Then I have a "preview"  
> button with a
> "preview" action assigned. If the user clicks this button I hand the  
> params
> over to a service method and I request data from a remote webservice  
> to fill
> in some more command object properties. so far so good. In my  
> preview action
> I'm using a command object and if I look at my debug output the date  
> is
> still a date. If all data are requested, I display a create button  
> to save
> the data. On the very same create.gsp I do this:
>
> <g:if test="${cmd.city != null}">
>    <g:form action="save" method="post">
>        <input type="hidden" name="city" value="${fieldValue(bean: cmd,
> field: 'city')}"/>
>        <input type="hidden" name="zipcode" value="${fieldValue(bean:  
> cmd,
> field: 'zipcode')}"/>
>        <input type="hidden" name="yearDate" value="$
> {fieldValue(bean: cmd,
> field: 'yearDate')}"/>
> <div class="buttons">
>            <input class="save" type="submit" value="Create"/>
>        </div>
>    </g:form>
> </g:if>
>
> On calling the save method the yearDate is a string now. But I  
> wasn't able
> to bind it correctly to my domain object. What do I wrong? I really  
> tried
> everything (incl. bindData, obj.properties = params, command object).

Dates are usually bound from multiple fields i.e. yearDate_year,  
yearDate_month, yearDate_day etc. I think it is probably looking for  
these and failing. I don't think the current date binding supports  
mapping incoming strings to dates - after all what format should they  
come in (bear in mind locale issues etc)

Marc


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Data Binding trouble (datePicker)

A_Grails_User
I could make some more hidden fields with the values for yearDate_year, yearDate_month etc... Would it work this way? I think parsing a string to a date is painful and I'm aware of the locale issue. Additionally it wouldn't be so classy. Is there no easy way? How would you solve this problem? What is best practice here?

Thanks.
AGU

Marc Palmer Local wrote
On 26 Sep 2008, at 19:39, A_Grails_User wrote:

>
> I'm in trouble with binding a date from a datePicker to a domain  
> class. I
> know this has been discussed in  many posts before but I did not  
> find the
> answer yet.
>
> I try to do the following. I have a create.gsp with a form to fill  
> in some
> data including a drop down for a date. Then I have a "preview"  
> button with a
> "preview" action assigned. If the user clicks this button I hand the  
> params
> over to a service method and I request data from a remote webservice  
> to fill
> in some more command object properties. so far so good. In my  
> preview action
> I'm using a command object and if I look at my debug output the date  
> is
> still a date. If all data are requested, I display a create button  
> to save
> the data. On the very same create.gsp I do this:
>
> <g:if test="${cmd.city != null}">
>    <g:form action="save" method="post">
>        <input type="hidden" name="city" value="${fieldValue(bean: cmd,
> field: 'city')}"/>
>        <input type="hidden" name="zipcode" value="${fieldValue(bean:  
> cmd,
> field: 'zipcode')}"/>
>        <input type="hidden" name="yearDate" value="$
> {fieldValue(bean: cmd,
> field: 'yearDate')}"/>
> <div class="buttons">
>            <input class="save" type="submit" value="Create"/>
>        </div>
>    </g:form>
> </g:if>
>
> On calling the save method the yearDate is a string now. But I  
> wasn't able
> to bind it correctly to my domain object. What do I wrong? I really  
> tried
> everything (incl. bindData, obj.properties = params, command object).

Dates are usually bound from multiple fields i.e. yearDate_year,  
yearDate_month, yearDate_day etc. I think it is probably looking for  
these and failing. I don't think the current date binding supports  
mapping incoming strings to dates - after all what format should they  
come in (bear in mind locale issues etc)

Marc


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

    http://xircles.codehaus.org/manage_email

Loading...