如何使用自定义权限修改liferay的Book Portlet?

时间:2012-09-24 13:20:25

标签: liferay portlet liferay-6

我正在使用liferay 6 CE并成功整合了book-portlet及其工作正常。

现在,我想修改此book-portlet,以便在没有用户权限时隐藏submitreset按钮。

我已使用以下代码更改了view.jspdisplay_action.jsp

我的display_action.jsp

<%@ include file="/init.jsp"%>

<%
ResultRow row = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
Books book = (Books)row.getObject();
long groupId = themeDisplay.getLayout().getGroupId();
String name = Books.class.getName();
String bookId = String.valueOf(book.getPrimaryKey());
%>

<c:if
    test="<%= permissionChecker.hasPermission(groupId, name,bookId,\"DELETE\") %>">
    <portlet:actionURL name="deleteBooks" var="deleteURL">
        <portlet:param name="bookId" value="<%=bookId%>" />
    </portlet:actionURL>
    <liferay-ui:icon image="delete" url="<%=deleteURL.toString() %>" />
</c:if>
<c:if
    test="<%= permissionChecker.hasPermission(groupId, name,bookId,\"ADD_BOOKS\") %>">
    <portlet:actionURL name="addBook" var="addBookURL">
        <portlet:param name="bookId" value="<%=bookId%>" />
    </portlet:actionURL>
    <aui:fieldset>
        <aui:button-row>
        <p>
            <aui:button class="aui-button-input" type="submit" value="Submit" />
            <aui:button class="aui-button-input" type="reset" value="Reset" />
        </p>
        </aui:button-row>
    </aui:fieldset>
</c:if>

我的view.jsp文件如下:

<%@ include file="/init.jsp"%>
<%
Books book = (Books) request.getAttribute("book");
if (book == null) {
    book = new BooksImpl();
    Calendar now = CalendarFactoryUtil.getCalendar();
    now.set(1970, 1, 1);
    book.setDateOfPurchase(now.getTime());
}
%>

<liferay-portlet:actionURL name="addBook" var="addBookURL"></liferay-portlet:actionURL>
<liferay-ui:success key="book-added" message="book-added" />
<liferay-ui:success key="book-deleted" message="book-deleted" />
<liferay-ui:error key="error-deleting" message="error-deleting" />
<liferay-ui:error key="error-while-adding" message="error-while-adding" />

<aui:form action="<%=addBookURL.toString() %>" method="post" name="fm">    
    <aui:fieldset>
        <liferay-ui:error key="title-required" message="title-required" />
        <p>
            <aui:input name="title" label="Title" type="text"
                value="<%=book.getTitle() %>"></aui:input>
        </p>
        <liferay-ui:error key="author-required" message="author-required" />
        <p>
            <aui:input name="author" label="Author" type="text"
                value="<%=book.getAuthor() %>"></aui:input>
        </p>
        <liferay-ui:error key="pages-required" message="pages-required" />
        <liferay-ui:error key="pages-cannot-be-zero"
            message="pages-cannot-be-zero" />
        <p>
            <aui:input name="pages" label="Pages" type="text"
                value="<%=String.valueOf(book.getPages()) %>"></aui:input>
        </p>
        <liferay-ui:error key="dop-required" message="dop-required" />
        <p>
            <%
            Calendar dop = CalendarFactoryUtil.getCalendar();
            dop.setTime(book.getDateOfPurchase());
            %>
            <aui:input model="<%=Books.class %>" bean="<%=book%>"
                label="Date of Purchase" name="dateOfPurchase" value="<%= dop %>" />

        </p>
            </aui:fieldset>
</aui:form>

<liferay-ui:search-container emptyResultsMessage="no-books" delta="5">
    <liferay-ui:search-container-results>
        <%
        List<Books> tempResults = (List<Books>) BooksActionUtil
                        .getAllBooks(themeDisplay.getCompanyId());

        results = ListUtil.subList(tempResults,
                searchContainer.getStart(),
                searchContainer.getEnd());
        total = tempResults.size();

        pageContext.setAttribute("results", results);
        pageContext.setAttribute("total", total);
        %>
    </liferay-ui:search-container-results>

    <liferay-ui:search-container-row
        className="com.books.database.model.Books" keyProperty="bookId"
        modelVar="book1">

        <liferay-ui:search-container-column-text name="Title" property="title" />
        <liferay-ui:search-container-column-text name="Author"
            property="author" />
        <liferay-ui:search-container-column-text name="Pages" property="pages" />
        <liferay-ui:search-container-column-text name="Date of Purchase"
            property="dateOfPurchase" />
        <%
        long groupId = themeDisplay.getLayout().getGroupId();
        String name = Books.class.getName();
        String bookId = String.valueOf(book.getPrimaryKey());
        %>
        <c:if
            test="<%= permissionChecker.hasPermission(groupId, name,bookId,\"DELETE\") %>">
            <liferay-ui:search-container-column-jsp name="Delete"
                path="/jsps/display_actions.jsp" align="right" />
        </c:if>
        <c:if
            test="<%= permissionChecker.hasPermission(groupId, name,bookId,\"ADD_BOOKS\") %>">
            <liferay-ui:search-container-column-jsp name="addBook"
                path="/jsps/display_actions.jsp" align="right" />
        </c:if>

    </liferay-ui:search-container-row>

    <liferay-ui:search-iterator />

</liferay-ui:search-container>

我遇到的问题是当用户有ADD_BOOKS权限时,它会在每一行显示submitreset按钮。

我只是通过谷歌搜索以某种方式成为新手,我已成功隐藏并按用户角色显示按钮,但现在我正面临这个小问题。

任何人都可以指导我如何将这些按钮限制为仅一次。

0 个答案:

没有答案