1
votes

Problem Statement: I have to show data from two independent models on the JSP.

Say for example There are two models: account and Student.

Attributes of Student Model are editable so, I can make use of modelattribute in the spring form and map the data from jsp to my java object.

Attributes of account are readable only, but as I have already mentioned student model in the modelattribute , in the jsp form and there can only be one modelattribute per jsp form, so I cannot assign the account to the modelattribute in Jsp spring form. In that case, how the data of the account model will be shown in the Jsp.

Secondly, writing: public String requestHandlingMethod(@ModelAttribute Student student, @ModelAttribute Student student)

Is this valid or not, i.e having two @ModelAttribute in Spring handler method

1

1 Answers

2
votes

One approach would be to create a new class which has Student and Account as attributes. This way you only need one @ModelAttribute in your handler method.

Public Class StudentAcctWrapper{
private Student student;
private Account account;

The appropriate fields will be accessible in your view through an instance of StudentAcctWrapper.