![](/img/trans.png)
[英]how do I know the url caused the invocation of the @RenderMapping render() method of portlet spring mvc liferay?
[英]How to call another portlet @RenderMapping method in liferay + springmvc?
我有2个liferay + springmvc portlet应用程序(2个war文件)。
第一个portlet是Category portlet,它列出了所有可用的类别。 单击类别链接时,我将显示产品(默认页面)页面,其中包含Portlet-2中所选类别的产品列表。 我正在通过PortletSession传达所选类别。
在portlet-2中,用户可以将产品添加到购物车并导航到购物车页面(也在portlet-2中)。
现在,如果用户单击portlet-1上的另一个类别,那么我要显示产品(默认)页面。 但是当前正在发生的事情是,当在portlet-1上单击类别链接时,由于购物车页面现在在portlet-2上处于活动状态,因此重新渲染购物车页面,这是预期的。
@Controller
@RequestMapping("VIEW")
public class CatalogListingPortlet {
@Autowired
private CategoryRepository categoryRepository;
@RenderMapping
public String handleRenderRequest(RenderRequest request, RenderResponse response, Model model) {
model.addAttribute("categories", categoryRepository.findAll());
return "categories";
}
@ActionMapping(params = "action=showCategory")
public void showCategory(ActionRequest request, ActionResponse response) {
String categoryId = ParamUtil.get(request, "categoryId",StringPool.BLANK);
request.setAttribute("categoryId", categoryId);
PortletSession portletSession = request.getPortletSession();
portletSession.setAttribute("LIFERAY_SHARED_categoryId", categoryId, PortletSession.APPLICATION_SCOPE);
}
}
@Controller
@RequestMapping("VIEW")
public class ProductListingPortlet
{
@Autowired
private CategoryRepository categoryRepository;
@Autowired ProductRepository productRepository;
@RenderMapping
public String handleRenderRequest(RenderRequest request, RenderResponse response, Model model) {
PortletSession portletSession = request.getPortletSession();
String categoryId = (String) portletSession.getAttribute("LIFERAY_SHARED_categoryId", PortletSession.APPLICATION_SCOPE);
Category category = categoryRepository.findOne(Long.parseLong(categoryId));
List<Product> products = category.getProducts();
portletSession.setAttribute("PRODUCTS", products);
return "products";
}
@ActionMapping(params = "action=addProductToCart")
public void addProductToCart(ActionRequest request, ActionResponse response) {
//logic to add the selected product to cart
}
@RenderMapping(params = "action=checkout")
public String checkout(RenderRequest request, RenderResponse response, Model model) {
return "checkout";
}
}
当用户单击portlet-1中的类别链接时,我想在portlet-2中调用@RenderMapping方法。
要从CatalogListingPortlet.showCategory()方法进行具体说明,我需要触发ProductListingPortlet.handleRenderRequest()方法。
我该怎么做?
您可以通过IPC(内部Portlet通信)在Portlet之间发送数据:
在CatalogListingPortlet中:
@ActionMapping(params = "action=showCategory")
public void showCategory(ActionRequest request, ActionResponse response) {
QName qname = new QName("http://liferay.com/events","ipc.messsage","x");
response.setEvent(qname, "some message");
}
在ProductListingPortlet中:
@EventMapping(value ="{http://liferay.com/events}ipc.messsage")
public void receiveEvent(EventRequest request, EventResponse response) {
Event event = request.getEvent();
String messsage = (String)event.getValue();
//process the message
}
在portlet.xml中进行配置:
<portlet>
<portlet-name>catalogListingPortlet</portlet-name>
...
<supported-publishing-event>
<qname xmlns:x="http://liferay.com/events">x:ipc.messsage</qname>
</supported-publishing-event>
</portlet>
<portlet>
<portlet-name>productListingPortlet</portlet-name>
...
<supported-processing-event>
<qname xmlns:x="http://liferay.com/events">x:ipc.messsage</qname>
</supported-processing-event>
</portlet>
<event-definition>
<qname xmlns:x="http://liferay.com/events">x:ipc.messsage</qname>
<value-type>java.lang.String</value-type>
</event-definition>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.