|
Anyway to get that?
--------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
all those attributes you see on tags. like <g:if test="${foo}"> ....
well test is an attribute and whatever you put in it goes to the tag. Just look at the source for the existing tags to see how it gets passed in. -Kate On 4/14/07, Alex Shneyderman <[hidden email]> wrote: > Anyway to get that? > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > -- - kate = masukomi http://weblog.masukomi.org/ --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
That's not what I am after. Here is what I am trying to do.
Say I have a tag like this: <g:textfield name="project.name" /> It should be sufficient to generate this: <input name="project.name" value="${project?.name}" /> I am not sure why I have to do this in grails: <g:textfield name="project.name" value="porject?.name" /> The value attribute makes no sense most of the time. In order to achieve the syntax I am after I have to have access to the model inside the tag code without passing it thru the tag attribute. Thanks, Alex. On 4/14/07, kate rhodes <[hidden email]> wrote: > all those attributes you see on tags. like <g:if test="${foo}"> .... > well test is an attribute and whatever you put in it goes to the tag. > Just look at the source for the existing tags to see how it gets > passed in. > -Kate --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by a.shneyderman
Alex,
I'm not convinced you need to have the whole model without passing it yet... If you have a tag you'd like to express as <g:field descriptor="${project}"/> and a model [project: [name:'myfield', value: 'myvalue']] you can do <input name="${descriptor.name}" value="${descriptor.value}" /> You can probably construct the associated model using a similar idea to what Siegfried is doing for the JSON stuff. I just created something similar to that for creating a Dojo I/O bind args string. Would this approach meet your needs? - Daiji Alex Shneyderman wrote: > That's not what I am after. Here is what I am trying to do. > Say I have a tag like this: > > <g:textfield name="project.name" /> > > It should be sufficient to generate this: > > <input name="project.name" value="${project?.name}" /> > > I am not sure why I have to do this in grails: > > <g:textfield name="project.name" value="porject?.name" /> > > The value attribute makes no sense most of the time. In order to achieve > the syntax I am after I have to have access to the model inside the > tag code without passing it thru the tag attribute. > > Thanks, > Alex. > > On 4/14/07, kate rhodes <[hidden email]> wrote: >> all those attributes you see on tags. like <g:if test="${foo}"> .... >> well test is an attribute and whatever you put in it goes to the tag. >> Just look at the source for the existing tags to see how it gets >> passed in. >> -Kate > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > > > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
> I'm not convinced you need to have the whole model without passing it
> yet... If you have a tag you'd like to express as well, if you look at struts and webwork for examples you will see how nifty they have it. They just noted that setting and getting almost always symmetrical. So, providing one name as an argument is sufficient for both setting (setting a value on the field of your domain object on the backend) and getting (display value for a field). > <g:field descriptor="${project}"/> Yes but than how would I know what is the name of this field? If I provide that as an extra param then it is no different from what it is now. > and a model > > [project: [name:'myfield', value: 'myvalue']] > > you can do > > <input name="${descriptor.name}" value="${descriptor.value}" /> still 2 params. > You can probably construct the associated model using a similar idea to > what Siegfried is doing for the JSON stuff. I just created something > similar to that for creating a Dojo I/O bind args string. any pointers to that? > Would this approach meet your needs? I actually found that what I am trying to do is not possible. Here is why: the code that invokes tag in GroovyPage looks like this Closure tag = setupTagClosure(out, tagLibProp); if(tag.getParameterTypes().length == 1) { tag.call( new Object[]{ attrs }); if(body != null) { body.call(); } } if(tag.getParameterTypes().length == 2) { tag.call( new Object[] { attrs, body }); } this of course means that whatever the bindings that the page has are not available inside the tags. Adding a line like this tag.setDelegate(this); Before ifs will make model available to the taglib closure :-) Not sure what will be the side-effect of it. But I added it on my local copy of grails and it works. Alex. --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by a.shneyderman
Hi Alex,
Hmm. I think I wasn't clear enough in my response before, or maybe you weren't clear enough in why my response wasn't sufficient. In the example I suggested, <g:field descriptor="${project}"/>, field is a tag with a single argument projectwhich is a Map instance set by the Controller-set model [project: [name: 'myfield', value: 'myvalue']] (note the nested map). The field tag could then be defined as follows: field = { attrs -> def descriptor=attrs.descriptor out << """ <input name="${descriptor.name}" value="${descriptor.value}" /> """ } The actual values that you pass into a field tag may vary. As for how you'd construct the object, I think you could construct the map in the controller using: [exposedBean: retrievedbean as ExposedBean] where ExposedBean is something you'd create in src/groovy as something like the following (no I haven't actually run this code but something like it should probably work): class ExposedBean { def bean def ExposedBean(Object obj) { this.bean = obj } def getAt(String prop) { [ name: prop, value: bean[prop] ] } } and then call <g:field descriptor="${exposedBean['project']}" /> <g:field descriptor="${exposedBean['owner']}" /> or alternatively you could do def exposedBean = retrievedbean as ExposedBean [project: exposedBean['project'], owner: exposedBean['owner']] <g:field descriptor="${project}" /> <g:field descriptor="${owner}" /> That said, I just discovered via the Groovy Javadocs and Grails source code that GroovyPage extends Script, which has a getBinding() to return Binding which has a getVariables(), so you could do the following as well, w/o modifying Grails itself: <g:mysuperdupertag thewholevariablebinding="${binding.variables}" /> which truly passes _everything_ including things you probably don't care about, or <g:mynotquitesodupertag themodelonly="${binding.variables['org.codehaus.groovy.grails.MODEL_AND_VIEW'].model" /> which provides exactly the sort of functionality you were asking for in the first place; but is extremely verbose and probably could be shortened via a helper class to: <g:acleanernotsodupertag model="${FromBinding.getModel(binding)}" /> which is much nicer. :P On the other hand this is all starting to get dependent on Grails innards.... I'm not sure if there's a cleaner way to get at the model aside from modifying Grails, as you've done. So take your pick.... :P - Daiji Alex Shneyderman wrote: >> I'm not convinced you need to have the whole model without passing it >> yet... If you have a tag you'd like to express as > > well, if you look at struts and webwork for examples you will see how > nifty > they have it. They just noted that setting and getting almost always > symmetrical. So, providing one name as an argument is sufficient for both > setting (setting a value on the field of your domain object on the > backend) > and getting (display value for a field). > >> <g:field descriptor="${project}"/> > > Yes but than how would I know what is the name of this field? > If I provide that as an extra param then it is no different from > what it is now. > >> and a model >> >> [project: [name:'myfield', value: 'myvalue']] >> >> you can do >> >> <input name="${descriptor.name}" value="${descriptor.value}" /> > > still 2 params. > > >> You can probably construct the associated model using a similar idea to >> what Siegfried is doing for the JSON stuff. I just created something >> similar to that for creating a Dojo I/O bind args string. > > any pointers to that? > >> Would this approach meet your needs? > > I actually found that what I am trying to do is not possible. Here is > why: > > the code that invokes tag in GroovyPage looks like this > Closure tag = setupTagClosure(out, tagLibProp); > > if(tag.getParameterTypes().length == 1) { > tag.call( new Object[]{ attrs }); > if(body != null) { > body.call(); > } > } > if(tag.getParameterTypes().length == 2) { > tag.call( new Object[] { attrs, body }); > } > > > this of course means that whatever the bindings that the page has > are not available inside the tags. Adding a line like this > > tag.setDelegate(this); > > Before ifs will make model available to the taglib closure :-) Not sure > what will be the side-effect of it. But I added it on my local copy of > grails > and it works. > > Alex. > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > > > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
> Hmm. I think I wasn't clear enough in my response before, or maybe you
> weren't clear enough in why my response wasn't sufficient. > > In the example I suggested, <g:field descriptor="${project}"/>, field is > a tag with a single argument projectwhich is a Map instance set by the > Controller-set model [project: [name: 'myfield', value: 'myvalue']] > (note the nested map). > > The field tag could then be defined as follows: > > field = { attrs -> > def descriptor=attrs.descriptor > out << """ > <input name="${descriptor.name}" value="${descriptor.value}" /> > """ > } > > The actual values that you pass into a field tag may vary. As for how > you'd construct the object, I think you could construct the map in the > controller using: > > [exposedBean: retrievedbean as ExposedBean] So far everything is clear. It is just way more complicated than I think it should be. Would not you say? Contrast this with how it would look like after that additional line to GroovyPage. Tag code: field = { attrs -> def name = attrs.name def value = getProperty(name) out << """ <input name="${name}" value="${value}" /> } the tag inside gsp: <g:field name='project.name' /> the code inside controller: ... [project:domainObject] no magic just simple code as it used be. BTW, I really like your approach in ScaffoldTags, the way you introduce the template mechanism to the generation of the html. It reminds me very much of WW. In WW to change forms from being simple html to css html to ajax based forms you would simply change the template set of ww tags. That approach was quite nifty. I think your approach is very similar to what was done in webwork (I think struts 2 does the same thing now). --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by a.shneyderman
Aha- I didn't understand well-enough what was the issue with what I'd
illustrated before. Also, I didn't know how the change you put in would expose the bindings. So with your example, I think that the sort of change you're talking about is probably a good idea. Btw, thanks for the compliment about my plugin. I don't have any sense as to how many people are using it or thinking of using it... it'd be nice to know if anyone's using it and what issues they've encountered so far (or reasons that they've decided against using it after taking a look at it). I'm probably too impatient about getting feedback tho. :P Ah well. - Daiji Alex Shneyderman wrote: >> Hmm. I think I wasn't clear enough in my response before, or maybe you >> weren't clear enough in why my response wasn't sufficient. >> >> In the example I suggested, <g:field descriptor="${project}"/>, field is >> a tag with a single argument projectwhich is a Map instance set by the >> Controller-set model [project: [name: 'myfield', value: 'myvalue']] >> (note the nested map). >> >> The field tag could then be defined as follows: >> >> field = { attrs -> >> def descriptor=attrs.descriptor >> out << """ >> <input name="${descriptor.name}" value="${descriptor.value}" /> >> """ >> } >> >> The actual values that you pass into a field tag may vary. As for how >> you'd construct the object, I think you could construct the map in the >> controller using: >> >> [exposedBean: retrievedbean as ExposedBean] > > So far everything is clear. It is just way more complicated than I > think it should be. > Would not you say? Contrast this with how it would look like after > that additional > line to GroovyPage. Tag code: > > field = { attrs -> > def name = attrs.name > def value = getProperty(name) > out << """ > <input name="${name}" > value="${value}" /> > } > > the tag inside gsp: > > <g:field name='project.name' /> > > the code inside controller: > > ... > [project:domainObject] > > no magic just simple code as it used be. > > BTW, I really like your approach in ScaffoldTags, the way you > introduce the > template mechanism to the generation of the html. It reminds me very > much of WW. In WW to change forms from being simple html to css html > to ajax based forms you would simply change the template set of ww tags. > That approach was quite nifty. I think your approach is very similar to > what was done in webwork (I think struts 2 does the same thing now). > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > > > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
