【发布时间】:2014-09-15 17:15:08
【问题描述】:
我有 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() 方法。
我该怎么做?
【问题讨论】:
标签: java spring spring-mvc liferay liferay-6