O'Reilly logo

Professional Cairngorm™ by Jeremy Wischusen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

17.7. Implementation and Testing

The first thing you need to take care of is restricting access to the write view. If you go to the write view without being logged in there will be no user id for the currentUser and the submitPost function will give you a null reference in error when trying to retrieve the userId to set it as the authorId for the PostVO. To restrict access to the write view, edit the writeButton in the ApplicationControlBar in the MainView component to match the following:

<mx:LinkButton label="Write" id="writeButton"
visible="{(this.model.currentUser == null)
? false:(this.model.currentUser.accessLevel == 100)}" click="new
ChangeMainViewEvent(ChangeMainViewEvent.WRITE_VIEW).dispatch();"/>

Here the visible property is tied to the value of a ternary expression that checks to see if there is a current user. Simply checking to see if accessLevel equals 100 will not work and will cause the button to be shown until a user logs in and there is a value for the accessLevel property, so you first have to determine whether the currentUser property is null. If there is no user, the button is hidden. If there is a user, the access level is checked and the button is displayed if the access level is 100 (indicating that the user is an author).

Now edit the writeView HBox, adding the PostEditor view below the label:

<mx:HBox id="writeView"> <mx:Label styleName="viewHeader" text="Write"/> <views:PostEditor width="100%" postSubmitted="{this.model.postSubmissionStatus}"/> </mx:HBox> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required