Spring Boot Thymeleaf Could not parse as expression with an url - spring

I'm putting a button on page 1 to navigate to page 2. Page 1 and 2 are on different controllers.
This is the code of my button. The pid is the ID of the project. p.id gives the ID of the project. But I don't know what the problem here is.
<td><a th:href="#{/projects/project/{pid}/clusters(pid=${p.id})" class="btn btn-info" role="button">Clusters</a></td>
The exception:
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "#{/projects/project/{pid}/clusters(pid=${p.id})" (projects:53)

You've missed one curly bracket at the end of expression
<a th:href="#{/projects/project/{pid}/clusters(pid=${p.id})}" class="btn btn-info" role="button">Clusters</a>

Related

Thymeleaf th:onclick event - calling confirm function

I am new to Thymeleaf. Recently I stumbled in the following situation. Here is a piece of my Thymeleaf html page:
<!-- an delete button link -->
<a th:href="#{/employees/delete(employeeId=${tempEmployee.emplId},firstName=${tempEmployee.firstName},lastName=${tempEmployee.lastName})}"
class="btn btn-danger btn-sm py-1 "
th:onclick="if(!(confirm('Are you sure you want to delete this employee ?') )) return false" >
Delete
</a>
This code works fine as intended. However I want to add employee name as part of the confirmation. Here is the code:
<!-- an delete button link -->
<a th:href="#{/employees/delete(employeeId=${tempEmployee.emplId},firstName=${tempEmployee.firstName},lastName=${tempEmployee.lastName})}"
class="btn btn-danger btn-sm py-1 "
th:onclick="if(!(confirm('Are you sure you want to delete this employee ' + '\'+${tempEmployee.firstName}+\'' +'?' ) )) return false" >
Delete
</a>
Unfortunately the result is:
Are you sure you want to delete this employee
'+${tempEmployee.firstName}+'.
Looks like Thymeleaf does not recognize ${tempEmployee.firstName}. It has no problem with it in th:href tag but does not like it in th:onclick.
I would appreciate if somebody can turn me into the right direction.
Not sure exactly what the problem is (though it may be related to onclick vs th:onclick. Regardless, I think a format more like this will work (with some added benefits like no JavaScript injection).
<!-- an delete button link -->
<a
th:href="#{/employees/delete(employeeId=${tempEmployee.emplId},firstName=${tempEmployee.firstName},lastName=${tempEmployee.lastName})}"
class="btn btn-danger btn-sm py-1 "
th:data-confirm-delete="|Are you sure you want to delete this employee ${tempEmployee.firstName}?|"
onclick="if (!confirm(this.getAttribute('data-confirm-delete'))) return false"
>
Delete
</a>
(Notice I'm using onlick and not th:onclick.
Instead of this line in above code ---onclick="if (!confirm(this.getAttribute('data-confirm-delete'))) return false">
You can write as:
onclick="return confirm(this.getAttribute('data-confirm-delete'))"

Refresh view content when there is change in database laravel

I am using laravel queue to upload a csv file. And, I have used a column completed on the database table.
So, by default the value of this column will be 0 and as soon as the job is completed this column's value will be updated to 1 for that particular row.
Similarly, during uploading phase, this value will be 2 and if some error occured during upload or if some row can't be imported then the value will be 3
On front end, I have a simple button like:
#if($r->completed == 1)
<a class="btn btn-xs btn-primary d-inline-block" href="{{url('/?property='.$r->id)}}">Property</a>
#elseif($r->completed == 2)
<a class="btn btn-xs btn-warning d-inline-block" href="#">Pending</a>
#elseif($r->completed == 3)
<a class="btn btn-xs btn-secondary d-inline-block" href="{{route('property.create',$r->id)}}">Par. Completed</a>
#else
<a class="btn btn-xs btn-secondary d-inline-block" href="{{route('property.create',$r->id)}}">Property</a>
#endif
Yeah, its working totally fine. Here, we need to refresh to check the recent status. However, my requirement is to update the status without refreshing the page.
After some searching, I find that sending ajax request on certain interval might be an option. However, it don't seems ideal, so I don't want to go with that.
Is there any better option available? Currently, I am using jquery/javascript (not any js framework like vue,react).

ui-sref does not produce correct href with parameter

I'm trying to use ui-router to change state and pass a GUID parameter to my controller. I have this working using Kendo (different syntax) so I know what I'm aiming for. I cannot for the life of me figure out what the deal is. I have searched far and wide and I believe that I have the correct syntax for the ui-sref. Here it is:
<a ui-sref="clientEdit({ clientId: '{{vm.clientModel.id}}' })">Edit Link</a>
Produces this output in the rendered view (notice missing id):
<a ui-sref="clientEdit({ clientId: 'bfd50b6c-6542-48c5-adf7-8c1a21caf421' })" href="#/clientEdit/">Edit Link</a>
Here is my state:
.state("clientEdit", {
url: "/clientEdit/:clientId",
templateUrl: "/CompanyDashboard/ClientsCrud",
controller: "DashboardClientsCtl",
controllerAs: "vm"
})
When I hardcode the ID into the ui-sref it works as expected and produces the correct href for the tag. Like this:
<a ui-sref="clientEdit({clientId:'bfd50b6c-6542-48c5-adf7-8c1a21caf421'})">Hard code Edit Link</a>
The hard-coded ID tag produces this output in the rendered view (exactly as I would expect):
<a ui-sref="clientEdit({clientId:'bfd50b6c-6542-48c5-adf7-8c1a21caf421'})" href="#/clientEdit/bfd50b6c-6542-48c5-adf7-8c1a21caf421">Hard code Edit Link</a>
So, my question is: Am I missing something here? I really believe this should work as I'm already doing this successfully using a Kendo template for a different route.
Just in case you care, here is the working kendo template code:
template: "<a ui-sref='clientDetails({clientId:\"#=id#\"})'>#=customerNumber#</a>"
I have tried changing quotes to double as in the Kendo example, removing the quotes, removing the {{ }} from the Id expression. No Joy.
Thanks for any and all help.
Solution here is to NOT wrap the param with {{}}
// instead of this
<a ui-sref="clientEdit({ clientId: '{{vm.clientModel.id}}' })">Edit Link</a>
// use this
<a ui-sref="clientEdit({ clientId: vm.clientModel.id})">Edit Link</a>
The content of a vm.clientModel.id is already a string, and will be correctly passed as string (it is GUID for JS it is string)
So, I thought I had tried this yesterday before I posted the question, but I had not. Here is the correct syntax:
<a class="btn btn-sm btn-primary" ui-sref="clientEdit({ clientId: {{'vm.clientModel.id'}} })">Edit Client Test</a>
Notice that the single quotes are INSIDE the {{ }} and not on the outside. Simple eh?
This HTML produces the correct HREF like this:
<a class="btn btn-sm btn-primary" ui-sref="clientEdit({ clientId: vm.clientModel.id })" href="#/clientEdit/bfd50b6c-6542-48c5-adf7-8c1a21caf421">Edit Client Test</a>

Angular ng-show not working

I have a button in a directive that I only want to appear on the last object in the array. The ng-show evaluates an expression on the controller.
<button class="btn btn-danger button-xs tsid-btn-sch-pad
glyphicon glyphicon-remove"
type="submit" ng-click=""
ng-show="{{$index == sc.schedule.length - 1}}"></button>
The expression is being correctly evaluated in the browser, but the button is displaying anyway.
So the difference between the highlighted row and the one above where the delete button is not displaying is that ng-hide was added to the class attribute of the row above and it has not been added to the row that is displaying the delete button incorrectly. But I don't know why that update isn't taking place since the ng-show expression is being updated.
Try using the $last variable
<button class="btn btn-danger button-xs tsid-btn-sch-pad
glyphicon glyphicon-remove"
type="submit" ng-click=""
ng-show="$last"></button>
http://plnkr.co/edit/Sf6Xw7YjPlfUuqyHIWng?p=preview

Unable to click on list element from drop down

Using Selenium WebDriver, I'm trying to click on Manual Testing option from Testing menu from http://guru99.com/ Manual Testing option appears after hovering mouse on Testing. In order to achieve above, I did following -
testing = $driver.find_element(:xpath, "//li[#class='item118 parent']")
mt = $driver.find_element(:xpath, "//li[#class='item119']/a")
$driver.action.move_to(testing).move_to(mt).perform
mt.click
But, sometimes error for line #3 above code -
Selenium::WebDriver::Error::MoveTargetOutOfBoundsError: Offset within element ca
nnot be scrolled into view: (85, 21): http://guru99.com/software-testing.html
and sometimes error for line #4 in above code -
Selenium::WebDriver::Error::ElementNotVisibleError: Element is not currently vis
ible and so may not be interacted with
Please help me to resolve this issue without executing javascript.
Here is HTML code -
<li class="item118 parent">
<a class="item" href="/software-testing.html"> Testing </a>
<span class="dropdown-spacer"></span>
<div class="dropdown columns-1 " style="width:180px;">
<div class="column col1" style="width:180px;">
<ul class="l2">
<li class="item119">
<a class="item" href="/software-testing.html"> Manual Testing </a>
</li>
.
.
.
You can try with partial_link_text:
testing = $driver.find_element(:partial_link_text, "Testing")
$driver.action.move_to(testing).perform
mt = $driver.find_element(:partial_link_text, "Manual Testing")
mt.click

Resources