Filtering source views for use in #xpages

In our continuing example of purchase orders, we move from our examination of dynamic field binding in repeats to the filter used on the source view to select the competition questions we want to appear in that repeat control.

Depending on the type of competition, the source selection method and the dollar amount of the purchase order, there are different questions that the person preparing the purchase order needs to answer about the competition. There are several categories of competition questions, but the layout for the questions and answers remains the same, so I created a custom control that is used by all categories and the custom control appears on the XPage multiple times.

Each time, I pass the category as one of the properties of the custom control, as well as the criteria (type, method and amount). My view is set up with four sorted columns to filter my competition questions, so with the help of Per Henrik Lausten on StackOverflow, I learned that all I have to do is create an array to be used as the key, just as I would in LotusScript for a GetAllDocumentsByKey.

On our Purchase Order XPage, the syntax for one of the custom control insertions would appear as follows:

<xc:pro_competitionQuestions_cc
		sectionTitle="Competitive Process" competitionType="#{javascript:competitionType}"
		sourceSelectionMethod="#{javascript:sourceSelectionMethod}"
		dollarRange="#{javascript:dollarRange}">
</xc:pro_competitionQuestions_cc>

When referring to the custom properties of a custom control within that control, you use compositeData followed by the property name. It makes it rather easy to pass parameters to the control.

In Java, arrays are handled by using a Vector. Simply create the Vector, then addElement to add each of my four filters (category, type, method and amount). When this is assigned to the Keys element of a dominoView used as a source, it filters the documents returned to provide only those that match our filter criteria. Here’s our filter in action:

<xp:this.data>
    <xp:dominoView var="competitionQuestionView"
     viewName="CompetitionQuestions" keysExactMatch="true"
     sortOrder="ascending"
     sortColumn="QuestionSortOrder">
       <xp:this.keys><![CDATA[#{javascript:var vArray = new java.util.Vector();
        vArray.add(compositeData.sectionTitle);
        vArray.add(compositeData.competitionType);
        vArray.add(compositeData.sourceSelectionMethod);
        vArray.add(compositeData.dollarRange);

        return vArray;
        }]]></xp:this.keys>
    </xp:dominoView>
</xp:this.data>

*Updated to us vArray.add instead of vArray.addElement on Jesse Gallagher’s advice. Thanks, Jesse!

Advertisements
Categories: Server-Side Javascript, Xpages | Tags: , , , , | 3 Comments

Post navigation

3 thoughts on “Filtering source views for use in #xpages

  1. This is definitely a good trick to keep familiar with. One pedantic note, though: it’s better to use “add” instead of “addElement” when working with Vectors (same goes with “get” instead of “elementAt”). The reason is that “add” and “get” are the standard methods common for all Lists – using them will save some headache down the line, particularly since some XPage controls wisely prefer ArrayLists to Vectors. The “element” methods in Vector are just a byproduct of Java’s misguided 1.0 API.

  2. Pingback: Nesting repeats to provide links to attachments in #XPages | Lost in XPages, Soon to be Found

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

Create a free website or blog at WordPress.com.

%d bloggers like this: