У меня есть этот шаблон html / thymleaf, который работал с операторами th: if. В коде операторы if используются только для отображения div и его содержимого, если в базе данных SQL есть что-то в этом поле.
Я пытаюсь добавить новую частную строку cyberAttackInsurance и использовать тот же код для ее отображения, но выдает эту ошибку: Вызов метода: Попытка вызова метода isEmpty () для нулевого объекта контекста
Почему это проблема с этим битом кода, а не с остальным кодом? Я попытался написать это по-разному, используя th: block и th: switch th: case, но мне это тоже не понравилось ... что вызвало другую ошибку. Буду очень признателен за любые идеи, как исправить эту ошибку или узнать, почему это происходит!
Вот код с добавленной CyberAttackInsurance.
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="fragments/layout" th:with="currentPage='dashboard'">
<head>
<title>Home</title>
</head>
<body>
<div class="container" layout:fragment="content">
<div class="row">
<br/>
<div class="ui segment">
<div class="ui container">
<div th:if="${param.sentMessageFail}">
<div class="ui warning message">
<p style="color: #ffffff; text-align:left;"> Oops! Something went wrong. Please try submitting your form again.</p>
</div>
</div>
</div>
<div th:if="${param.sentMessage}">
<div class="ui positive message">
<p style="color: #ffffff; text-align:left;"> Sent Successfully!</p>
</div>
</div>
</div>
<div class="col m6 xl3 valign-wrapper">
<div th:if="${access!=null and !access.micrositeLink.isEmpty()}" class="card xs scale-transition scale-out z-depth-0">
<a th:href="${access.micrositeLink}" target="_blank">
<div class="card-image">
<img src="images/ReferralMicrosite.jpg"/>
</div>
</a>
<div class="card-content">
<p>Submit a new opportunity</p>
</div>
</div>
</div>
<div class="col m6 xl3 valign-wrapper">
<div th:if="${access!=null and !access.partnerPortalLink.isEmpty()}" class="card xs scale-transition scale-out z-depth-0">
<a th:href="${access.partnerPortalLink}" target="_blank" style="background-color:#2f373e;color:white;">
<div class="card-image">
<img src="images/ProspectManager.png"/>
</div>
</a>
<div class="card-content">
<p>Track all your referral business</p>
</div>
</div>
</div>
<div class="col m6 xl3 valign-wrapper">
<div th:if="${#authorization.expression('hasRole(''ROLE_ADMIN'')')} or ${loggedUser.client.ams360Affiliate == 'All Access – Traditional'}" class="card xs scale-transition scale-out z-depth-0">
<a href="https://platform.vertafore.com/#/" target="_blank">
<div class="card-image">
<img src="images/ams360.png"/></div>
</a>
<div class="card-content">
<p>Agency Management System</p>
</div>
</div>
</div>
<div class="col m6 xl3 valign-wrapper">
<div th:if="${#authorization.expression('hasRole(''ROLE_ADMIN'')')} or ${loggedUser.client.ams360Affiliate == 'All Access – Traditional'}" class="card xs scale-transition scale-out z-depth-0">
<a href="https://rating.vertafore.com/UserInterface/main/login.aspx" target="_blank">
<div class="card-image">
<img src="images/plRating.png"/>
</div>
</a>
<div class="card-content">
<p>Personal Lines Comparative Rater & Quoting</p>
</div>
</div>
</div>
</div>
<div class="row flex" style="margin-bottom:0;">
<div class="col s12 xl6">
<div class="row" style="margin-bottom:-5px;">
<div class="col s6 m4 scale-transition scale-out">
<a th:href="@{/carriers}">
<div class="white red-text text-accent-2 valign-wrapper ">
<span class="center-align" style="width:100%; padding:10px;">
<img src="/images/menu_icons/icons8-handshake-48.png"/>
<br/>
<span class="grey-text text-darken-2">Know your carriers!</span>
</span>
</div>
</a>
</div>
<div th:if="${access!=null and !access.indioCustomerApplicationSite.isEmpty()}" class="col s6 m4 scale-transition scale-out">
<a th:href="${access.indioCustomerApplicationSite}" target="_blank">
<div class="white text-accent-4 valign-wrapper ">
<span class="center-align" style="width:100%; padding:10px;">
<img class="responsive-img" src="images/Indio.png"/>
<br/>
<span class="grey-text text-darken-2">Online Applications for your customers to complete</span>
</span>
</div>
</a>
</div>
<div class="col s6 m4 scale-transition scale-out">
<a target="_blank" href="https://www.university.com/">
<div class="white valign-wrapper ">
<span class="center-align" style="width:100%; padding:10px;">
<img src="/images/menu_icons/icons8-reading-48.png"/>
<br/>
<span class="grey-text text-darken-2">University</span>
</span>
</div>
</a>
</div>
<div th:if="${access!=null and !access.cyberAttackInsurance.isEmpty()}" class="col s6 m4 scale-transition scale-out">
<a th:href="${access.cyberAttackInsurance}" target="_blank">
<div class="white valign-wrapper ">
<span class="center-align" style="width:100%; padding:10px;">
<img class="responsive-img" src="images/vendor_logos/CAI.jpg"/>
<br/>
<span class="grey-text text-darken-2">Cyber Attack Insurance</span>
</span>
</div>
</a>
</div>
<div th:if="${access!=null and !access.hiscoxQuotingSite.isEmpty()}" class="col s6 m4 scale-transition scale-out">
<a th:href="${access.hiscoxQuotingSite}" target="_blank">
<div class="white black-text text-accent-4 valign-wrapper ">
<span class="center-align" style="width:100%; padding:10px;">
<img class="responsive-img" src="images/vendor_logos/hiscox_logo.gif"/>
<br/>
<span class="grey-text text-darken-2">Online Quoting site for <strong>P&C licensed Affiliates only</strong></span>
</span>
</div>
</a>
</div>
<div th:if="${access!=null and !access.CRQLink.isEmpty()}" class="col s6 m4 scale-transition scale-out">
<a th:href="https://esubmissions.thehartford.com/" target="_blank">
<div class="white black-text valign-wrapper " >
<span class="center-align" style="width:100%; padding:10px;">
<img class="responsive-img" src="images/hartford-logo.png"/>
<br/>
<span class="grey-text text-darken-2">The Hartford Pocket </span>
</span>
</div>
</a>
</div>
<div th:if="${access!=null and !access.hartfordCustomerQuotingSite.isEmpty()}" class="col s6 m4 scale-transition scale-out">
<a th:href="${'mailto:?body=Thank you for your interest in our Commercial Lines Insurance, here is a link to get a quote online NOW! '+access.hartfordCustomerQuotingSite+'&subject=Thank you for your interest!'}" >
<div class="white black-text valign-wrapper" >
<span class="center-align" style="width:100%; padding:10px;">
<i class="material-icons center-align" style="font-size:3.25rem">mail_outline</i>
<br/>
<span class="grey-text text-darken-2">Email: Link to Hartford Customer Facing Rater </span>
</span>
</div>
</a>
</div>
</div>
</div>
<div class="col s12 xl6">
<div class="white scale-transition scale-out" style="padding:5px 10px">
<h6><Strong>Latest Announcements</Strong></h6>
<table class="table striped" data-toggle="table" data-classes="table-no-bordered" data-striped="true" data-pagination="true" data-page-size="3">
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr th:each="announcement : ${announcements}">
<td>
<a th:href="@{|/announcement/${announcement.id}|}">
<h6><strong th:text="${announcement.heading}">Announcement Heading</strong></h6>
<small class="designation" th:text="${announcement.description}">Description for this announcement.</small></a>
</td>
<td class="center-align">
<h6><strong th:if="${announcement.createdDate}" th:text="${#dates.day(announcement.createdDate)}">28</strong></h6>
<h6><strong th:if="${announcement.createdDate}" th:text="${#dates.monthName(announcement.createdDate)}">Feb</strong></h6>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="row">
<div class="col s12">
<div class="white scale-transition scale-out " style="padding:5px 10px">
<h6 style="margin-bottom:-40px;"><strong>Resources Directory</strong></h6>
<table class="table striped highlight" data-toggle="table" data-classes="table-no-bordered" data-striped="true" data-search="true" data-pagination="true" data-page-size="4">
<thead>
<tr>
<th>Name</th>
<th>Category</th>
<th>Services</th>
</tr>
</thead>
<tbody>
<tr th:each="resource : ${resources}">
<td><a th:href="@{/}" th:text="${resource.name}"></a></td>
<td th:text="${resource.category}"></td>
<td th:text="${resource.services}"></td>
</tr>
</tbody>
</table>
</div>
</div>
<script>
$(document).ready(function(){
$('.scale-out').addClass("scale-in");
});
</script>
</div>
</div>
</body>
</html>
Вот модель:
@Entity
public class ResourceWebsiteAccess {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ResourceWebsiteAccessId")
private Long id;
private String micrositeLink;
private String partnerPortalLink;
private String hartfordCustomerQuotingSite;
private String hiscoxQuotingSite;
private String indioCustomerApplicationSite;
private String CRQLink;
private String cyberAttackInsurance;
@OneToOne
@JoinColumn(name = "client")
private Client client;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getMicrositeLink() {
return micrositeLink;
}
public void setMicrositeLink(String micrositeLink) {
this.micrositeLink = micrositeLink;
}
public String getPartnerPortalLink() {
return partnerPortalLink;
}
public void setPartnerPortalLink(String partnerPortalLink) {
this.partnerPortalLink = partnerPortalLink;
}
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
public String getHartfordCustomerQuotingSite() {
return hartfordCustomerQuotingSite;
}
public void setHartfordCustomerQuotingSite(String hartfordCustomerQuotingSite) {
this.hartfordCustomerQuotingSite = hartfordCustomerQuotingSite;
}
public String getHiscoxQuotingSite() {
return hiscoxQuotingSite;
}
public void setHiscoxQuotingSite(String hiscoxQuotingSite) {
this.hiscoxQuotingSite = hiscoxQuotingSite;
}
public String getIndioCustomerApplicationSite() {
return indioCustomerApplicationSite;
}
public void setIndioCustomerApplicationSite(String indioCustomerApplicationSite) {
this.indioCustomerApplicationSite = indioCustomerApplicationSite;
}
public String getCRQLink() {
return CRQLink;
}
public void setCRQLink(String CRQLink) {
this.CRQLink = CRQLink;
}
public String getCyberAttackInsurance() {
return cyberAttackInsurance;
}
public void setCyberAttackInsurance(String cyberAttackInsurance) {
this.cyberAttackInsurance = cyberAttackInsurance;
}
}