Grails f:table customization - grails

I am trying to use template to apply to my scaffolding of f:table. However I do not know how to access the information of each line of my table in order to properly write my template. For simple fields, I have bean, property,label, and such but I cannot find any documentation pointing out how to access information for f:table. Please help me out guys !
Grails 3.1.x

See, if this sample below can provide you some hint.
<table>
<thead>
<tr>
<g:each in="${domainProperties}" var="p" status="i">
<g:set var="propTitle">
${domainClass.propertyName}.${p.name}.label
</g:set>
<g:sortableColumn property="${p.name}"
title="${message(code: propTitle, default: p.naturalName)}" />
</g:each>
</tr>
</thead>
<tbody>
<g:each in="${collection}" var="bean" status="i">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<g:each in="${domainProperties}" var="p" status="j">
<g:if test="${j==0}">
<td>
<g:link method="GET" resource="${bean}">
<f:display bean="${bean}"
property="${p.name}"
displayStyle="${displayStyle?:'table'}" />
</g:link>
</td>
</g:if>
<g:else>
<td>
<f:display bean="${bean}"
property="${p.name}"
displayStyle="${displayStyle?:'table'}"/>
</td>
</g:else>
</g:each>
</tr>
</g:each>
</tbody>
</table>
Taken from the Github page.

The documentation for this plugin is a bit sketchy. The part you are looking for is in section Customizing Field Rendering.
The particular table you are looking for (containing value, bean, etc. parameters) is called Template parameters.

Related

When do you use th:remove="tag" versus th:block?

The following two blocks would evaluate the same, so when would you use th:remove="tag" over th:block?
<th:block th:text="${myBean.value}">[value]</th:block>
versus
<span th:remove="tag" th:text="${myBean.value}">[value]</span>
Since they can be used interchangeably I think it is opinion based... but for readability, my opinion is:
<th:block /> should be used for doing structural logic (th:if, th:each, etc..) and only when it's not possible on the parent tag. For example, in the case you have to contain more than one element in a loop -- e.g, a loop that produces 2 table rows for each object:
<table>
<th:block th:each="object: ${objects}">
<tr>
<td th:text="${object.data1}" />
<td th:text="${object.data2}" />
</tr>
<tr>
<td th:text="${object.data3}" />
<td th:text="${object.data4}" />
</tr>
</th:block>
<table>
th:remove should only be used for example data that should only be rendered when viewing the file in a browser/prototyping w/o rendering the thymeleaf:
<table>
<th:block th:each="object: ${objects}">
<tr>
<td th:text="${object.data1}" />
<td th:text="${object.data2}" />
</tr>
<tr>
<td th:text="${object.data3}" />
<td th:text="${object.data4}" />
</tr>
</th:block>
<tr th:remove="all">
<td>Mild Cinnamon</td>
<td>1.99</td>
</tr>
<tr th:remove="all">
<td>Other</td>
<td>Data</td>
</tr>
<table>
In the specific case where you want to output data/text without a tag, I prefer inline expressions. They're enabled by default in thymeleaf 3. So:
[[${myBean.value}]] instead of <th:block th:text="${myBean.value}">[value]</th:block>

Struts 2 textfield label doesn't show in table

The following jsp file fragment using struts2 tags doesn't show the textfield label. How can I fix this? Is it possible to have the label displayed by using only struts2 tags?
<s:form action="voucher" theme="simple">
<table width=50% border="5">
<tr>
<td>
<s:textfield label="Enter the voucher hrn" name="voucher.SN" />
</td>
<td>
<s:submit value="Check state" />
</td>
</tr>
<tr>
<td>
<s:radio list="#{'used': 'Mark as used', 'available': 'Mark as available'}" name="selections" value="%{'used'}"></s:radio>
</td>
<td>
<s:submit value="Update state" />
</td>
</tr>
</table>
</s:form>
It is because you are using simple theme in your form. Remove theme="simple" from <s:form> tag then Struts2 will do table layout as well field errors and labels for you.
BTW if you really need to use your custom layout then use <s:label> tags for labels.

In s:iterator tag im having set of hyperlinks which leads to respective datas. I need to know which link is clicked

In s:iterator tag I have set of hyperlinks which leads to respective data. I need to know which link is clicked
Here my code:
<s:iterator value="datasFinal" status="reportStatus">
<tr class="<s:if test="#reportStatus.odd == true ">odd</s:if><s:else>even</s:else>">
<td align="center"><s:property value="#reportStatus.count" /></td>
<td align="center"><a href="javascript:submit('')">
<s:set name="index" value="#reportStatus.index" scope="session"/>
<s:property value="reportName" /> </a></td>
</tr>
<s:hidden name="reportName" value="%{reportName}"/>
</s:iterator>
I got the solution, thank u RAO and Dave.
<s:iterator value="datasFinal" status="reportStatus">
<tr class="<s:if test="#reportStatus.odd == true ">odd</s:if><s:else>even</s:else>">
<td align="center"><s:property value="#reportStatus.count" /></td>
<td align="center"><a href="javascript:submit('${reportName}')">
<s:set name="index" value="#reportStatus.index" scope="session"/>
<s:property value="reportName" /> </a></td>
</tr>
</s:iterator>
By submitting this to java script i got which link is clicked...

Iterator, set, if-else tags of Struts2(Getting the value of s:radio and applying if-else )

I have a jsp page in which I have two radio buttons and a select tag. Now, if the first radio button is clicked than I want to make that select tag disable but I am fail to do this , I have tried using "disabled" property. Following is the code.
Jsp Page
<table align="center">
<s:iterator value="FirstObjectList" status="AuthorTypeStatus">
<tr>
<td>
<s:radio name="radio_SelectedValue" list="{ObjectName}" listKey="ObjectKey" listValue="ObjectName" value="DefaultObject"/>
</td>
</tr>
</s:iterator>
<s:if test="%{#radio_SelectedValue == 'ObjectName1'}">
<s:set name="isSelectDisabled" value="false"/>
</s:if>
<s:else>
<s:set name="isSelectDisabled" value="True"/>
</s:else>
<tr >
<td colspan="2">
Select Parent Discover Lab
</td>
</tr>
<tr>
<td>
<s:select name="select_SelectedValue" headerKey="DefaultObject" headerValue="ParentObject" list="ObjectList" listKey="ObjectListKey" listValue="ObjectListValue" disabled="%{isSelectDiabled}">
<s:iterator value="ObjectList">
</s:iterator>
</s:select>
<s:submit value="Continue">
</s:submit>
</td>
</tr>
All the getter and setter methods are fixed..is this possible without javascript?
I'm a little confused by your code block, but I think I understand what you're aiming for. Something like this should work
<tr>
<td>
<s:radio name="radio_SelectedValue" list="%{radioList}" listKey="ObjectKey" listValue="ObjectName" value="DefaultObject"/>
</td>
</tr>
<s:if test="%{radio_SelectedValue.equals('myChosenValueFromTheList')}">
<s:select name="select_SelectedValue" headerKey="-1" headerValue=" " list="ObjectList" listKey="ObjectList.Key" listValue="ObjectList.Value" />
</s:if><s:else>
<s:select name="select_SelectedValue" headerKey="-1" headerValue=" " list="ObjectList" listKey="ObjectList.Key" listValue="ObjectList.Value" disabled="disabled" />
</s:else>
I'm not sure what you're doing with the iterators with these tags, they handle the list propagation themselves. Simply tell the tag what list to use and struts will populate the tags appropriately. You can then do a conditional based on the value of the radio when the page renders and perform magic on the select tag as shown above.

why struts UI tags can not be put together in the same row?

I need 2 textareas in the same row and tried as below but it is printing in the next row.
All struts tags are have same problem.Is there any alternative method ? Please suggest.
<table>
<tr>
<td>
<s:textarea name="1"/>
</td>
<td>
<s:textarea name="2"/>
</td>
</tr>
</table>
This is due to Struts2's default rendering based on its default theme. I find this tutorial gives a good idea of Struts2 theming/templating: http://www.mkyong.com/struts2/working-with-struts-2-theme-template/
If you don't want to use the default and want to lay it out as you have it, try:
<table>
<tr>
<td>
<s:textarea name="1" theme="simple"/>
</td>
<td>
<s:textarea name="2" theme="simple"/>
</td>
</tr>
</table>

Resources