Tuesday, December 13, 2011

An EO validation rule that involves a transient attribute

Problem
Say you have a VO with a transient attribute (e.g., AmountSpent), and an entity-based attribute (e.g., MaxAmount).  The value of AmountSpent (the transient attribute) is set when the application starts.  Then, the user enters a value for MaxAmount (the entity-based attribute) in the UI.

Now, say you need to validate that MaxAmount is greater than AmountSpent.  The transient attribute does not exist in the EO, so a simple Compare validation rule is not possible.

How can you do this? 

Solution
First, create a method on the Application Module to return the value of the transient attribute:

  public Number getAmountSpent() {
    AmountVOImpl vo = this.getAmountVO1();
    AmountVORowImpl row = (AmountVORowImpl)vo.getCurrentRow();
    return row.getAmountSpent();
  }

Next, create a validation rule on the entity-based attribute (MaxAmount).  In this rule, compare the value of MaxAmount to a Groovy expression that calls the AM method. Here's the expression:

  source.getDBTransaction().getRootApplicationModule().getAmountSpent()

Note that you need to use "source" at the start of the Groovy expression. The reason for this is explained in the Fusion Dev Guide.

This rule will give you the validation you need.

2 comments:

  1. Hi There is a problem with this appoach.
    In case of exception thrown , the actual exception msg can go hidden.
    Please refer to blog:
    http://jobinesh.blogspot.com/2010/06/jbo-27023-failed-to-validate-all-rows.html

    ReplyDelete
  2. Casinos Near Casinos Near Casinos & Gambling
    A map showing casinos 양주 출장샵 and other gaming facilities located near Casinos & Gambling in the United States. 문경 출장마사지 Find 구리 출장안마 addresses, see photos and 포항 출장샵 read real 정읍 출장마사지 reviews.

    ReplyDelete