Prasanth A R
Prasanth A R

Reputation: 4174

how to set @modelattribute boolean value inside html

the code shows below

the Users value from @Modelattribute is boolean an how to set this condition

 <div  th:each="s: ${Users}"> 
        <div  th:if="${s == true"  >
            <header th:include="../templates/SellerTemplate :: header" id="header">
            </header>
        </div>
        <div th:if="${s != true}" >
            <header  th:include="../templates/homeTemplate :: header" id="header">
            </header> 
        </div> 

    </div>

the @Modelattribue

public boolean users ;
@ModelAttribute("Users")
public boolean getloggeduser() {
 if(securityDAO.getLoggedUserAccount()!= null) { 
    users=true;
     }
 else{ 
     users=false;
 } 
    return users;
}

the main problem is how to set the attribute value to th:each or any other statement are available? please share your answer

Upvotes: 0

Views: 1513

Answers (1)

geoand
geoand

Reputation: 64059

I believe that you are looking for something like this:

<div th:if="${Users == true}"  >
   <header th:include="../templates/SellerTemplate :: header" id="header">
   </header>
</div>
<div th:if="${Users == false}" >
   <header  th:include="../templates/homeTemplate :: header" id="header">
   </header> 
</div> 

You should only use th:each for lists or arrays, there is no point using it for other types.

Upvotes: 1

Related Questions