2012-06-27 76 views
1

我正在開發一個liferay portlet。這是我在JSP文件中的代碼:Implement在liferay portlet中編輯

<table class="DDGridView"> 
<tr class="td"> 
    <td class="th">Complex Name</td> 
    <td class="th">City</td> 
    <td class="th">Status</td> 
</tr> 
<% 
    Complex complex; 
    for(int i = 0 ; i < complexList.size(); i++) 
    { 
     complex = (Complex)complexList.get(i); 
%> 
     <tr class="td"> 
      <td><%=complex.complexName %></td> 
      <td><%=complex.complexCity %></td> 
      <% 
       if(complex.isActive == 1) 
       { 
      %>    
        <td class="th">Active</td> 
      <% 
       } 
       else 
       { 
      %> 
        <td>Not Active</td> 
      <% 
       } 
      %> 
      <td><a href="<%=prepareEditComplexURL%>">Edit</a></td> 
      <td><a>Delete</a></td> 
     </tr> 
<% 
    } 
%> 
</table> 

當用戶點擊編輯URL,我要選擇的行項發送到portlet類。但我不知道該怎麼做。我怎樣才能做到這一點?

+0

你能詳細說說你是什麼意思的「選定的行項目」。你如何準備'prepareEditComplexURL'或者你想幫助準備這個URL本身? –

+0

通過單擊編輯執行轉到Portlet類中的方法。在該方法中,我需要知道complexName,complexCity和Edit按鈕被單擊的行的狀態。 – Karadous

回答

4

通過您的評論,您似乎需要幫助來構建網址。

所以,你可以構造內的URL for循環,如:

如果你想利用這些信息做一些數據庫操作像updateinsert

<portlet:actionURL var="preparedEditComplexURL"> 
    <portlet:param name="complexName" value="<%=complex.complexName %>" /> 
    <portlet:param name="complexCity " value="<%=complex.complexCity %>" /> 
    <portlet:param name="status " value="<%=complex.isActive %>" /> 
</portlet:actionURL> 

或者,如果你想渲染(或顯示)一些頁面取決於這些字段,然後使用渲染URL,如下所示:

<portlet:renderURL var="preparedEditComplexURL"> 
    <portlet:param name="complexName" value="<%=complex.complexName %>" /> 
    <portlet:param name="complexCity " value="<%=complex.complexCity %>" /> 
    <portlet:param name="status " value="<%=complex.isActive %>" /> 
</portlet:renderURL> 

另外它會hel p如果你可以參考一些有關portletURL的概念以及如何使用它們。有好的教程可用,並且Portlets in Action是關於幾乎所有portlet開發概念的好書。

希望這會有所幫助。

1

Prakash K回答非常好!只需添加一件可能有用的東西。 當您創建一個portlet操作URL,你可以指定地址的名稱屬性,這樣

<portlet:actionURL name="preparedEditComplex" var="preparedEditComplexURL"> 
    <portlet:param name="complexName" value="<%=complex.complexName %>" /> 
    <portlet:param name="complexCity " value="<%=complex.complexCity %>" /> 
    <portlet:param name="status " value="<%=complex.isActive %>" /> 
</portlet:actionURL> 

所以,在你的portlet類,你可以打電話給你的方法是這樣的:

的Liferay 6.x的

public preparedEditComplex(ActionRequest actionRequest, ActionResponse actionResponse) { 
    //Your implementation 
    ... 
} 

的Liferay 5.2

@ProcessAction(name="preparedEditComplex") 
public preparedEditComplex(ActionRequest actionRequest, ActionResponse actionResponse) { 
    //Your implementation 
    ... 
} 

這樣你就可以寫一個更清潔d更多可讀代碼。 :)

乾杯