Liferay7开发文档_3.4.5更新视图

更新UI,创建一个用于管理留言簿的新JSP,并更新现有的JSP。

  1. 首先,更新依赖关系。在guestbook-web模块,打开/src/main/resources/META-INF/resources/的init.jsp,添加以下依赖项:
    <%@ taglib uri="http://liferay.com/tld/frontend" prefix="liferay-frontend" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security" %>
    <%@ page import="java.util.List" %>
    <%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
    <%@ page import="com.liferay.portal.kernel.util.HtmlUtil" %>
    <%@ page import="com.liferay.portal.kernel.util.StringPool" %>
    <%@ page import="com.liferay.portal.kernel.model.PersistedModel" %>
    <%@ page import="com.liferay.portal.kernel.dao.search.SearchEntry" %>
    <%@ page import="com.liferay.portal.kernel.dao.search.ResultRow" %>
    <%@ page import="com.liferay.docs.guestbook.model.Guestbook" %>
    <%@ page import="com.liferay.docs.guestbook.service.EntryLocalServiceUtil" %>
    <%@ page import="com.liferay.docs.guestbook.service.GuestbookLocalServiceUtil" %>
    <%@ page import="com.liferay.docs.guestbook.model.Entry" %> 
    
  2. /resources/META-INF/resources/guestbookwebportlet打开view.jsp。将内容替换为以下代码:
    <%@include file="../init.jsp"%>
    
    <%
    long guestbookId = Long.valueOf((Long) renderRequest
            .getAttribute("guestbookId"));
    %>
    
    <aui:button-row cssClass="guestbook-buttons">
    
        <portlet:renderURL var="addEntryURL">
            <portlet:param name="mvcPath" value="/guestbookwebportlet/edit_entry.jsp" />
            <portlet:param name="guestbookId"
                value="<%=String.valueOf(guestbookId)%>" />
        </portlet:renderURL>
    
        <aui:button onClick="<%=addEntryURL.toString()%>" value="Add Entry"></aui:button>
    
    </aui:button-row>
    
    <liferay-ui:search-container total="<%=EntryLocalServiceUtil.getEntriesCount()%>">
    <liferay-ui:search-container-results
        results="<%=EntryLocalServiceUtil.getEntries(scopeGroupId.longValue(),
                        guestbookId, searchContainer.getStart(),
                        searchContainer.getEnd())%>" />
    
    <liferay-ui:search-container-row
        className="com.liferay.docs.guestbook.model.Entry" modelVar="entry">
    
        <liferay-ui:search-container-column-text property="message" />
    
        <liferay-ui:search-container-column-text property="name" />
    
    </liferay-ui:search-container-row>
    
    <liferay-ui:search-iterator />
    
    </liferay-ui:search-container>
    

This view.jsp now retrieves the entries from the guestbook it gets from the render method. It does this inside a Liferay Portal construct called a Search Container. This is a front-end component that makes it easy to display data in rows and columns. The EntryLocalServiceUtil call retrieves the data from your new Service Builder-based back-end. Otherwise, this JSP is much the same: you still have an Add Entry button with its corresponding URL.

接下来,编辑edit_entry.jsp

  1. Open edit_entry.jsp and replace the existing code with this:
    <%@include file="../init.jsp" %>
    
    <% 
    
    long entryId = ParamUtil.getLong(renderRequest, "entryId");
    
    Entry entry = null;
    if (entryId > 0) {
      entry = EntryLocalServiceUtil.getEntry(entryId);
    }
    
    long guestbookId = ParamUtil.getLong(renderRequest, "guestbookId");
    
    %>
    
    <portlet:renderURL var="viewURL">
    
    <portlet:param name="mvcPath" value="/guestbookwebportlet/view.jsp"></portlet:param>
    
    </portlet:renderURL>
    
    <portlet:actionURL name="addEntry" var="addEntryURL"></portlet:actionURL>
    
    <aui:form action="<%= addEntryURL %>" name="<portlet:namespace />fm">
    
    <aui:model-context bean="<%= entry %>" model="<%= Entry.class %>" />
    
        <aui:fieldset>
    
            <aui:input name="name" />
            <aui:input name="email" />
            <aui:input name="message" />
            <aui:input name="entryId" type="hidden" />
            <aui:input name="guestbookId" type="hidden" value='<%= entry == null ? guestbookId : entry.getGuestbookId() %>'/>
    
        </aui:fieldset>
    
        <aui:button-row>
    
            <aui:button type="submit"></aui:button>
            <aui:button type="cancel" onClick="<%= viewURL.toString() %>"></aui:button>
    
        </aui:button-row>
    </aui:form>
    

    虽然现在有更多的字段,但这是相同的形式。通过一些AlloyUI标签,表单链接到您的Entry实体。两个隐藏字段包含新留言簿entryIdguestbookId。submit按钮是一个ActionURL,它在控制器(您的portlet类)中执行addEntry方法。

现在已经成功地用真正的数据库驱动的后端替换了原型后端。接下来,部署您的应用程序。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>