We've got the following code:
<div th:each="client : ${clients}">
<div th:each="purchase : ${client.purchases}">
<div th:each="product : ${purchase.products}">
<span th:text="${product.price}"></span>
<!-- <span id="2" th:text="${#aggregates.sum(products.{price})}"> </span> -->
<!-- <span id="2" th:text="${#aggregates.sum(products.![price])}"> </span> -->
</div>
</div>
</div>
The output is:
5.25
4.20
If I uncomment the first comment, I get error
Exception evaluating SpringEL expression: "#aggregates.sum(products.{price})" (clients/clients:84)
If I uncomment only the second comment, I get error:
Exception evaluating SpringEL expression: "#aggregates.sum(products.![price])" (clients/clients:85)
I tried to use http://demo-dspace-cris.cineca.it/bitstream/123456789/26/1/usingthymeleaf.pdf
I am using thymeleaf 2.1.4
IT WORKS !
I should use:
<span id="2" th:text="${#aggregates.sum(purchase.products.![price])}"> </span>
I figured it myself after posting here !
<div th:each="client : ${clients}">
<div th:each="purchase : ${client.purchases}">
<span id="2"
th:text="${#aggregates.sum(purchase.products.![price])}"> </span>
<div th:each="product : ${purchase.products}">
<span th:text="${product.price}"></span>
</div>
</div>
</div>
output:
9.45
5.25
4.20
site that helped me a lot: http://forum.thymeleaf.org/aggregates-with-Spring-td3767446.html
Related
I have tried the code below, but getting false even for ROLE_ADMIN
<th:block th:each="authority : ${#authentication.getAuthorities()}">
<span th:with="role=${authority.getAuthority()}">
<span th:text="${role}"></span>
<p th:with="res=${#strings.toString(role) == 'ROLE_ADMIN'}">
<div th:if="${res}">successtrial</div>
<div th:unless="${res}">failed trial</div>
<span th:text=${res}></span>
</span>
</p>
</th:block>
Getting ${role} - printed correct, but finally getting failed trial
You can use the hasRole method like this:
<div sec:authorize="hasRole('ADMIN')">
<div>success trial</div>
</div>
<div sec:authorize="!hasRole('ADMIN')">
<div>failed trial</div>
</div>
Be sure to have the org.thymeleaf.extras:thymeleaf-extras-springsecurity5 dependency in your application.
I would like to Display image on my page, I am struggling with evaluating a span tag which contains an HTTP URL.
<span sec:authentication="principal.image">
I have Updated the Authentication Object to have custom fields like image, firstName, lastName etc. So Basically below HTML
<div th:fragment="logout" class="logout" sec:authorize="isAuthenticated()">
<div class="container">
<div class="row">
<div class="span2 display-label">Name:</div>
<div class="span4 display-values">
<p>
<span sec:authentication="principal.firstName"></span>
<span sec:authentication="principal.lastName"></span>
</p>
</div>
</div>
<div class="row">
<div class="span2 display-label">Email:</div>
<div class="span4 display-values">
<p>
<span sec:authentication="name"></span>
</p>
</div>
</div>
<div class="row">
<div class="span2 display-label">Image:</div>
<div class="span4 display-values">
<span sec:authentication="principal.image"> </span>
</div>
</div>
<div>
<form action="#" th:action="#{/logout}" method="post">
<input type="submit" value="Logout"/>
</form>
</div>
</div>
</div>
Is printing
Name:
Abhishek
Email:
abhishek#gmail.com
Image:
https://scontent.xx.fbcdn.net/v/t1.0-0/p480x480/320426_10151045513476766_423049521_n.jpg?oh=766767548269c2483f0ad1e865d
As you can see I do have a valid URL I want to enclose this URL as <img src=""...>
I have tried
<img src = <span sec:authentication="principal.image"> </span></img>
<img th:src = <span sec:authentication="principal.image"> </span></th>
But none of these is working.
PS: I don't want to create a model attribute to store image URL and show it on page.
The syntax you have posted is not correct. Try using the authentication object with the following syntax:
<img th:if="${#authentication.principal.image}"
th:src="${#authentication.principal.image}"
alt="placeholder" />
I am having a issue with the styling for the iphone.
I have this form where it displays list of doctors base on a list of doctors from the db and it it generates the results correctly.
However, when the results are generated, you need to swipe from right to left to see the info.
How can I target only Iphone users so the information is within the frame of the iphone?
Here is the following form I used. Ignore the "##", I am using coldfusion and bootstrap.
$(function(){
$('##myModal').modal('show');
});
<div class="widthResults">
<nav class="hidden-xs visible-md visible-lg" ng-show="ShowResults"><uib-pagination boundary-links="true" max-size="maxPageNumbersToShow" ng-model="currentPage" total-items="resultsCount"> </uib-pagination></nav>
<nav class="visible-xs hidden-md hidden-lg" ng-show="ShowResults"><uib-pager ng-model="currentPage" total-items="resultsCount"> </uib-pager></nav>
<div class="container">
<div id="searchResults" ng-repeat="e in providers" ng-show="ShowResults">
<div class="row">
<hr />
<h4>{{e.FullName}}</h4>
</div>
<div class="row">
<div class="col-md-4 no-margin padding"><strong>Specialty: </strong>{{e.Specialty}}<br />
<span class="padding"><strong>Gender:</strong> {{e.Gender}}</span><br />
<strong>Language(s):</strong> {{e.Languages}}</div>
<div class="col-md-4 no-margin"><strong>Clinic: </strong> <i class="glyphicon glyphicon-map-marker"></i> {{e.Address1}}<br />
<span class="shiftAdd padding">{{e.Address2}} </span><br />
<strong>Phone:</strong> <i class="glyphicon glyphicon-earphone"></i> {{e.Phone | PhoneNumber}}</div>
</div>
</div>
</div>
<nav class="visible-xs hidden-md hidden-lg" ng-show="ShowResults">
<hr /><uib-pager ng-model="currentPage" total-items="resultsCount"> </uib-pager></nav>
</div>
I am trying to create multiple divs on the fly using a template which is called for a number of times and each time i create a new div ... which seems to be working fine below is the code. I am passing a map tempMap from the controller to the gsp page which is of the below format
tempMap = [key_1:v1,key_2:v2,key_3:v3] //from the controller
//this is the gsp part
<g:set var="counter" value="${1}" />
<g:while test="${counter <= tempMap.counter}">
<g:render template="travelDetailsToShow" />
<g:set var="counter" value="${counter + 1}" />
</g:while>
I need to set the ids of the elements based on the counter which also is working ... But i am unable to set the values of the fields.
<div class="col-sm-6" id="key_${counter}"> // This sets the id to key_1, key_2 depending on the counter value
<div class="form-group">
<label>Departure Date</label>
<span class="input-icon-right input-group">
<g:set var="temp" value="kep_${counter}" />
**<input type="text" name="key_${counter}" class="form-control" value="${tempMap?.key_${counter}}" readonly></input> // this does not work**
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</span>
</div>
</div>
I searched a lot but with no luck ... can anyone tell me where am i going wrong with this .. Any help is appreciated ... Thanks in advance people
The render tag has a model attribute. It works like the model passed from controller to view. You can use it to pass data into the template.
view
<g:each in="${1..tempMap.counter}" var="counter">
<g:set var="key" value="key_${counter}">
<g:render template="travelDetailsToShow" model="${[id: key, value: tempMap[key]]}"/>
</g:each>
template
<div class="col-sm-6" id="${id}">
<div class="form-group">
<label>Departure Date</label>
<span class="input-icon-right input-group">
<input type="text" name="${id}" class="form-control" value="${value}" readonly></input>
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</span>
</div>
</div>
Thanks Emmanuel for your answer ... but i think i wasnt clear enough and misled you to think that the "key" would be static ... As your logic would expect the static value "key" ..... The proper structure of the map is below ...
tempMap = [key_1:v1,anotherkey_1:v2,yetanotherkey_1:v3,key_2:v4,anotherkey_2:v5,yetanotherkey_2:v6]
I havent tried out the solution posted by you but got another solution to work.... code for which is below ...
<div class="col-sm-6" id="key_${counter}">
<div class="form-group">
<label>Departure Date</label>
<span class="input-icon-right input-group">
<input type="text" name="key_${counter}" class="form-control" value='${tempMap?."${'key_' + counter}"}' readonly></input>
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</span>
</div>
</div>
<div class="col-sm-6" id="anotherkey_${counter}">
<div class="form-group">
<label>Return Date</label>
<span class="input-icon-right input-group">
<input type="text" name="anotherkey_${counter}" class="form-control" value='${tempMap?."${'another_' + counter}"}' readonly></input>
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</span>
</div>
</div>
</div>
The problem was that i was not referencing the value in the Map properly... The code that fails is stated below.
<div class="col-sm-6" id="departureDate_${counter}">
<div class="form-group">
<label>Departure Date</label>
<span class="input-icon-right input-group">
**<input type="text" name="departureDate_${counter}" class="form-control" value="${tempMap?.${departureDate_counter}"} readonly></input>** // THIS CODE DOES NOT WORK. This will look for a key ${departureDate_counter} and will through a gsp error that tags have not been closed
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</span>
</div>
</div>
Although i have found a solution to my problem it would be nice if we posted more solutions as i feel that not a lot of solutions are present on the net for grails and gsp ...
I'm using query mobile 1.4.0 and I'm trying to make my flip switch active by default but I'm not really sure how to approach it. I've tried adding selected="selected" to the <input> but it doesn't seem to make a difference. Anyone have any ideas?
<form>
<div class="prof-wrap">
<div class="prof-left">
<div class="prof-txt-wrap">
<div class="text-off">OFF TITLE</div>
<div class="text-off2">OFF TYPE</div>
</div>
</div>
<!-- END prof-left -->
<div class="prof-mid">
<div class="prof-switch">
<input type="checkbox" data-role="flipswitch" name="flip-checkbox-4" id="flip-checkbox-4" data-wrapper-class="custom-size-flipswitch" selected="selected">
</div>
<!--END prof-mid -->
</div>
<!-- END prof-switch -->
<div class="prof-right">
<div class="prof-txt-wrap2">
<div class="text-active">ON TITLE</div>
<div class="text-active2">ON TYPE</div>
</div>
</div>
<!-- END prof-right -->
</div>
<!-- END prof-wrap -->
</form>
According to the Documentation use the checked=""attribute:
<form>
<label for="flip-checkbox-4">Flip toggle switch checkbox:</label>
<input type="checkbox" data-role="flipswitch" name="flip-checkbox-4" id="flip-checkbox-4" checked="">
</form>