AD104 Intro to Managed Beans (Russel Maher, MWLUG 2012)

Introduction

This presentation was not on my initial ‘to-study list’ so I will add it there. The presentation was held by Russel Maher at the MWLUG 2012.

Not surprisingly this presentation has quiet some familiarities with the presentation Improving XPages Application Performance with Managed Beans (Russell Maher, The View Advanced Xpages 2012).

Same presenter, similar topic.

Beginnings

Why use beans, managed beans and Java in your XPage projects:

  • Makes your applications run faster.
  • Reduces app maintenance efforts.–
  • Improves reliability.
  • Makes you a stronger developer.
  • Enhances your professional skills.

Complexity

Arguments why objects are sometimes better:

  • A user can have more metadata than just their name and roles.
  • A “document” might actually be comprised of multiple records.
  • An “environment” might be comprised of multiple databases.

Reduce complexity by embracing complexity:

  • Managing a large number of scoped variables in your app.
  • Dynamic visibility of scoped variables.
  • Progressive disclosure of scoped variables.

Requirements of a Managed:

  • Java class.
  • No-argument constructor.
  • Expose properties/fields through getters/setters.
  • Serializable.

Persistance

Sometimes data needs to stick around for a while:

  • “Data” can be a number or a complex object.
    • Session scoped.
    • A session is generally there until the user shuts down the browser.

Persistence allows you to know what the user did “before”

  • They saved a document.
  • They saved as draft/complete.

Beans can be scoped to application, session, view, request or none.

Managed Properties

Sharing data between beans:

  • Representing complex objects typically results in a “logical normalization” of data.
    • You generally will include all of the data about an object with that object.
    • You generally will not duplicate that data into other objects.
  • You want to pass data from one bean to another.
  • You need to read some existing data in another bean from your current bean.

Options for sharing data across beans:

  • Using variable resolvers:
    • Accessing other beans through the session map.
    • See: Persistence
  • Using managed properties:
    • One bean is a property of another bean.
    • Configured in faces-config.xml.
    • Object declared within “container” bean.
    • At run time the managed property is “injected” into the container bean.

Defined in Faces-config.xml:

 

How to use the managed property:

 

 

Managed property setter:

 

Tips

Use proper scopes and load order

  • Use the longest scope you need that will work:
    • Issues with viewScope serialization?
      • -> Use session scope.
    • Only need the bean for a single request?
      • -> Request scope.
    • Don’t need the bean to persist at all?
      • -> None scope.
  • Every bean must be called before it can be used.
    • If you try to inject Bean B into Bean as a managed property and Bean A has not been instantiated yet…you got problems.
    • If Bean A errors out but is a managed property of Bean B…you got problems.

Use Java UUID to get unique numbers

  • Designed to give universally unique numbers.
  • Beats inventing your own mechanism if all you need is a unique number.

 

 

Summary

Another great introduction on managed beans, especially if you didn’t get a hold on the Improving XPages Application Performance with Managed Beans from The View conference.

I haven’t taken a look at the example database, which was demonstrated during this presentation but that is something I will surely will when returning back to the office on Monday.

That’s it for this week. It has been a great 5 days of Java in Xpages. For next Monday I schedule ‘Zähme den Tiger – Java-Entwicklung in Notes und Domino‘. Looking forward to rehearse my German skills!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s