Data is not retrieving by g:select in Grails 3.
My code is like below-
<g:select from="${Machine_summaryList}" name="brand" />
Here "Machine_summaryList" is List of "Machine_summary" class and "brand" is the column which data I need to retrieve.
You need to use optionValue="brand" in this case.
Your g:select must be like:
<g:select from="${Machine_summaryList}" name="brand" optionKey="id" optionValue="brand"/>
When the form will submit, you will receive the selected Machine in params.brand.
Just this procedure works for me
<g:select from="${project.Machine_summary.executeQuery("select distinct c.brand from Machine_summary c")}" name="brand" />
Related
On my gsp-page I've dropdown list. The code below:
<g:select name="tablePlacesAvailable" from="${tableInfo}"
optionValue="${{it.placesInTableAmount}}"
optionKey="placesInTableAmount" value=""/>
It shows non-unique results. How to fix it?
You can modify your code as per following .
<g:select name="tablePlacesAvailable" from="${tableInfo.unique()}" optionValue="${{it.placesInTableAmount}}" optionKey="placesInTableAmount" value=""/>
I have a JSP page and I use Struts to build my select tag. The JSP code is the following:
<s:select
required="true"
name="form.tipologia"
label="%{getText('Enum.label')}"
list="#it........Enum#values()"
listKey="name()"
listValue="getText('Enum.' + name())"
headerKey=""
headerValue="%{getText('Enum.')}"
/>
This code produces me a select field with my Enum constants.
What I want to do is to create the field with only a subset of the Enum.
How can I do it? Is it possible?
You can use OGNL projection for this.
<s:select list="#it..Enum#values().{? #this != #it..Enum#ENUM_TO_EXCLUDE}" />
This will create a subset of all enum values except that one that you want to exclude.
If comparing enums doesn't work then you can compare strings.
<s:select list="#it..Enum#values().{? #this.toString() != 'ENUM_TO_EXCLUDE'}" />
how to put values in select tag in grails.
<g:select name="country_name" > </g:select>
like all country name USA,UK,AUS,SA,CAN,INDIA
<g:select name="country_name" from="${['USA','UK','INDIA']}"> </g:select>
through this you can put values manually
from="${['USA','UK','INDIA']}
I have a select box of TYPES that each type has their own PARAMETERS. The TYPES select box will fire off some AJAX that calls a template and renders PARAMETER select boxes on my view. The Parameters are made up of name:value pairs, thus every name can have many values.
Some parameters need multiple='true' for the user to select multiple values for each name, while other parameters need to be restricted to only one choice.
In my gsp page I have a bunch of these:
<g:if test="${it?.getKey().toString().equals('PARAMETER_A')}">
<td><g:select multiple="true" optionKey="id" optionValue="value" name="sampleParameters" id="parameter" value="${params?.sampleParameters}" from='${it?.getValue().sort()}'></g:select></td>
</g:if>
<g:if test="${it?.getKey().toString().equals('PARAMETER_B')}">
<td><g:select multiple="true" optionKey="id" optionValue="value" name="sampleParameters" id="parameter" value="${params?.sampleParameters}" from='${it?.getValue().sort()}'></g:select></td>
</g:if>
My issue is that I have 6 parameters for one particular TYPE that need to select multiple values, the rest do not. Rather than explicitly type out as above, is there a way that I can test for more than one thing in a g:if statement like you can in java? such as:
if(something.equals(PARAMETER_A) || something.equals(PARAMETER_B))
etc.
Is there a way to do something similar to java's approach in groovy?
Grails g:if just uses groovy in its test attribute. So to answer your question, yes:
<g:if test="${something.equals(PARAMETER_A) || something.equals(PARAMETER_B)}">
</g:if>
I am running into an issue where by I want to pass form elemets that gets generated dynamically as such id's of those elements are dynamic as well.
Here is the code snippet I am running
<g:each in="${selectedList}" status="i" var="menuForCity">
<td><input type="checkbox" id="${100+i}" name="check_list" value="${city.id}" checked="checked" /></td>
<g:select name="myClass.id"
from="${instances}"
onchange="${remoteFunction(
controller:'cityPlan',
action:'test',
params:'\'id=\'+this.value+\'\'&cityid=\'+document.getElementById(100+i).value',
update:(i+1))}"
optionKey="id" />
...
Problem I am running into is how to get id of dynamic checkbox thats created in the form ?
Is there any way I can write/evaluate gstring ?
...
params:'\'id=\'+this.value+\'\'&cityid=\''+city.id,
update:(i+1))}"
optionKey="id" />
...
I'm not answering your question but there's an extra single quote in your code that shouldn't be there in the first place, that might solve your problem.
params:'\'id=\'+this.value+\'\'&cityid=\'+document.getElementById(100+i).value',
should be:
params:'\'id=\'+this.value+\'&cityid=\'+document.getElementById(100+i).value',