Grails: Removing Unwanted Brackets when Displaying Variable - grails

I have a .gsp page where a student can select a course that they are in. That selection is then stored in an array list. I have another .gsp page that shows student details and within those details it shows which course they selected from the other page. However, when it displays the course it displays like this: "[courseName]", but I would like it to display without the brackets: "courseName".
This is my code for displaying the selection:
<g:if test="${studentDetails?.course}">
<li class="fieldcontain">
<span id="course-label" class="property-label">
<g:message code="student.course.label" default="Course(s)" /></span>
<span class="property-value" aria-labelledby="course-label">
<g:set var="course" value="${studentDetails?.course.courseName}" />
<g:message message="${course}" /></span>
</li>
</g:if>
So far I've tried displaying the variable with g:fieldValue, g:message, and just the variable itself without a tag. All methods display with the brackets. Any suggestions on how to remove the brackets are appreciated. If any other code is needed I can provide it. Thanks.

If your studentDetails?.course.courseName contains a List of courses and your want to display all of them, you need to convert it to a String. But default implementation of List.toString() uses brackets. Your could use .join(',') instead.
Like:
<g:if test="${studentDetails?.course}">
<li class="fieldcontain">
<span id="course-label" class="property-label">
<g:message code="student.course.label" default="Course(s)" /></span>
<span class="property-value" aria-labelledby="course-label">
${studentDetails.course.courseName.join(', ')}
</span>
</li>
</g:if>
Also I suggest to add .encodeAsHTML() if you got this data (course name) from a user, to escape any HTML content inside variables (avoid XSS, etc). Like:
${studentDetails.course.courseName.join(', ').encodeAsHTML()}

Related

Find a dynamic <input> tag with Capybara/Selenium

I have the following HTML:
<label for="file-input-76eb2" id="ember3042" class="c-text-input c-text-input o-grid-cell--6 file-upload ember-view">
<input id="file-input-76eb2" type="file" accept="text/csv" style="display: none;">
<span class="c-file-upload__input-filename"></span>
<a class="c-button c-button--single-action-primary c-file-upload__input-button">
Select
</a>
</label>
I have managed to get a Capybara::Node:Element corresponding to the label tag, but I can't get to the input. The id is dynamic- constantly changing. Moreover, I need to upload a file to this input tag.
Is there any information what I can do? This is all using google-chrome-headless.
This is using Ruby, with Capybara, with Selenium.
Looks like
label_element.find(:xpath, '//input') did it!

Select following-sibling if element unknown

I want to select the first sibling of a tag from an HTML element. Lets say I want to get the <a> that follows this <span>:
<span id="unique"></span>
<a href="#">
This can easily be done with the following Xpath:
//div[#id="unique"]/following-sibling::a
This, however, is very specific in a way that it looks for an <a> tag. How can I make it more generic that it would find any tag as long as it is the first sibling to the element I selected?
Write as below
//span[#id="unique"]/following-sibling::*[1]
Here is a sample HTML :
<div>
<span id="unique"></span>
<p>foo</p>
<p>bar</p>
</div>
XPATH expression:
//span[#id="unique"]/following-sibling::*[1]
output
<p>foo</p>

How can I use g:render with my g:each variable from a Map collection?

I have a def statusMap = HashMap<String, List<MyItem>>() that gets passed into my gsp page.
In my gsp page I have the following:
<g:each var="myList" in="${statusMap}">
<div id="pending_list" class="onTop">
<g:render template="/list" model="['list':"${myList.value}", 'listSize':"${myList.value.size()}"]" />
</div>
</g:each>
But I can't seem to correctly pass myList.value and myList.value.size() into my template. I think my quotes are wrong somehow but I'm not sure.
How can I correctly pass myList.value and myList.value.size() into the list template through the model?
Since you are using a map your itteration is based on keys within that Map. So the basic syntax looks like this:
<g:each in=${yourCoolMap.entrySet()}" var="entry">
${entry.key} = ${entry.value}
</g:each>
Thus, your code will look something like this:
<g:each var="myList" in="${statusMap.entrySet()}">
<div id="pending_list" class="onTop">
<g:render template="/list" model="['list': myList.value, 'listSize': myList.value.size()]" />
</div>
</g:each>

Render selectManyCheckbox without HTML table

is there a way to remove the table out of rendered html that is created by the h:selectManyCheckbox tag in server faces?
I am using twitter bootstrap and i placed the checkboxes inside a dropdown menu:
<ul class="dropdown-menu dropdown-menu-form">
<li><label class="checkbox"> <input type="checkbox" />
Activated
</label></li>
<li><label class="checkbox"> <input type="checkbox" />
Deactivated
</label></li>
</ul>
So the generated html table destroys the layout ...
You could just render a bunch of <h:outputLabel><h:selectBooleanCheckbox> inside <ui:repeat>. This way you've markup freedom. You'll only need to alter the model from e.g. List<T> to Map<T, Boolean> to represent the checked values and then loop over the map afterwards to collect checked ones.
A ready-to-use component is Tomahawk's <t:selectManyCheckbox> which has an additional layout attribute value of spread.

Grails filterPane plugin to fit page layout

I would like to have the filterPane to be inserted in my own div in order to fit my page layout. Basically I want to get rid of the default pop-up behavior and harmonize filterPane with the other elements of the application.
this is my gsp
<div class="filter">
<p>
<filterpane:isFiltered>
<filterpane:currentCriteria domainBean="demoracer.Pilot" />
</filterpane:isFiltered>
</p>
<g:formRemote method="post" name="form_search" url="${[action:'list']}" update="listContainer" >
<filterpane:filterPane customForm="true" formName="form_search" domainBean="demoracer.Pilot"
filterProperties="name," id="filterpaneContainer" />
<g:actionSubmit value="Apply Filter From Outside Filter Pane" action="list" />
</g:formRemote>
</div>
but the pane do not show up.
Thanks
Since the filterpane generates its own div, can't you just use the div it generates and restyle it to fit your layout? You can specify the id, class, and style attributes of the container div it generates. That should be more than enough to restyle it any way you'd like.
it doesn't seems possible since the html is statically created by the taglib
def output = """\
<div id="${containerId}"
class="filterPane ${containerClass ?: ''}"
style="display:none;${containerStyle}">
<h2>${title}</h2>
${openFormTag}
<input type="hidden" name="filterProperties" value="${propsStr}" />
<table cellspacing="0" cellpadding="0" class="filterTable">
"""

Resources