2012-03-23 118 views
2

我剛剛爲Liferay構建了一個Web服務portlet,以瞭解它是如何工作的。它工作正常,並通過http的GET方法也工作,雖然拋出異常,因爲數據庫是空的,但沒關係。從liferay portlet發送POST方法

所以我現在想要的是通過編輯我的view.jsp來完全從同一個portlet的數據庫。

我的問題是,我該如何或應該在jsp中將我的代碼發送POST請求以在數據庫中添加一行?我想用aui來顯示一個字段和一個按鈕,這樣你就可以編寫你想要插入的內容,點擊提交,然後發送POST請求。

<%@ page import="javax.portlet.PortletPreferences" %> 
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> 
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %> 

<portlet:defineObjects /> 

<% 
PortletPreferences prefs = renderRequest.getPreferences(); 
String name = (String)prefs.getValue("name", "Employee name"); 
%> 

Please insert you new <b>Employee</b> name. 

<form method="post"> 
<aui:form method="post"> 
<aui:input label="New Employee: " name="name" type="text" value="<%=name%>"/> 
<aui:button type="submit" /> 
</aui:form> 
</form> 

此代碼正確顯示按鈕和字段。我只是想知道我必須把代碼以及如何發送的DB這個請求並存儲的東西:

serviceClassName:xxx.service.XServiceUtil 

serviceMethodName:methodName 

servletContextName:X-portlet 

serviceParameters:["param1","paramN"] 

param1:n 

paramN:m 

Web服務是建立和工作。

非常感謝你,

貝尼特斯

回答

1

我覺得你的代碼幾乎是正確的,只是去掉了外部形態和保持AUI:形式。這應該適合你

<aui:form method="post"> 
<aui:input label="New Employee: " name="name" type="text" value="<%=name%>"/> 
<aui:button type="submit" /> 
</aui:form> 

name參數應該使用post發送。我注意到的另一件事是在你的表單中你沒有給出動作url。所以,你應該寫類似以下

<portlet:actionURL var="configurationURL" /> 

<aui:form method="post" action="<%=configurationURL%>"> 

那麼您的portlet應該有processAction方法,這將使用localServiceUtil類調用相應的業務邏輯。

更多關於完整的portlet創建參考以下鏈接

http://www.liferay.com/documentation/liferay-portal/6.0/development/-/ai/portlet-development

+0

您好,感謝了很多,但你留在路上的東西,不寫:)我明白了一點點什麼,我必須這樣做,但我仍然有一些問題:在我的processAction中,我必須編寫包含必須發送到服務的url的字符串,不是嗎?我想我也可以在<% %>之間的jsp中做到這一點。 – agapitocandemor 2012-03-23 13:22:09

+0

哎呀對不起,我有Firefox 3.5.6,它不會告訴我所見即所得編輯器 – 2012-03-23 13:44:24

+0

我已經修改我的答案與IE – 2012-03-23 13:51:24