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

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

Creating a new announcement

<h:form id="entryForm">
    <fx:content typeName="announcementEntry" var="entry">  <!-- (1) -->
        <fx:value property="caption"/><br/>
        <fx:value property="announcementText"/><br/>
        <fx:value property="publishDate"/><br/>
        <fx:value property="publishURL"/><br/>
        <h:commandButton action="#{asubmissionBean.saveReadAll}" value='Save with "Read all" ACL'> <!-- (2) -->
            <f:setPropertyActionListener target="#{asubmissionBean.content}" value="#{entry_content}"/> <!-- (3) -->
        </h:commandButton>
        <br/>
        <h:commandButton action="#{asubmissionBean.saveEditorsOnly}" value='Save with "Editors only" ACL'> <!-- (4) -->
            <f:setPropertyActionListener target="#{asubmissionBean.content}" value="#{entry_content}"/> <!-- (3) -->
        </h:commandButton>
    </fx:content>
</h:form>

(1) <fx:content/> from the [fleXive] component library is used to create a new announcement content instance.
(2) The Save with "Read all" ACL command button's action is bound to the saveReadAll() method of the JSF managed ASubmissionBean, which sets an instance ACL that grants all users the permission to read this content instance.
(3) The property action listener maps the in instance created by <fx:content/> to the variable content in ASubmissionBean, so that the save methods have access to the newly created content.
(4) The Save with "Editors Only" ACL command button's action is bound to the saveEditorsOnly() method of the JSF managed ASubmissionBean, which sets an instance ACL that only grants editors the permission to read this content instance.

JSF managed ASubmissionBean

ASubmissionBean's method save methods
public String saveReadAll() {
    try {
        content.setAclId(CacheAdmin.getEnvironment().getACL("Announcement Instance Read All").getId()); // (1)
        EJBLookup.getContentEngine().save(content.copy()); //(2)
    } catch (FxApplicationException e) {
        new FxFacesMsgErr(e).addToContext();
        return null;
    }
    return "instance_created";
}

public String saveEditorsOnly() {
    try {
        content.setAclId(CacheAdmin.getEnvironment().getACL("Announcement Instance Editors Only").getId()); //(3)
        EJBLookup.getContentEngine().save(content.copy());
    } catch (FxApplicationException e) {
        new FxFacesMsgErr(e).addToContext();
        return null;
    }
    return "instance_created";
}

(1) The previously defined instance ACL "Announcement Instance Read All" is assigned to the content, which grants all users read permission.
(2) Before the content is saved content.copy() is called. This is important in order to preserve the original content instance for display on a JSF-page, as the save method automatically alters and compacts the content instance to minimize disc space.
(3) The previously defined instance ACL "Announcement Instance Editors Only" is assigned to the content, which grants read permission to editors only.

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