2

我需要在以这种方式定义的两个选项卡中共享同一个 bean:

<fmt:message var="tabNames" key="message.tab.alta" />


<c:set var="tabValues" value="valtab01,valtab02" />


<portlet:renderURL var="URL01" >
        <portlet:param name="action" value="${ServletContextKeys.SC_INSERT}" />
    <portlet:param name="${ServletContextKeys.SC_TAB_INSERT}" value="valtab01" />
</portlet:renderURL>

<portlet:renderURL var="URL02" >
     <portlet:param name="action" value="${ServletContextKeys.SC_ADD_LIST}" />
     <portlet:param name="${ServletContextKeys.SC_TAB_INSERT}" value="valtab02" />
</portlet:renderURL>

<liferay-ui:tabs 
     names="${tabNames}"
     tabsValues="${tabEscrituraValues}"
     param="${ServletContextKeys.SC_TAB_INSERT}"
     url0="${URL01}"
     url1="${URL02}"
     value="${insert_tabs}"
  />

所以我只需要在代表 2 个选项卡的 2 个 jsp 中定义一个 bean:

    <form:form id="formInsert" action="action01" method="post" modelAttribute="myBean" enctype="multipart/form-data">

但我不知道如何让 2 个 jsp 共享同一个 bean。我需要在一个选项卡中填充 bean 的一些数据,并在另一个选项卡上填充一个列表(在同一个 bean 中)。填写完所有数据后,从第一个选项卡提交,我需要控制器中的整个 bean(第一个选项卡中的数据和第二个选项卡中的列表)我对 portlet、spring 和所有这些东西,所以任何帮助都会很棒!

这可能吗..?

4

1 回答 1

1

If you want to remember in some way the properties of modelAttribute which are not on current tab, you may do this in several ways:

  • Persist the modelAttribute in session using the @SessionAttributes annotation. This is probably the easiest way and it quite literally does what you wanted – makes the JSPs "share" the same bean – but I highly disencourage doing this as a REST advocate, as session is quite an overkill here (not that it's even possible to build RESTful applications with portlets currently).
  • Hold the values from the first tab in second tab's form in hidden inputs.
  • Hold the values from the first tab in cookies and meld them with second tab's modelAttribute upon submission request

The latter two are quite similar I think but for general purposes the hidden inputs would probably be easier to implement (they may require little to no controller code, e.g. for proper validation).

于 2012-12-21T09:38:34.567 回答