Spring Portlet + Thymeleaf:ActionMapping的绑定对象

时间:2015-04-30 20:19:00

标签: spring spring-mvc portlet thymeleaf

我使用模板引擎Thymeleaf的Spring 4 Portlet存在问题。

我想将一个正常工作的servlet转换为一个portlet。 我使用Thymeleaf来编辑JSP文件中表单中的对象。

<form method="POST" th:object="${object}" th:action="${portletActionURL}"> <input th:field="*{objField}"/> ... <input type="submit"/> </form>

portletActionURL是生成的操作网址,目前为止有效。如您所愿,我想在我的控制器中使用object。我尝试了很多方法来实现这一点,例如:以下内容:

@ActionMapping("saveChanges")
public void bla(@ModelAttribute("object") AnyDatatype object, ModelMap model, ActionResponse response, ActionRequest request) throws Exception { ...}

不幸的是,在调用操作后,对象尚未填充其属性。我并不是真的在想这个,但我不知道如何使用Thymeleaf来实现这一点。

我知道使用<form:form>的选项,但是Thymeleaf无法用taglibs解析文件。我当然希望使用Thymeleaf,因为我的大多数JSP文件都使用它,并且可能需要花费很多精力来更改每个文件。

1 个答案:

答案 0 :(得分:1)

我找到了解决方案!

我在Liferay门户网站中使用了portlet。虽然Liferay在默认情况下需要命名空间参数,但我在liferay-portlet.xml中将其停用。

<?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_2_0.dtd">
<liferay-portlet-app>
<portlet>
<portlet-name>MyPortletName</portlet-name>
<requires-namespaced-parameters>false</requires-namespaced-parameters>
</portlet>
</liferay-portlet-app>

现在,它可以在不更改上述代码的情况下正常工作。

真诚的,你的, 儒略