如何将数据绑定到弹簧形式列表

如何将数据绑定到弹簧形式列表

本文介绍了如何将数据绑定到弹簧形式列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有背衬物体的弹簧形式。表格就像这样 -

I have a spring form with having backing object for it. The form is like this-

<sf:form cssClass="form-horizontal" commandName="campaignModel" method="post">
<sf:input path="campaign.name" class="form-control" />
<sf:input path="landingPageModels.landingPage.url" class="form-control" />
</sf:form>

模型类(表格支持对象) -

Model class(Form backing Object) -

CampaignModel.java

public class CampaignModel {
private Campaign campaign = new CampaignImpl();
private List<LandingPageModel> landingPageModels = new Arraylist<LandingPageModel>;
public Campaign getCampaign() {
    return campaign;
}
public void setCampaign(Campaign campaign) {
    this.campaign = campaign;
}
public List<LandingPageModel> getLandingPageModels() {
    return landingPageModels;
}
public void setLandingPageModels(List<LandingPageModel> landingPageModels) {
    this.landingPageModels = landingPageModels;
}

LandingPageModel.java 是 -

public class LandingPageModel {
private LandingPage landingPage = new LandingPageImpl();
private List<LandingPageParameterImpl> landingPageParameters = new ArrayList<LandingPageParameterImpl>();

public LandingPage getLandingPage() {
    return landingPage;
}
public void setLandingPage(LandingPage landingPage) {
    this.landingPage = landingPage;
}
public List<LandingPageParameterImpl> getLandingPageParameters() {
    return landingPageParameters;
}
public void setLandingPageParameters(List<LandingPageParameterImpl> landingPageParameters) {
    this.landingPageParameters = landingPageParameters;
}
}

LandingPage.java 是 -

public class LandingPageImpl extends EntityImpl implements LandingPage {

private String url;

public String getUrl() {
    return url;
}

public void setUrl(String url) {
    this.url = url;
} }

所以我希望我可以插入很多对象页面的对象(拥有自己的url property)在landingPageModels列表中。这意味着我可以拥有多个这样的url属性的输入标签 -

So i want that i can insert many objects of landingPage (having their own url property) in landingPageModels list. That means i can have mulitple input tag having url property like this -

<sf:input path="landingPageModels.landingPage.url" class="form-control" />
<sf:input path="landingPageModels.landingPage.url" class="form-control" />
<sf:input path="landingPageModels.landingPage.url" class="form-control" />

但是在执行此代码时,spring给出了一个错误,即landingPageModels的landingPage属性没有getter setter方法。如何解决它以及如何获取这样的多个值?

But when executing this code, spring gives me error that landingPage property of landingPageModels has not getter setter method. How to solve it and how to take multiple value like this ?

推荐答案

为了将列表模型属性绑定到多个输入字段,你需要以渲染的形式:

In order to bind a list model property to multiple input fields, you need this in the rendered form:

<input type="text" name="landingPageModels[0].landingPage.url" class="form-control" />
<input type="text" name="landingPageModels[1].landingPage.url" class="form-control" />
<input type="text" name="landingPageModels[2].landingPage.url" class="form-control" />

这是通过以下方式完成的:

Which is accomplished by:

<c:forEach items="${campaignModel.landingPageModels}" varStatus="s">
    <sf:input path="landingPageModels[${s.index}].landingPage.url" class="form-control" />
</c:forEach>

这篇关于如何将数据绑定到弹簧形式列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 21:20