Cant get Exception object on default error.html Thymeleaf page - spring-boot

I have a Spring Boot application and want to display the exception on the error page.
I put the error.html page in the template directory and I can see the change, but the exception variable keeps coming back as null. I can see all the other data like message and stacktrace.
I took this from several examples. What is missing?
Thymeleaf
<div class="row rowDesign">
<div class="col-md-4 ml-auto">
<span class="legend">Date</span>
</div>
<div class="col-md-8">
<span th:text="${timestamp}"></span>
</div>
</div>
<div class="row rowDesign">
<div class="col-md-4 ml-auto">
<span class="legend">Error</span>
</div>
<div class="col-md-8">
<span th:text="${error}"></span>
</div>
</div>
<div class="row rowDesign">
<div class="col-md-4 ml-auto">
<span class="legend">Status</span>
</div>
<div class="col-md-8">
<span th:text="${status}"></span>
</div>
</div>
<div class="row rowDesign">
<div class="col-md-4 ml-auto">
<span class="legend">Message</span>
</div>
<div class="col-md-8">
<span th:text="${message}"></span>
</div>
</div>
<div class="row rowDesign">
<div class="col-md-4 ml-auto">
<span class="legend">Exception</span>
</div>
<div class="col-md-8">
<span th:text="${exception}"></span>
</div>
</div>
<div class="row rowDesign">
<div class="col-md-4 ml-auto">
<span class="legend">Trace</span>
</div>
<div class="col-md-8">
<span th:text="${trace}"></span>
</div>
</div>

Add this to your application.properties:
server.error.include-exception=true
server.error.include-stacktrace=always
These properties are not enabled by default (See https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html)

Related

Web pages gets distorted when ever I try to specify a variable on my route

I tried parsing a variable through my route and but the CSS isn't rendered on the page and my page shows purely html=
Here is my web route;
Route::get('/create-transaction/{id}', 'AdminController#create')->name('Create Transaction');
And here is my controller;
public function create($id){
$users = User::orderBy('id', 'desc')->paginate(100);
return view('create-transaction')->with(compact('users', 'id'));
}
I get this sam error with every other web page on my website when. once I parse in a variable through my route, the whole page losses it's formatting. I've tried the same page without parsing variables and it works fine but it's a different case when I parse in a variable
Here is my view page;
#extends('layouts.admin')
#section('content')
<section class="content-top-margin page-title-small border-bottom-light border-top-light">
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-12 wow fadeInUp" data-wow-duration="300ms">
<!-- page title -->
<h1 class="black-text">Create Transaction</h1>
<!-- end page title -->
</div>
<div class="col-md-6 col-sm-12 breadcrumb text-uppercase wow fadeInUp" data-wow-duration="600ms">
<!-- breadcrumb -->
<ul>
<li>Dashboard</li>
<li>Withdrawals</li>
<li>Change Password</li>
</ul>
<!-- end breadcrumb -->
</div>
</div>
</div>
</section>
<section class="wow fadeIn border-top">
<div class="container">
<div class="row">
<div class="col-md-5 col-sm-10 center-col">
#if (session('error'))
<div class="alert alert-danger">
{{ session('error') }}
</div>
#endif
#if (session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
#endif
<form action="/create-transaction" method="POST">
#csrf
<div class="form-group">
<div class="col-md-6">
<label for="exampleInputEmail1">Date</label>
<input type="text" name="current-password" class="form-control input-round big-input" required>
</div>
<div class="col-md-6">
<label for="exampleInputEmail1">Amount</label>
<input type="text" name="current-password" class="form-control input-round big-input" required>
</div>
</div>
<div class="form-group">
<div class="col-md-3">
<label for="exampleInputEmail1">Type</label>
<input type="text" name="current-password" class="form-control input-round big-input" required>
</div>
<div class="col-md-9">
<label for="exampleInputEmail1">Description</label>
<input type="text" name="current-password" class="form-control input-round big-input" required>
</div>
</div>
<button class="btn btn-black btn-small btn-round no-margin-bottom" type="submit">Create Transaction</button>
<!-- end button -->
</form>
</div>
</div>
</div>
</section>
#endsection

How to load data dynamically on template?

I have this model that I have multiple instances of it in a list. I want to pass this to my UI and have the UI figure out how to draw this.
data class InfoModel(val icon: String, val title: String, val text: String {
}
The controller.
#GetMapping("/index")
fun start(model: Model): String {
val list = getList()
model ["list"] = list
return "index"
}
Now in the UI I would like this to be duplicated but I don't know how.
<div class="row">
<div class="col-md-6 col-lg-3 d-flex align-self-stretch ftco-animate">
<div class="media block-6 services d-block text-center">
<div class="d-flex justify-content-center"><div class="icon color-1 d-flex justify-content-center mb-3"><span class="align-self-center icon-layers"></span></div></div>
<div class="media-body p-2">
<h3 class="heading">Title</h3>
<p>Text here.</p>
</div>
</div>
</div>
</div>
What I tried and it doesn't display anything.
{{#list}}
<div class="col-md-6 col-lg-3 d-flex align-self-stretch ftco-animate">
<div class="media block-6 services d-block text-center">
<div class="d-flex justify-content-center">
<div class="icon color-1 d-flex justify-content-center mb-3"><span
class="align-self-center icon-{{icon}}"></span></div>
</div>
<div class="media-body p-2">
<h3 class="heading">{{title}}</h3>
<p>{{text}}</p>
</div>
</div>
</div>
{{/list}}
Big thanks to JBNizet for helping me through this. (You should post the answer, you did all the hard work).
{{#list}}
<div class="col-md-6 col-lg-3 d-flex align-self-stretch ftco-animate">
<div class="media block-6 services d-block text-center">
<div class="d-flex justify-content-center">
<div class="icon color-1 d-flex justify-content-center mb-3"><span
class="align-self-center icon-{{icon}}"></span></div>
</div>
<div class="media-body p-2">
<h3 class="heading">{{title}}</h3>
<p>{{text}}</p>
</div>
</div>
</div>
{{/list}}
Reference:
https://scalate.github.io/scalate/documentation/mustache.html#Non_Empty_Lists

How to click on link using Selenium in Ruby on Rails?

HTML code:
<div class="card-body">
<div class="row align-items-center mb-4">
<div class="col">
<h1>Data and Tools</h1>
</div>
</div>
<a href="/reports">
<div class="row my-4 align-items-center clickable">
<div class="col my-3">
<span class="semi-bold">Reports</span>
<div class="stamp-md">
Create, run and schedule reports.
</div>
</div>
<div class="col-1 text-right">
<i class="fas fa-chevron-right gray-light small"></i>
</div>
</div>
</a>
<hr class="inner-divider">
Ruby code:
wait.until { #browser_def.find_element(css: ".card-body > a")}.attribute("href").text("Reports").click()
How can I click link which stands for 'Reports'?
I have found the correct answer for it:
wait.until { #browser_def.find_elements(css: 'a[href$="/reports"] div.clickable').first}.click()

Undefined variable: user (View: C:\xampp\htdocs\myproject\resources\views\works.blade.php)

I install Auth in my laravel project. In my user table i define a role colum for define Teacher and Student. so in my blade page I want to give access some part for the teacher and hide that part for the student. But I can't do that.
Here is my code: this part only for the teacher.
#if($user->role==Teacher)
<div class="">
<div class="">
<div class="col-md-7 col-md-offset-3">
{!! Form::open(['files'=>true])!!}
<div class="panel panel-default">
<div class="panel-heading">Submit your works</div>
<div class="panel-body">
<div class="form-group>">
<label>Write a new title</label>
<textarea class="form-control" name="assainments" id="assainments"></textarea>
</div>
</div>
<div class="panel-footer clearfix">
<div class="row">
<div class="col-md-6">
<label for="file-upload" class="custom-file-upload">
<i class="glyphicon glyphicon-paperclip"></i>
</label>
<input id="file-upload" name="status_file_upload" type="file"/>
</div>
<div class="col-md-6">
<button class="btn btn-info pull-right btn-am"><i class="fa fa-plus">Add works</i></button>
</div>
</div>
</div>
</div>
#endif
To use the $userin your view you need to pass it from the controller or the method from which you are calling the view.<br/>
Or instead of$useryou can useAuth::user()`:
#if(Auth::user()->role==Teacher)

bootstrap in view of 768px, the image will not be displayed

I'm currently working with bootstrap grid system and got the following problem:
the solution should be work like that: http://ciiznv.axshare.com/#c=2
<div class="row ">
<div class="col-md-6 col-sm-6 col-xs-12 bg-two col-sm-height col-middle nopadding">
<div class="col-md-6 col-sm-12 col-xs-12 col-sm-height col-middle">
<div class="item">
<div class="content">
<h2>Text one</h2>
<p>lorem ipsum dorem</p>
</div>
</div>
</div>
<div class="col-md-6 col-sm-12 col-xs-12 col-sm-height col-middle nopadding ">
<div class="item nopadding">
<div class="content">
<img class="lazyload" sizes="(min-width: 40em) 80vw, 100vw"
srcset="http://lorempixel.com/356/150/ 375w, http://lorempixel.com/480/150/ 480w, http://lorempixel.com/768/250/ 768w, http://lorempixel.com/480/480/ 800w" alt="a picture" />
</div>
</div>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-12 bg-three col-sm-height col-middle nopadding">
<div class="col-md-6 col-sm-12 col-xs-12 col-sm-height col-middle">
<div class="item">
<div class="content">
<h2>Text two</h2>
<p>lorem ipsum dorem dolor</p>
</div>
</div>
</div>
<div class="col-md-6 col-sm-12 col-xs-12 col-sm-height col-middle nopadding">
<div class="item nopadding">
<div class="content">
<img class="lazyload" sizes="(min-width: 40em) 80vw, 100vw"
data-srcset="http://lorempixel.com/356/150/ 375w, http://lorempixel.com/480/150/ 480w, http://lorempixel.com/768/250/ 768w, http://lorempixel.com/480/480/ 800w" alt="a picture" />
</div>
</div>
</div>
</div>
</div>
But in view of 768px, the image will not be displayed
I think that you are missing the .img-responsive class on your images.
See this fiddle

Resources