Skip to content
Advertisement

How to set a object’s field using another objects field in thymeleaf

I’m trying to set boxes’ elements copied from medicineBox’s values like below. Can anyone help me in this. I need to post medicineOrder model to the controller

JavaScript

I’m using two object here –

  1. medicine and medicineOrder

——————> Controller method to get the page

JavaScript

——————> thymeleaf html page

JavaScript

—————> Controller method to handle the post request

JavaScript

—————-> Class MedicineOrder

JavaScript

Not able to get the MedicineOrder.medicineId and medicineBorder.boxes[*].boxNumber from template to model object.

Advertisement

Answer

After lot of searching I didn’t find any answer which is solving the issue only using thymeleaf. To solve this issue I had to add two hidden input field for medicineId and boxNumber on medicineOrder object and populate those input field using javascript as below. Anyway if anyone find the solution by only using thymeleaf, please let me know.

Populated those fields using javascript

JavaScript

updated template file

JavaScript
Advertisement