Liferay Portlet基本MVC流程和视图选择 [英] Liferay Portlet Basic MVC Flow and View Selection

查看:142
本文介绍了Liferay Portlet基本MVC流程和视图选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用LifeRay 6.1开发一个基本的portlet。我非常精通各种MVC实现,但我发现Liferay / java portlet有点令人困惑 - 尤其是执行管道。

I'm trying to develop a basic portlet with LifeRay 6.1. I'm well versed with various MVC implementations, but I find Liferay / java portlets somewhat confusing - especially the execution pipeline.

对于大多数MVC框架我都使用过前提是简单的请求>路由器>控制器>视图。视图选择通常基于控制器/动作命名约定,与请求一起传入的参数或在控制器动作中手动加载。

With most MVC frameworks I've worked with the premise is simple request > router > controller > view. The view selection is usually based the controller / action naming convention, a parameter passed in with the request or is manually loaded in the controller action.

使用LifeRay MVCPortlet它不会像这样工作;可以生成至少两种类型的URL - 呈现URL和动作URL。

With LifeRay MVCPortlet it doesn't work like this; there's at least two types of URL that can be generated - a render url and an action url.

渲染URL似乎完全绕过了我认为是控制器的东西 - MVCPortlet的子类。似乎这些url相对容易生成并且请求加载了预期视图,如果你可以调用它,考虑到所有意图和目的它完全绕过控制器并且与模型无关。

The render URL seems to totally bypass what I perceive to be the controller - a subclass of MVCPortlet. It seems as though these urls are relatively easy to generate and the request loads the expected view, if you can call it that considering for all intents and purposes it completely bypasses the controller and has nothing to do with a model.

<portlet:renderURL var="badminURL"><portlet:param name="mvcPath" value="/views/edit.jsp" /></portlet:renderURL>

操作URL通过控制器,调用操作然后使用默认视图进行渲染无论我提供什么作为mvc路径,都可以使用portlet。

The action URL goes through the controller, the action is called and then the default view is used to render the portlet regardless of what I supply as an mvc path.

<portlet:actionURL var="adminURL" name="editSlide"><portlet:param name="mvcPath" value="/views/edit.jsp" /></portlet:actionURL>

通过类树读取我可以看到一个属性用于定义使用的视图取决于portlet模式。即。

Reading up through the class tree I can see that a property is used to define the view that gets used depending on the portlet mode. i.e.

this.viewTemplate = "/views/edit.jsp";
this.editTemplate = "/views/edit.jsp";

再次在调用init()之后设置此项似乎只有在没有通过actionURL访问时才有效。

Again setting this after init() is called only seems to have any effect when not accessed via an actionURL.

所以我想我的问题非常基本,如何选择视图以及如何选择通过actionURL时使用的视图。此外,执行管道上的任何大纲都会非常有用

So I guess my question is pretty basic, how are views selected and how to I select one to use when going via an actionURL. Also any outline on execution pipeline would be very helpful

推荐答案

我找到了解决方案。您可以在传递给控制器​​操作的ActionResponse对象上分配render参数。这告诉liferay加载提供的视图。 ie

I found the solution. You can allocate a render parameter on the ActionResponse object that is passed to the controller action. This tells liferay to load the supplied view. i.e.

public void editSlide(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException {

    // action code goes here

    // set up the view
    actionResponse.setRenderParameter("mvcPath", "/views/edit.jsp");        

}

这篇关于Liferay Portlet基本MVC流程和视图选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆