Home > Articles > Web Development

Dojo Made Easy

This chapter is from the book

Composite Dojo Extensions

Some extension controls are available under the Dojo category that do not fit into the previous categories. Rather than extending core controls available, these controls add new functionality not previously available as controls in XPages.

As Listing 5.3 shows, the dijit.form.HorizontalSlider requires multiple HTML elements. In the same way, some of the Dojo controls are more complex. Sliders comprise multiple components for their implementation, whereas the Dojo Link Select and Dojo Image Select controls have complex properties to define the values.

Sliders

The beginning of this chapter covered adding a slider with traditional Dojo. The code was covered in Listing 5.4, where the slider comprised a div with an ordered list of labels and an onchange event passing the value to a hidden field via Client-Side JavaScript. The sliders in the Extension Library remove the necessity to use a div with an onChange event to store the value. Rather, the sliders themselves are bound directly to the field.

There are two types of sliders, the Dojo Horizontal Slider (xe:djHorizontalSlider) and the Dojo Vertical Slider (xe:djVerticalSlider), as Figure 5.16 shows. Although the properties for both are identical and shown in Table 5.10, you need to choose the relevant slider at development time.

Table 5.10. xe:djHorizontalSlider and xe:djVerticalSlider Properties

Property

Description

clickSelect

Defines whether the user can change the value by clicking on a position on the bar in addition to dragging the slider.

discreteValues

Defines the number of discrete values between the minimum and maximum values.

maximum

Defines the maximum value for the slider.

minimum

Defines the minimum value for the slider.

pageIncrement

Defines the number of increments applied to the slider when the user clicks the Page Up or Page Down button.

showButtons

Defines whether buttons are shown to move the slider.

slideDuration

Defines the number of milliseconds it takes to move the slider from 0% to 100%; it is 1000 milliseconds by default.

The values of the slider are controlled by four properties: defaultValue defines the initial starting value (if the field the control is bound to does not already have a value), whereas minimum and maximum define the bounds of the slider, and discreteValues defines the number of steps between the minimum and maximum. By default, whenever the user clicks on a part of the slider, that value is selected, and this is controlled by the clickSelect property. If set to false, this functionality is suppressed. Also, by default, there are buttons on either end of the slider for moving the current position. Again, these can be suppressed by setting the showButtons property to false.

Figure 5.16

Figure 5.16. Sliders.

Besides clicking on a position of the slider or using the buttons, you can use keyboard shortcuts to control the movement, like you did for the spinner controls. All four cursor keys can be used for both sliders: left (←) and down (↓) moving in one direction, right (→) and up (↑) moving in the other direction. Although the cursor keys can be used to increment in small amounts, Page Up and Page Down increment in larger amounts. The smaller increment is always one step on the slider, but the developer can override the larger increment—by default 2 steps—using the pageIncrement property. Furthermore, because the speed of increment could be controlled for the spinners, it can also be controlled for the sliders, by means of the slideDuration property. This is a value in milliseconds that the slider will take to move from one end of the slider to the other; by default, it is one second.

As with the traditional Dojo implementation, you can add labels. This comprises two further controls: the Dojo Slider Rule (xe:djSliderRule) for the markers and the Dojo Slider Rule Labels (xe:djSliderRuleLabels) for the actual labels. For both controls, two properties determine how many and where the rules appear: count and container. The container provides a ComboBox list of options, with all four options available regardless: topDecoration, leftDecoration, bottomDecoration, and rightDecoration. Obviously, you must choose the relevant container for the relevant slider; rightDecoration and leftDecoration are not applicable for the Dojo Horizontal Slider.

You can map styling to CSS classes for both controls. You can style the markers by using the ruleStyle property on the Dojo Slider Rule, whereas you can style the labels by using the labelStyle property on the Dojo Slider Rule Labels.

You can set a number of additional properties for the Dojo Slider Rule Labels. The minimum and maximum properties set the top and bottom level for the labels, and numericMargin can define how many labels to omit at either end of the label list. So setting the value to 1 omits 0% and 100% from a default Dojo Slider Rule Labels control. As this suggests, the default labels are percentages, running from 0% to 100%. But you can override this in two ways. You can pass an array of labels into the labels property or use the labelList property, as shown in Listing 5.15. This method is recommended over <li> tags because it supports localization.

Listing 5.15. Dojo Horizontal Slider

<xe:djHorizontalSlider
   id="djHorizontalSlider2"
   value="#{sessionScope.djSlider1}"
   maximum="100"
   minimum="0"
   style="margin: 5px;width:200px; height: 20px;"
   discreteValues="10"
   pageIncrement="3">
   <xp:this.converter>
      <xp:convertNumber
         integerOnly="true">
      </xp:convertNumber>
   </xp:this.converter>
   <xe:djSliderRuleLabels
      id="djSliderRuleLabels2"
      container="topDecoration"
      style="height:10px;font-size:75%;color:gray;"
      count="6"
      numericMargin="1">
   </xe:djSliderRuleLabels>
   <xe:djSliderRule
      id="djSliderRule5"
      container="topDecoration"
      style="height:5px;" count="6">
   </xe:djSliderRule>
   <xe:djSliderRule
      id="djSliderRule6"
      style="height:5px;"
      count="5"
      container="bottomDecoration">
   </xe:djSliderRule>
   <xe:djSliderRuleLabels
      id="djSliderRuleLabels5"
      container="bottomDecoration"
      style="height:10px;font-size:75%;color:gray;">
<xe:this.labelsList>
        <xe:djSliderRuleLabel
           label="green tea">
        </xe:djSliderRuleLabel>
        <xe:djSliderRuleLabel
           label="coffee">
        </xe:djSliderRuleLabel>
        <xe:djSliderRuleLabel
           label="red bull">
        </xe:djSliderRuleLabel>
     </xe:this.labelsList>   </xe:djSliderRuleLabels>
</xe:djHorizontalSlider>

Table 5.11 shows the properties for the Dojo Slider Rule and Dojo Slider Rule Labels.

Table 5.11. xe:djSliderRule and xe:djSliderRuleLabels Properties

Property

Description

count

Defines how many markers or labels should appear.

labels

Allows the developer to write a Client-Side JavaScript expression to define the labels. This property is available only for the Dojo Slider Rule Labels.

labelsList

Allows the developer to define a localizable set of labels. This property is available only for the Dojo Slider Rule Labels.

maximum

Defines the maximum position for the labels. This property is available only for the Dojo Slider Rule Labels.

minimum

Defines the minimum position for the labels. This property is available only for the Dojo Slider Rule Labels.

numericMargin

Defines the number of labels to omit from either end of the label list. This property is available only for the Dojo Slider Rule Labels.

container

Defines where in relation to the slider line the markers or labels should appear.

ruleStyle

Defines the styling for the markers.

labelStyle

Defines the styling for the labels and is available only for Dojo Slider Rule Labels.

Dojo Link Select (xe:djLinkSelect)

The Dojo Link Select control allows developers to group link options so that when one link is selected, the others are deselected. You can see this in action with the filter area of the All Documents page on the TeamRoom database. Here, for example, selecting All by Date not only selects that entry but deselects the default All link. Unlike the traditional link functionality, you can bind the Link Select to a field or scoped variable. In addition, you can trigger a wealth of events from the Link Select.

Despite having properties multipleTrim and multipleSeparator, the control allows only one value to be selected at any one time. You can define the available options in a number of ways. The All Documents page (allDocumentsFilter.xsp custom control) uses selectItem controls, but you can also use a selectItems control. As with the ComboBox and FilteringSelect controls covered earlier, there is currently no mechanism to add an xp:selectItem or xp:selectItems control from the palette. So you can use the core ComboBox or ListBox control to define the values; then you can cut and paste the code across from the core control to the Dojo control.

Alternatively, there are three dataProviders available. Those who are comfortable with Java may choose to use the beanValuePicker. The other options are the simpleValuePicker and the dominoViewValuePicker. The simpleValuePicker allows a developer to define a list of options as a string of label value pairs. The label values themselves are defined in the valueList property. You can define the separator between the label and the value using the labelSeparator property, and you can define the separator between values using the valueListSeparator property. The dominoViewValuePicker allows you to select the options from a view, by defining the databaseName and viewName properties. The labelColumn property defines the column from which the values will be picked. The value set when the label is clicked is pulled from the first column in the view. So Listing 5.16 shows a Dojo Link Select where the options are pulled from the AllStates view, showing the Names column. Figure 5.17 shows the resulting output. As you can see, the onChange event refreshes the computed field with the value whenever you select a new link.

Figure 5.17

Figure 5.17. Link Select with dominoViewValuePicker.

Listing 5.16. Link Select Control with dominoViewValuePicker

<xe:djextLinkSelect
   id="djextLinkSelect2"
   defaultValue="MA"
   value="#{viewScope.link3}">
   <xe:this.dataProvider>
      <xe:dominoViewValuePicker
         viewName="AllStates"
         labelColumn="Name">
      </xe:dominoViewValuePicker>
   </xe:this.dataProvider>
   <xp:eventHandler
      event="onChange"
      submit="true"
      refreshMode="partial"
      refreshId="computedField3">
   </xp:eventHandler>
</xe:djextLinkSelect>

Table 5.12 shows the pertinent properties for the Dojo Link Select control.

Table 5.12. xe:djLinkSelect Properties

Property

Description

dataProvider

Provides the options for the Dojo Link Select as an xe:simpleValuePicker, xe:dominoViewValuePicker, or xe:beanValuePicker.

firstItemStyle

Defines styling for the first link.

firstItemStyleClass

Defines the class to be applied to the first link.

itemStyle

Defines styling for the intermediate links.

itemStyleClass

Defines the class to be applied to the intermediate links.

lastItemStyle

Defines styling for the last link.

lastItemStyleClass

Defines the class to be applied to the last link.

Dojo Image Select

The Dojo Image Select control is similar to the Link Select in that it provides a group of links, or in this case images, only one of which can be selected. Again, it is bound to a field or scoped variable, with a default value that can be set. The images are defined using selectImage child controls of the imageValues property. Each selectImage has image and selectedImage properties, to define the images that appear when the link is deselected or selected. The selectedValue property defines the value that will be set when the image is clicked. In addition, properties are available for styling each image, both in its deselected state and its selected state. The example on the Core_FormControl.xsp XPage in the Extension Library Demo database, reproduced in Listing 5.17 and shown in Figure 5.18, shows buttons appropriate for a Calendar View control, although, as will be shown in Chapter 7, a slightly different method is used for the calendar view in the TeamRoom database.

Figure 5.18

Figure 5.18. Dojo Link Select for Calendar Picker.

Listing 5.17. Dojo Image Select for Calendar Picker

<xe:djextImageSelect
   id="djextImageSelect1"
   title="Select a value default is two days"
   value="#{viewScope.image1}"
   defaultValue="T">
   <xe:this.imageValues>
      <xe:selectImage
         selectedValue="D"

selectedImage="/.ibmxspres/.extlib/icons/calendar/1_Day_selected_24.
gif"

image="/.ibmxspres/.extlib/icons/calendar/1_Day_deselected_24.gif"
      imageAlt="One Day">
   </xe:selectImage>
   <xe:selectImage
      selectedValue="T"

selectedImage="/.ibmxspres/.extlib/icons/calendar/2_Days_selected_24.
gif"

image="/.ibmxspres/.extlib/icons/calendar/2_Days_deselected_24.gif"
         imageAlt="Two Days">
      </xe:selectImage>
      <xe:selectImage
         selectedValue="F"

selectedImage="/.ibmxspres/.extlib/icons/calendar/1_Work_Week_selected_
24.gif"

image="/.ibmxspres/.extlib/icons/calendar/1_Work_Week_deselected_24.gif"
         imageAlt="One Work Week">
      </xe:selectImage>
      <xe:selectImage
         selectedValue="W"

selectedImage="/.ibmxspres/.extlib/icons/calendar/1_Week_selected_24.
gif"

image="/.ibmxspres/.extlib/icons/calendar/1_Week_deselected_24.gif"
         imageAlt="One Week">
       </xe:selectImage>
       <xe:selectImage
          selectedValue="2"

selectedImage="/.ibmxspres/.extlib/icons/calendar/2_Weeks_selected_24.
gif"

image="/.ibmxspres/.extlib/icons/calendar/2_Weeks_deselected_24.gif"
         imageAlt="Two Weeks">
       </xe:selectImage>
       <xe:selectImage
          selectedValue="M"

selectedImage="/.ibmxspres/.extlib/icons/calendar/Month_selected_24.
gif"
image="/.ibmxspres/.extlib/icons/calendar/Month_deselected_24.gif"
         imageAlt="One Month">
       </xe:selectImage>
       <xe:selectImage
          selectedValue="Y"

selectedImage="/.ibmxspres/.extlib/icons/calendar/All_Entries_selected_
24.gif"

image="/.ibmxspres/.extlib/icons/calendar/All_Entries_deselected_24.gif
"
          imageAlt="All Entries">
       </xe:selectImage>
  </xe:this.imageValues>
  <xp:eventHandler
    event="onClick"
    submit="true"
    refreshMode="partial"
    refreshId="computedField3">
  </xp:eventHandler>
</xe:djextImageSelect>

Table 5.13 details the additional properties available for the Dojo Image Select control.

Table 5.13. xe:djImageSelect Properties

Property

Description

image

Defines the image shown when this image is not selected.

imageAlt

Defines the alt text to appear when the user hovers over the image.

selectedImage

Defines the image shown when this image is selected.

selectedStyle

Defines styling to be applied when this image is selected.

selectedStyleClass

Defines the class to be applied when this image is selected.

selectedValue

Defines the value to pass when this image is selected.

style

Defines styling to be applied when this image is not selected.

styleClass

Defines the class to be applied when this image is not selected.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020