Log In | Sign Up   View a printable version of the current page.
  Dashboard > flexive > ... > The security enabled announcement submission application > Listing announcements

Added by Hans Bacher, last edited by Gerhard Glos on Nov 13, 2008  (view change)
Labels: 
(None)

Listing announcements

This page displays a list of stored announcements which the current user may read and provides "Edit" and "Delete" Buttons for editors to modify announcements. The announcement list is in fact the display of a search result, retrieved from our managed Bean named ASubmissionBean:

JSF managed ASubmissionBean: getAnnouncementEntries() method
public DataModel getAnnouncementEntries() throws FxApplicationException { (1)
    if (announcementEntries == null) {
        final FxResultSet result = new SqlQueryBuilder() (2)
                .select("@permissions",                  (3) 
                        "announcementEntry/caption",
                        "announcementEntry/announcementText",
                        "announcementEntry/publishDate",
                        "announcementEntry/publishURL",
                        "@pk")
                .type("announcementEntry") (4)
                .orderBy("announcementEntry/publishDate", SortDirection.DESCENDING) (5)
                .getResult() (6);
        announcementEntries = new FxResultSetDataModel(result); (7)
    }
    return announcementEntries;
}

(1) A method is defined returning a DataModel object which wraps the retrieved search result.
(2) With the help of the SqlQueryBuilder (2) we define a search query as follows:
(3) We select all properties of interest in this order: @permissions, caption, announcementText, publishDate, publishURL and @pk (3). @permissions and @pk are virtual properties representing the permissions and the primary key of a specific content instance. For more information on selectable properties please refer to the reference documentation SqlQueryBuilder chapter.
(4,5) Additionally we specify the type to be queried, which is in our case "announcementEntry" (4) and we specify that we want the result set ordered by the property publishDate (5).
(6) The query is submitted and an we retrieve an FxResultSet containing all found contents of the specified type with the selected properties as result.
(7) Finally the result is converted into a DataModel object and returned.

The returned DataModel object is then ready to be rendered:

Announcement Listing on index.xhtml
...
<h:form>
<ui:repeat value="#{asubmissionBean.announcementEntries}" var="annEntry"> <!-- (1) -->
 <div class="announcementEntry">
    <table class="announcementEntry" width="100%" border="0" cellpadding="2" cellspacing="1">
        <caption><fx:resultValue value="#{annEntry[1]}"/></caption>
        <tr>
            <td class="key01">Text</td>
            <td class="value01"><fx:resultValue value="#{annEntry[2]}"/></td> <!-- (2) -->
        </tr>
        <tr>
            <td class="key02">Publish Date</td>
            <td class="value02"><fx:resultValue value="#{annEntry[3]}"/></td> <!-- (2) -->
        </tr>
        <tr>
            <td class="key01">Publish URL</td>
            <td class="value01"><fx:resultValue value="#{annEntry[4]}"/></td> <!-- (2) -->
        </tr>
        <tr>
            <td class="key02">Instance Permissions</td>
            <td class="value02"><fx:resultValue value="#{annEntry[0]}"/></td> <!-- (2) -->
        </tr>
    </table>
    <h:commandButton action="#{asubmissionBean.navEditContent}" rendered="#{annEntry[0].mayEdit}" value="Edit"> <!-- (3) -->
        <f:setPropertyActionListener target="#{asubmissionBean.instancePk}" value="#{annEntry[5]}"/> <!-- (5) -->
    </h:commandButton>
    <h:outputText value=" "/>
    <h:commandButton action="#{asubmissionBean.delete}" rendered="#{annEntry[0].mayDelete}" value="Delete"> <!-- (4) -->
        <f:setPropertyActionListener target="#{asubmissionBean.instancePk}" value="#{annEntry[5]}"/> <!-- (5) -->
    </h:commandButton>
 </div>
</ui:repeat>
</h:form>
....

Search Result iteration

(1) To iterate over search result entries and its properties (i.e the announcement properties we have selected in our search query) we iterate over the returned DataModel object using facelets <ui:repeat/> tag. During each iteration step the variable annEntry is updated with the next search result entry and can be used to access the selected properties.

(2) To retrieve the property values again, we just need to specify the index of the property we are interested in. I.e. #{annEntry[0]} would return the value of the first property. In our case we selected permissions to be the first property. #{annEntry[1]} would return the second, which returns the announcement title, and so on.
In order to render the property values the [fleXive] <fx:resultValue/> tag is used for more sophisticated output formatting.

Accessing content security settings in the user interface

Sometimes it is necessary to query security settings for the selective display of components in the user interface. In [fleXive], permissions for a content object can be selected in database queries by adding the property @permissions to a query. This property can then be used to control the appearance of user interface elements. The rendered attribute of JSF-Components is ideal to selectively hide or show user interface elements:

(3) An Edit button is rendered which is bound to the navigation method navEditContent() in the ASubmissionBean, redirecting the user to the instance editing form. In the rendered attribute of the button a permission check is performed that determines whether the current user may edit this announcement. If that is not the case, the button is not rendered.

(4) A Delete button is rendered which is bound the delete() method of ASubmissionBean. In the rendered attribute of the button a permission check is performed that determines whether the current user may delete this announcement. If that is not the case, the button is not rendered.

(5) Both command buttons have a PropertyActionListener defined, which sets the instancePk property in the ASubmissionBean to the primary key of the selected announcement. The set instancePk property is used to identify the instance to be edited or deleted.

Accessing content security settings in managed Beans

To determine security settings for a specific user, the UserTicket provides all necessary methods.
To check for example, if the current user may create an announcement the following code is used:

ASubmissionBean isMayCreateAnnouncement() method
public boolean isMayCreateAnnouncement() {         
    if (FxContext.getUserTicket().mayCreateACL(    //(1)
            CacheAdmin.getEnvironment().getACL("Announcement Type ACL").getId(), -1L))
        return true;
    return false;
}

(1) The user ticket is retrieved from the current context and mayCreateACL() is called to determine whether the current user may create instances of type announcement using the matching type-ACL.

Site running on a free Atlassian Confluence Open Source Project License granted to [fleXive] . Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.6.1 Build:#916 Nov 09, 2007) - Bug/feature request - Contact Administrators