0
votes

I am new to Portlet development and I am running into an annoying issue with Liferay.

I have played around a bit and created the following portlet (.jsp) page based on the "edit.jsp" from the "My-Greeting" tutorial:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>

<%@ page import="javax.portlet.PortletPreferences" %>

<portlet:defineObjects />

<%

PortletPreferences prefs = renderRequest.getPreferences();
String Temperature = (String)prefs.getValue("Temperature","Temperature");

PortletPreferences prefs2 = renderRequest.getPreferences();
String FromUnit = (String)prefs2.getValue("FromUnit", "FromUnit");

PortletPreferences prefs3 = renderRequest.getPreferences();
String ToUnit = (String)prefs3.getValue("ToUnit","ToUnit");



%>



<portlet:renderURL var="editGreetingURL">

    <portlet:param name="jspPage" value="/edit.jsp" />

</portlet:renderURL>

<aui:form action="http://www.webservicex.net/ConvertTemperature.asmx/ConvertTemp" method="post">

    <aui:input label="Temperature" name="Temperature" type="text" value="<%= Temperature %>" />
    <aui:input label="FromUnit" name="FromUnit" type="text" value="<%= FromUnit %>" />
    <aui:input label="ToUnit" name="ToUnit" type="text" value="<%= ToUnit %>" />
    <aui:button label="submit" type="submit" value="Submit" />

</aui:form>

<portlet:renderURL var="viewGreetingURL">

    <portlet:param name="jspPage" value="/view.jsp" />

</portlet:renderURL>

<p><a href="<%= viewGreetingURL %>">Back</a></p>

</body>
</html>

This portlet is supposed to take 3 input parameters: Temperature, FromUnit and ToUnit and then pass them on to a public WebService which converts Temperatures for example from Fahrenheit to Celcius (see http://www.webservicex.net/ConvertTemperature.asmx?WSDL) .

The portlet renders the input fields correctly and when I click the submit button it also tries to execute the Webservice but it doesn't actually pass on the parameters it seems because I get the following error response from the WebService itself:

System.InvalidOperationException: Missing parameter: Temperature. at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection) at System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest request) at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters() at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()

So even though my portlet has the input field Temperature it doesn't seem to actually pass it on and attach it to the action URL in the post ...

ne more thing, I replaced the "post" with a "get" and the URL string looks like this:

http://www.webservicex.net/ConvertTemperature.asmx/ConvertTemp?_mygreeting_WAR_mygreetingportlet_formDate=1377389917227&_mygreeting_WAR_mygreetingportlet_Temperature=30&_mygreeting_WAR_mygreetingportlet_FromUnit=degreeFahrenheit&_mygreeting_WAR_mygreetingportlet_ToUnit=degreeCelsius

What am I doing wrong here? Clearly it seems to be passing on the wrong parameters...

1

1 Answers

0
votes
  • Your portlet's jsps must not have a <html>, <head> and <body> section, that's the business of the portal. You only generate fragments of the whole page in your portlets
  • When you use <aui:form> and <aui:input>, AlloyUI is aware of it being run in a portal, thus it adds the portlet namespace to the parameter names - that's what you see in the GET URL you're quoting. (simply use <form> and <input> if you indeed want to post to an external site from your portal)
  • If you check http://www.webservicex.net/ConvertTemperature.asmx/ConvertTemp?&Temperature=30&FromUnit=degreeFahrenheit&ToUnit=degreeCelsius, you will see that this replies with a webservice-like results, e.g. <double>-1.1111111111110859</double>, so most likely you don't want to have this as the form's post target, but rather implement your portlet to reach out the the service and display the result embedded in your portlet's output. How to do this exceeds the scope of this answer though
  • just related: You can get all preferences just from your prefs object, no need for prefs2 and prefs3, and you're not using the editGreetingURL, right?