Reputation: 55
I have a Spring boot application with a flow like this.
It's all good up to this point but what I want to do is when user gets to login page, I want to populate user's email into the email field and let user to enter his/her password to continue.
My email field looks like this:
<input type="email"
id="userLoginFormEmail"
class="form-control mb-4"
th:field="*{email}"
placeholder="Your email" required />
When the user gets redirected to login page, I'm adding user's email to model attribute like this:
model.addAttribute("userEmail", userEmail);
return "user/login";
So, how do I pre populate email field is userEmail
attribute is not null?
UPDATE
I have an alert in the login page which appears fine when an activation url visited. It look like this
<div class="alert alert-info mt-5" role="alert" th:if="${userEmail != null}">
<strong>Your account is activated. Please login to proceed.</strong>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
So, userEmail
works fine but still can't show it in the email field.
Upvotes: 0
Views: 3275
Reputation: 20487
In the controller, set the users email on the userEmail
object (before the page is rendered).
Upvotes: 1
Reputation: 759
Add the attribute th:value="userEmail"
to the input field in the template
Upvotes: 1