title: Springboot Thymeleaf : How to format row according to a condition
body: <p>I have a page that displays the list of all the journals available. I want to write a thymeleaf expression language that highlights the already subscribed journals using there journal id . So for all the subscribed journals the text for the hyper-link href should be "Unsubscribe" and vice verse if its not subscribed.</p>
  
  <pre><code>  &lt;!DOCTYPE html&gt;
      &lt;html xmlns:th="http://www.thymeleaf.org"&gt;
      &lt;head lang="en"&gt;
  
      &lt;title&gt;TBD&lt;/title&gt;
  
      &lt;!--/*/ &lt;th:block th:include="fragments/headinc :: head"&gt;&lt;/th:block&gt; /*/--&gt;
  
      &lt;link rel="stylesheet"
          href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" /&gt;
  
  
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div class="container"&gt;
  
              &lt;h1 th:text="'Hello, ' + ${user.fullname} + '!'" /&gt;
              &lt;p&gt;Manage your subscriptions here&lt;/p&gt;
  
              &lt;form role="form" id="form-search" class="form-inline"
                  th:action="@{/subscriptions}" method="get"&gt;
                  &lt;input type="text" class="form-control" id="filter" name="filter"
                      placeholder="Enter filter"&gt;&lt;/input&gt;
                  &lt;button type="submit" class="btn btn-default"&gt;
                      &lt;span class="glyphicon glyphicon-search"&gt;&lt;/span&gt; Search
                  &lt;/button&gt;
  
                  &lt;a th:href="@{/logout}" class="btn btn-link" role="button"&gt;Logout&lt;/a&gt;
              &lt;/form&gt;
              &lt;div th:if="${not #lists.isEmpty(journals)}"&gt;
                  &lt;form role="form" id="form-subscribe" th:action="@{/subscribe}"
                      method="post"&gt;
                      &lt;input type="hidden" name="journalId" id="journalId" /&gt;
  
                  &lt;/form&gt;
                  &lt;table id="table" class="table"&gt;
                      &lt;thead&gt;
                          &lt;tr&gt;
                              &lt;th&gt;Subject&lt;/th&gt;
                              &lt;th&gt;Filename&lt;/th&gt;
                              &lt;th&gt;Tags&lt;/th&gt;
                              &lt;th&gt;View&lt;/th&gt;
                              &lt;th&gt;Action&lt;/th&gt;
                          &lt;/tr&gt;
                      &lt;/thead&gt;
                      &lt;tbody&gt;
                          &lt;tr th:each="journal : ${journals}"&gt;
                              &lt;td th:text="${journal.subject}"&gt;&lt;a
                                  href="/product/${product.id}"&gt;Id&lt;/a&gt;&lt;/td&gt;
                              &lt;td th:text="${journal.filename}"&gt;Product Id&lt;/td&gt;
                              &lt;td th:text="${journal.tags}"&gt;Description&lt;/td&gt;
                              &lt;td&gt;&lt;a&gt;View&lt;/a&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;a id="href"
                                  th:href="'javascript:subscribe(\'' + ${journal.id} + '\');'"&gt;Subscribe&lt;/a&gt;
  
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/tbody&gt;
  
                  &lt;/table&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/body&gt;
      &lt;script type="text/javascript"&gt;
          function subscribe(journalId) {
              $('#journalId').val(journalId);
              $('#form-subscribe').submit();
  
          }
      &lt;/script&gt;
  
  
      &lt;script type="text/javascript" th:inline="javascript"&gt;
          /*&lt;![CDATA[*/
  
          $(document).ready(function() {
             var modelAttributeValue = [[${subscriptions}]];
             console.log(modelAttributeValue);
             alert(modelAttributeValue);
  
             var array = modelAttributeValue.split(';');
             console.log(array);
             alert(array);
          });
  
          /*]]&gt;*/
      &lt;/script&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>Controller </p>
  
  <pre><code>    @Controller
      public class SubscriptionController {
  
          @Autowired
          private SubscriberService subscriberService;
  
          @RequestMapping(value = "/subscribe", method = RequestMethod.POST)
          String subscribe(Model model, @RequestParam("journalId") Integer journalId) {
  
              JournalToken token = (JournalToken) SecurityContextHolder.getContext().getAuthentication();
              Account user = (Account) token.getCredentials();
              model.addAttribute("user", user);
  
              Journal journal = this.subscriberService.findJournalById(journalId);
  
              this.subscriberService.subscribeJournalForSubscriber(journal, user);
  
              return "redirect:subscriptions";
          }
  
          @RequestMapping(value = "/subscriptions", method = RequestMethod.GET)
          String list(Model model) {
  
              JournalToken token = (JournalToken) SecurityContextHolder.getContext().getAuthentication();
              Account user = (Account) token.getCredentials();
              model.addAttribute("user", user);
  
              ArrayList&lt;Journal&gt; journals = this.subscriberService.FindAllJournals();
  
              model.addAttribute("journals", journals);
  
              StringBuilder sub = new StringBuilder();
              ArrayList&lt;Subscription&gt; subscribed = this.subscriberService.getSubscribedJournalsForSubscriber(user);
  
              model.addAttribute("subscriptions", subscribed);
  
              return "subscriptions";
          }
      }
  </code></pre>
  
  <p>Model subscriptions </p>
  
  <pre><code>    @Entity
      @Table(uniqueConstraints={@UniqueConstraint(columnNames={"userId", "journalId"})})
      public class Subscription {
  
          @Id
          @GeneratedValue(strategy = GenerationType.AUTO)
          private Integer id;
  
          @Version
          private Integer version;
  
          private Integer userId;
          private Integer journalId;
  
          public void setId(Integer id) {
              this.id = id;
          }
  
          public Integer getId() {
              return this.id;
          }
  
          public void setVersion(Integer version) {
              this.version = version;
          }
  
          public Integer getVersion() {
              return this.version;
          }
  
          public void setUserId(Integer userId) {
              this.userId = userId;
          }
  
          public Integer getUserId() {
              return this.userId;
          }
  
          public void setJournalId(Integer journalId) {
              this.journalId = journalId;
          }
  
          public Integer getJournalId() {
              return this.journalId;
          }
      }
  </code></pre>