Preparing for Add or Replicate

In this Lesson

You will

  • Learn how to provide default values for input fields used in add mode
  • Learn about the agent’s ability to replicate information for add mode operations

Concepts

When your solution is prompting the user for information it is good to provide default values, when possible, to reduce the amount of information they have to enter.

For example, imagine the Party Pool solution has the following requirements for default values.

  • The location field should always be defaulted to TBD (to be determined)
  • After a party is added, the host name and contact information should be used as the default for the next party to be added. This makes it easier to enter multiple parties for a single person or organization.

Soiree provides two mechanisms for providing default values for add operations.

  1. Default values for add mode
    This is the ability to pre-populate some of the input fields when the input fields are prepared for add mode.
  2. Replicate Mode
    Replicate mode is a transition mode used for layers that remain open after an add mode operation. It transitions an agent back into Add mode and retains the values in the agent’s scheme so they become the default values for the next add operation. This is in contrast to using only the Add mode – which will remove values from the agent’s scheme in preparation for receiving new values.

Default Values for Add Mode

In this exercise you will provide a default value for the party location when adding a new party.

  1. Open the Party agent Java file



  2. Open the Override/Implement Methods dialog



  3. Select the prepareForAddOrReplicateMode method



  4. Add this code to the end of the prepareForAddOrReplicateMode method
    if (!replicate){
    	scheme.setPartyLocation("TBD");
    }
    

    Your class should now look like this



  5. Save the Party class
  6. Start the party solution [ start the database and server if necessary ]
    Server not Running?
    If you attempt to start a solution when the server is not running you will receive a message saying the solution you requested is not on the server classpath.
  7. Advance to the Create a Party layer
    The location field will contain the default value.



Replicate Mode

In this exercise you will modify the add layer to retain the values in the agent’s scheme after a party is added so they become the default values for the next party to be added.

  1. Open the PartyDefinition scene
  2. Select the Add layer and switch to Agent Binding perspective.
    Change the Post-Add mode to Replicate



  3. Save the scene
  4. Use the solution to add a new party
    Notice that all the fields retain their values after the party is added.



Agent customization for Replicate Mode

In this exercise you will customize the agent’s replicate processing to default only the host name and contact information – but only if the customer wants them to be retained.

  1. Open the Party agent item
  2. Add a new Boolean node named retainHost



  3. The Party agent should now look like this



  4. Build the agent
    The agent view should show the build was successful



  5. Open the Party Java file
  6. Replace the previous prepareForAddOrReplicateMode method customization with
    if (replicate){
    	if (scheme.isRetainHost()){
    		//remove all values except the host information
    		scheme.setPartyName(null);
    		scheme.setPartyDate(null);
    		scheme.setPartyTimeStart(null);
    		scheme.setPartyTimeEnd(null);
    		scheme.setPartyType(null);
    	}else{
    		scheme.clearNodes(); //remove values from all the scheme nodes
    	}
    }
    scheme.setPartyLocation("TBD"); //always default the location
    
  7. The Party class should now look like this



  8. Save the class
  9. Return to the PartyDefinition scene in the scene editor
  10. Make the Create a Party container taller by dragging the top edge of the container up.



  11. Modify the layer definition as shown here
    • Select the OK and Cancel buttons by pressing and holding the Control (OS X) or CTRL (Windows) key while using the mouse to select the buttons.
    • Drag the buttons down to make room for another element under the Email field
    • Add a Check Box to the scene. Double click the check box and change its input text to Retain Host Information



  12. Switch to the Agent Binding perspective
  13. Press the Refresh button to obtain the modified Party scheme definition.
  14. Bind the retainHost node to the check box.



  15. Save the scene
  16. Retest the solution
    • When Retain Host Information is selected the host information will be replicated after adding a party. The location will also be defaulted.
    • When Retain Host Information is NOT selected only location will be defaulted.

You have reached the end of this lesson.