我试图在我的救生筏应用程序中使用SearchContainer。目前,我不得不使用JSP在<liferay-ui:search-container-results>标记中设置结果。这是目前为止的片段:
<liferay-ui:search-container emptyResultsMessage="there-are-no-courses" delta="5">
<liferay-ui:search-container-results>
<%
List<Course> tempResults = ActionUtil.getCourses(renderRequest);
results = ListUtil.subList(tempResults,
searchContainer.getStart(),
searchContainer.getEnd());
total = tempResults.size();
pageContext.setAttribute("results", results);
pageContext.setAttribute("total", total);
%>
</liferay-ui:search-container-results>
<liferay-ui:search-container-row ...></liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container>现在,我想把那些抄写员换成EL。对于同样的问题,我找到一个职位,但这是使用Spring MVC。我不知道在哪里写下面的一行,正如在这个问题的答案中所给出的,用portlet:
SearchContainer<Book> searchContainer = new SearchContainer<Book>(renderRequest, renderResponse.createRenderURL(), null, "there are no books");在无法将其写入portlet操作中,因为我的操作中的参数是ActionRequest和ActionResponse,后者不定义方法createRenderURL()。我怎么才能拿到PortletURL
我应该在哪里写上面的陈述?目前,我从返回到这个页面的地方写同样的动作。我做得对吗?下面是我从同一个页面启动的操作,正如search-container所包含的那样:
public void addCourse(ActionRequest request, ActionResponse response)
throws Exception {
ThemeDisplay themeDisplay =
(ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
Course course = ActionUtil.courseFromRequest(request);
List<String> errors = new ArrayList<String>();
if (CourseRegValidator.validateCourse(course, errors)) {
CourseLocalServiceUtil.addCourse(course, themeDisplay.getUserId());
SessionMessages.add(request, "course-added-successfully");
// I thought I might put it here.
// But I don't know what to pass as `PortletURL` in constructor of SearchContainer
} else {
SessionErrors.add(request, "fields-required");
}
}我希望这样,每次添加一个Course时,它都会在我的搜索容器中呈现,就在我触发addCourse操作的同一页面上。
是的,我的portlet扩展了MVCPortlet。
更新
好吧,我想出了几个部分。
doView方法,然后在SearchContainer中添加renderRequest,就像在doView中访问它一样。editCourse()操作时,我正在执行一个response.setRenderParameter(),将其发送到另一个jsp页面。在那个JSP页面中,我启动了一个updateCourse()操作。updateCourse()操作中,我再次使用response.setRenderParameter()将其发送到原始的JSP页面,在那里我使用Search。但是现在,由于它没有经过doView()方法,所以我无法创建SearchContainer并将其添加到请求中。所以,这附近有什么工作吗?如何确保在renderRequest中doView方法中设置的属性在updateCourse方法中可用?我知道这听起来不太实际,因为这完全是一个新的要求,但是还有其他的方法吗?
我可以想到的一个解决办法是在更大的范围内设置属性,比如session或context,而不是renderRequest。但是,我在其他地方不需要那个属性。所以,我不认为那是合适的。
有投入吗?
更新2
刚才,我用:
actionResponse.setPortletMode(PortletMode.VIEW);代替:
actionResponse.setRenderParameter("jspPage", jspPage);它起了作用,因为它现在通过doView()方法。我只想问一问,这样做合适吗?当我们将呈现参数设置为相同的JSP页面( doView方法重定向的位置)时,这两种方法有什么区别呢?
我当前的doView方法如下所示:
@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
throws IOException, PortletException {
SearchContainer<Course> searchContainer =
new SearchContainer<Course>(renderRequest, renderResponse.createRenderURL(), null, "there-are-no-courses");
searchContainer.setDelta(5);
List<Course> tempResults = ActionUtil.getCourses(renderRequest);
List<Course> results = ListUtil.subList(tempResults,
searchContainer.getStart(),
searchContainer.getEnd());
searchContainer.setTotal(tempResults.size());
searchContainer.setResults(results);
renderRequest.setAttribute("searchContainer", searchContainer);
super.doView(renderRequest, renderResponse);
}发布于 2013-07-30 10:33:33
将评论转换为应答:
searchContainer设置在doView方法本身中,就像您在问题中链接的回答中所解释的那样。https://stackoverflow.com/questions/17923082
复制相似问题