Sachin
Sachin

Reputation: 459

<form:form modelAttribute .. using two beans in JSP

This is a spring based application. My form definition in JSP is as below,

<form:form modelAttribute="article" enctype="multipart/form-data" method="POST"
           action="${sendEmailUrl}" name="postAd" id="postAd">

I want to display some data from 'article' bean on my form so I've defined modelAttribute='article'. Till here it is all fine. But on submit of the form, I want to collect data in different bean than article. Since I can define modelAttribute only once in the form, can someone please advise how can I use two beans in JSP?

P.S. In case I am not clear, let me give more details. On submit of form, data entered by user will be collected in bean 'X' and email will be sent using java email. But bean 'Y' (article in this case) is holding some values which needs to be displayed on the form.

Hope I am clear.

Upvotes: 0

Views: 1475

Answers (1)

jelies
jelies

Reputation: 9290

You could create a FormBean class, containing the two beans you said. Use this new class as a modelAttribute in your form and you will be able to access to both object's properties.

public class FormBean {

    public Article article;

    public YourOtherObject yourOtherObject;

}

Upvotes: 2

Related Questions