i want to access the inList-values which i set in domain, in my view. Like this:
<g:countrySelect name="SelectState" keys="${incidentInstance?.state.toList()}" value="${incidentInstance?.state}"/>
But it dont work...(any idea?)
Thx
Well, you are using <g:countrySelect> instead of <g:select>
To get the inList values (from your constraints definition) you do something like this
<g:select name="state" from="${incidentInstance.constraints.state.inList}"
value="${incidentInstance?.state}"/>
Related
Given two similar domains Foo and Bar, is it possible to create a g:select tag that can choose from both of them? E.g.,
<g:select from="${[Foo.list(), Bar.list()]}"/>
That, unfortunately, does not work. It creates a single option that is the text of all items from both domains :|
So, does anybody know if this can be done?
Edit
Nope, it doesn't make any difference to pass this list in from the controller.
<g:select from="${Foo.list() + Bar.list()}"/>
would also do just fine
Whoops, just needed to flatten the list!
<g:select from="${[Foo.list(), Bar.list()].flatten()}"/>
Otherwise, it was a list of lists.
I have a layout file. I want something like this in each of my pages inheriting that layout:
Just ${step} Steps Away From The Awesome!!
So in my layout I have defined a string as above with a placeholder step. I dont want to pass the value of this placeholder from controller. I wish to define it in the gsp that inherits this layout.
I was looking for something like <g:set var="step" value="1"/> (or 2 or 3 depending on the gsp). But it does not work if I define it like that.So how do I dereference the value of "step" inside each extending layout?
One of the best ways to accomplish this is to make use of content blocks and page properties. These are both features derived from Sitemesh.
I assume you only want to conditionally include this information when the page using the layout provides a value. So in my example here I have wrapped it in a quick if check.
In your layout:
<g:if test="${pageProperty(name: 'page.step')}">
Just <g:pageProperty name="page.step" /> Steps Away From The Awesome!!
</g:if>
Then in any page that uses the layout you can include the content for the variable step
<content tag="step">3</content>
Note that the value within the content tag can be whatever you like. It will be evaluated when the page is rendered.
I have a g:select statement that looks like the following:
<g:select id="gearbox" name="gearbox.id" from="${com.nppc.mes.energyusage.Gearbox.list()}" optionKey="id" optionValue="${ {"${it.gearboxType} - (${it.gearboxRatio})"} }" required="" value="${gearboxVoltageInstance?.gearbox?.id}" class="many-to-one"/>
I have added an optionValue attribute: optionValue="${ {"${it.gearboxType} - (${it.gearboxRatio})"} }"
This works as I want.
However, I want to show my domain object, Gearboxes the same everywhere. I have created a template, and am able to use the g:render tag on my show.gsp.
What I can't figure out is how to get something like this to work:
optionValue="<g:render template="/shared/gearbox" model:="[gearbox:it]"/>"
Is it possible to use templates to generate the content that goes into an optionValue?
You could hack around it, but it feels like bad design to me.
The right way to do something like is seems to be to add a helper method to your Gearbox domain class
static transients = [ 'renderedValue' ]
def getRenderedValue(){
"$gearboxType - $gearboxRatio"
}
Then, you can just call optionValue="${ it.renderedValue }".
Also, if you specify a toString() in your domain class, this would be used to generate the default rendered value.
Tags can be used as regular functions in Groovy code. Like:
optionValue="${g.render(template: '/shared/gearbox', model: [gearbox: it])}"
I have something like:
<input type="text" name="TerrMng" id="TerrMng"/>
in HTML. What is the equivalent of the above using #Html.Display?
I tried using:
#Html.Display("TerrMng", TerrMng)
but was not successful. Note that I like to use #Html.Display but not sure how to translate the ID value so that it shows up.
This should do the trick for you. Adding the TerrMng as a 2nd parameter sets the value of the created html but the variable must come from your Model on load.
#Html.Display("TerrMng");
guys!
I`d like to make 'clever pagination'. For example, if i already have params.category=Auto - i want it to be added to my params.
Of course, i can do smth like this :
<g:paginate total="${total}" max="10" maxsteps="5" params="[category: params.category,subcategory: params.subcategory]"/>
But if current params.subcategory is null - it will also be added to url ( ?subcategory=&category=Auto) . I don`t want to have 'subcategory=' in my params in such a case!
Also I can do it with string concatenations to create new url - but maybe grails have some cheats/mechanism to create new url without string concatenations?
Cheers, Dmitry.
There aren't any great solutions I can think of. You could try:
params="${[category: params.category,subcategory: params.subcategory].findAll {it.value} }"
Alternatively, provide your own custom tag that strips out null param values before delegating to the paginate tag.