資料來源參考:
http://liferayzone.wordpress.com/2013/11/29/kaleo-workflow-configuration-for-custom-portlet-in-liferay-6-1/
先照上面資料來源做法 照做一次,下面有關於view & controller的部分。
FeedbackController . java
=====================================
public class FeedbackController extends MVCPortlet {
public void addFeedback(ActionRequest actionRequest,
ActionResponse actionResponse) throws SystemException, IOException,
PortalException, ParseException {
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest
.getAttribute(WebKeys.THEME_DISPLAY);
ServiceContext serviceContext = ServiceContextFactory.getInstance(
Feedback.class.getName(), actionRequest);
String feedbackText = actionRequest.getParameter("feedbackText");
long pkId = CounterLocalServiceUtil.increment(Feedback.class.getName());
Long groupId = themeDisplay.getScopeGroupId();
Long userId = themeDisplay.getUserId();
Feedback newFeedback = FeedbackLocalServiceUtil.createFeedback(pkId);
newFeedback.setFeedbackText(feedbackText);
newFeedback.setFeedbackDate(new Date());
newFeedback.setCompanyId(themeDisplay.getCompanyId());
newFeedback.setGroupId(themeDisplay.getScopeGroupId());
FeedbackLocalServiceUtil.addFeedback(newFeedback, userId,
serviceContext);
PortletURL portletURL = PortletURLFactoryUtil.create(actionRequest,
(String) actionRequest.getAttribute(WebKeys.PORTLET_ID),
themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);
portletURL.setParameter("mvcPath", "/html/mylist.jsp");
actionResponse.sendRedirect(portletURL.toString());
}
}
mylist.jsp
==============================================
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@include file="/html/init.jsp"%>
<%
// 返回前頁
String currentURL = PortalUtil.getCurrentURL(request);
String redirect = ParamUtil.getString(request, "redirect",
currentURL);
%>
<liferay-portlet:renderURL var="addURL">
<liferay-portlet:param name="mvcPath" value="/html/add.jsp" />
<portlet:param name="redirect" value="<%=redirect.toString()%>" />
</liferay-portlet:renderURL>
<aui:button type="button" value="add" onClick="<%=addURL.toString()%>" />
<liferay-ui:search-container emptyResultsMessage="no data">
<liferay-ui:search-container-results>
<%
List<Feedback> tempList = FeedbackLocalServiceUtil
.getFeedbacks(-1, -1);
List<Feedback> myList = new LinkedList<Feedback>();
if (tempList != null && tempList.size() > 0) {
for(Feedback f : tempList){
if(f.getStatus()== WorkflowConstants.STATUS_APPROVED)
myList.add(f);
}
}
results = ListUtil.subList(myList,
searchContainer.getStart(),
searchContainer.getEnd());
total = myList.size();
pageContext.setAttribute("results", results);
pageContext.setAttribute("total", total);
%>
</liferay-ui:search-container-results>
<liferay-ui:search-container-row
className="com.fansysoft.danny.model.Feedback" keyProperty="userId"
modelVar="feedback" escapedModel="<%=true%>">
<liferay-ui:search-container-column-text property="feedbackId"
name="id" />
<liferay-ui:search-container-column-text property="feedbackText"
name="名字" />
<liferay-ui:search-container-column-text name="日期">
<%
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy/MM/dd");
%>
<%=sdf.format(feedback.getFeedbackDate())%>
</liferay-ui:search-container-column-text>
<liferay-portlet:renderURL var="editURL">
<liferay-portlet:param name="pkId_edit"
value="<%=String.valueOf(feedback.getFeedbackId())%>" />
<liferay-portlet:param name="mvcPath" value="/html/edit.jsp" />
<portlet:param name="redirect" value="<%=redirect.toString()%>" />
</liferay-portlet:renderURL>
<liferay-portlet:actionURL name="deleteData" var="deleteURL">
<liferay-portlet:param name="pkId"
value="<%=String.valueOf(feedback.getFeedbackId())%>" />
</liferay-portlet:actionURL>
<liferay-ui:search-container-column-text name="編輯">
<aui:button type="button" value="edit" onClick="<%=editURL%>" />
</liferay-ui:search-container-column-text>
<liferay-ui:search-container-column-text name="" value="刪除"
href="<%=deleteURL.toString()%>" />
<%--
<liferay-ui:search-container-column-jsp name="設定"
path="/html/action.jsp" />
--%>
</liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container>
add.jsp
==============================================
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@include file="/html/init.jsp" %>
<%
String currentURL = PortalUtil.getCurrentURL(request);
String redirect = ParamUtil.getString(request, "redirect", currentURL);
%>
<liferay-portlet:actionURL name="addFeedback" var="addURL" >
<portlet:param name="<%=Constants.CMD %>" value="<%=Constants.ADD %>"/>
</liferay-portlet:actionURL>
<liferay-ui:header
backURL="<%= redirect %>"
title="新增"
/>
<aui:form method="post" action="<%=addURL.toString()%>">
<aui:input type="textarea" name="feedbackText" label="測試輸入欄位" value="danny" />
<%-- <aui:input name="userAge" label="日期" value="2014-3-5 14:47:13" /> --%>
<aui:button type="submit" />
</aui:form>
沒有留言:
張貼留言