问题
Here's the JSP from where my Javascript function is being called: JSP code
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="continueTour" onclick="showTutorial()">Take a Quick Tour</button>
<a href="javascript:disableTutorial();" id="skipTour" class="textanchor" style="padding-left:30px;">Skip Tour</a>
</div>
Here's the Javascript function from where I need to render another JSP, and hence need to get to the Render method in the controller. Notice the 'simulate' method that I'm calling to simulate the click of the hyperlink (!Not sure if this is right or not!): Javascript Code showTutorial() method:
function showTutorial(){
launchTutorial();
}
function launchTutorial(){
var enjoyhint_instance = new EnjoyHint({
onEnd: function(){
AUI().use('liferay-portlet-url', function(A) {
var plid = Liferay.ThemeDisplay.getPlid();
var url=Liferay.PortletURL.createRenderURL();
/*url.setPortletId(plid);*/
url.setPortletName(Liferay.ThemeDisplay.getp)
url.setParameter('render','redirectToEmpInfo');
alert(url);
A.one(document.createElement('a')).attr('href',url).simulate('click');
});
}
});
var enjoyhint_script_steps = [
{
"next #newAuthorizationActive": 'To create an authorization form'
}
];
enjoyhint_instance.set(enjoyhint_script_steps);
enjoyhint_instance.run();
}
Here's the controller method which I've written to catch the render request from the Javascript. Controller Method (Not getting to this method)
@RenderMapping(params = "render=redirectToEmpInfo")
protected ModelAndView redirectToEmpInfoForAuthTour(ModelMap map, RenderRequest renderRequest, RenderResponse response) {
LiferayPortal.logInfo(_log, "Inside the render method for Emp Info");
return null;
/*return new ModelAndView("emailsuccess", map);*/
}
回答1:
You add this code in head of jsp:
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme"%>
<liferay-theme:defineObjects/>
<portlet:defineObjects />
Also in you code:
var plid = Liferay.ThemeDisplay.getPlid();
var url=Liferay.PortletURL.createRenderURL();
/*url.setPortletId(plid);*/
url.setPortletName(Liferay.ThemeDisplay.getp)
url.setParameter('render','redirectToEmpInfo');
alert(url);
Replace, similar to this:
var plid = Liferay.ThemeDisplay.getPlid();
var url = Liferay.PortletURL.createRenderURL();
url.setPortletId('<%=themeDisplay.getPortletDisplay().getId() %>');
url.setParameter('render', 'redirectToEmpInfo');
alert(url);
来源:https://stackoverflow.com/questions/38133287/cant-get-to-liferays-spring-portlet-mvcs-controller-from-js-by-doing-the-fo