Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Liferay 7 recieve data in ...Portal.java from view.jsp
Greetings,
I have trouble sending my data from my view.jsp to my ...Portlet.java class with the liferay 6 way
what I am trying to do is the following
view.jsp:
<div class="bottom"> <input class="button" type="button" name="testData" value="Test Data" onclick="testData();"/> </div>
<script>
var testJsp = '<portlet:resourceURL id="testJsp" />';
var lastName = 'Dragicevic';
var firstName = 'Matej';
console.log(testJsp);
console.log(lastName);
console.log(firstName);
testData = function() {
jQuery.ajax({
url: testJsp,
cache: false,
data: {
lastName : lastName,
firstName : firstName
},
type: "POST",
dataType: "json",
complete: function() {
},
success: function(dataJson) {
alert("ajax success");
},
error: function(error) {
alert("ajax error");
}
});
}
</script>
TestPortlet.java:
@Override public void serveResource(final ResourceRequest resourceRequest, final ResourceResponse resourceResponse) throws IOException, PortletException { final String resourceId = resourceRequest.getResourceID(); if ("testJsp".equals(resourceId)) { testJsp(resourceRequest, resourceResponse); } super.serveResource(resourceRequest, resourceResponse); } private void testJsp(ResourceRequest resourceRequest, ResourceResponse resourceResponse) { String lastName = ParamUtil.getString(resourceRequest, "lastName", "xxx"); String firstName = ParamUtil.getString(resourceRequest, "firstName", "yyy"); LOG.warn("The nameString is this: " + lastName + " " + firstName ); }
This was working in liferay 6 and I would like to know what the way to do this in liferay 7 is.
I am getting an ajax error but I am still able to get into the testJsp() java method and log the xxx and yyy nameStrings. I guess the format of the data is somehow wrong.
Is there another way to do this or am I doing the top version somehow wrong?
BR
Matej
Matej Dragicevic:This was working in liferay 6 and I would like to know what the way to do this in liferay 7 is.
Looks like none of your parameters are namespaced. Some of the early changes in Liferay 6.2 were LPS-35309, which made Liferay not read un-namespaced parameters, and LPS-37706, which at least allowed it to be configurable at the portlet level.
So, since 7.x inherits that behavior, unless you specifically added
<requires-namespaced-parameters>false</requires-namespaced-parameters>
to your liferay-portlet.xml (if creating a legacy
portlet), or add
com.liferay.portlet.requires-namespaced-parameters=false
as a component property (if creating a portlet with OSGi), your
parameters won't get read.
Thank you.