Reputation: 1116
I am building a MVCPortlet Liferay 6.2 portlet. I have a form with 2 buttons. First button validates the form (submit). The second one redirects to a jsp. I have a difficulty to make it work:
<portlet:actionURL name="mainSubmit" var="mainSubmitURL"></portlet:actionURL>
<portlet:renderURL var="viewLogsURL">
<portlet:param name="mvcPath" value="/jsp/logs.jsp"/>
</portlet:renderURL>
<form ... action="<%=mainSubmitURL%>">
...
<div class="controls-row ">
<label class="span1" ></label>
<input class="span2 btn " type="submit" value="Submit Form" >
<label class="span4" ></label>
<input class="span2 btn " onClick="<%=viewLogsURL.toString()%>" value="View Logs" />
</div>
</form>
First button works fine but second button does not redirect to viewLogsURL.
If I replace:
<input class="span2 btn " onClick="<%=viewLogsURL.toString()%>" value="View Logs" />
with:
<buttonclass="span2 btn " onClick="<%=viewLogsURL.toString()%>" value="View Logs" />
then the button also makes a submits the form url (mainSubmitURL) instead of the button URL (viewLogsURL).
And if I use:
<aui:button class="span2 btn " onClick="<%=viewLogsURL.toString()%>" value="View Logs" />
This actually performs the correct redirection but I would like to avoid using it as it generates some css style issues and some filtering-proxy issues that I don't have with or . So I would rather use or if possible (and I m pretty sure it is).
I also tried to change :
<portlet:renderURL var="viewLogsURL">
<portlet:param name="mvcPath" value="/jsp/logs.jsp"/>
</portlet:renderURL>
with:
<portlet:renderURL var="viewLogsURL">
<portlet:param name="jspPage" value="/jsp/logs.jsp"/>
</portlet:renderURL>
No chance...
Thx in advance.
Upvotes: 0
Views: 1425
Reputation: 2862
HTML onclick
attribute is used to execute JavaScript code, when the element is clicked. The value must be valid JavaScript code, not a URL. You've probably mistaken it with <a href='url'>...</a>
attribute.
That's a basic HTML concept - see for example w3schools description for more details.
To make the redirect work, you can set the redirect URL as the current location:
<input class="span2 btn" onClick="location.href = '<%= viewLogsURL.toString() %>'" value="View Logs"/>
Or call a JavaScript function instead:
<input class="span2 btn" onClick="<portlet:namespace/>doRedirect()" value="View Logs"/>
<script>
function <portlet:namespace/>doRedirect() {
location.href = '<%= viewLogsURL.toString() %>';
}
</script>
Upvotes: 2