Showing posts with label View Criteria. Show all posts
Showing posts with label View Criteria. Show all posts

Wednesday, November 24, 2010

Bit #27 - Setting a View Object attribute's Queryable property

Expanding on Bit #26 - Overriding getAttributeDef() to conditionally set an attribute property, you can set a View Object's attribute queryable property simply by calling setQueriable() on its ViewAttributeDefImpl. As explained in Bit #26, you can get the AttributeDef attribute definition by calling getAttributeDef() and passing the attribute index as a parameter. In order to call any of the attribute set...() methods, you will have to cast the AttributeDef interface to an ViewAttributeDefImpl implementation. By the way, did you know that by setting an attribute's queryable property will show or hide a View Criteria Item (i.e. the criterion) based on the attribute on the af:query dialog? Another way to hide the criterion was outlined in Bit #25 - Hiding a View Criteria item based on some condition. It will also show or hide the attribute from the Add Fields drop-down in the Advanced mode of af:query. One last thing: check-out the plethora of set...() methods available in the ViewAttributeDefImpl. As you may have guessed it, pretty much everything that is available declaratively on the Edit Attribute dialog, can be set (or reset) dynamically in your code based on some business condition. For a complete use case, check out the reference listed below.

Example:

  /**
   * Helper to set an attribute's queriable property.
   * Example:
   *    setQueriable(ViewRowImpl.SOMEFIELDINDEX, something.equals(somethingElse));
   *
   * @param attribIndex the attribute index
   * @param condition the condition (true/false)
   */
  protected void setQueriable(int attribIndex, boolean condition) {
      // set the attribute queryable as needed
      AttributeDef def = super.getAttributeDef(attribIndex);
      boolean queryable = condition;

      // set/reset queriable only if needed
      if (def != null && def.isQueriable() != queryable) {
          ViewAttributeDefImpl attributeDef = (ViewAttributeDefImpl)def;
          attributeDef.setQueriable(queryable);
      }
  }


Context:

View Object Implementation Class

References:

http://dstas.blogspot.com/2010/03/set-queryable-property-on-attribute.html

Monday, November 22, 2010

Bit #25 - Hiding a View Criteria item based on some condition

You can hide or show a View Criteria item (i.e. a criterion), based on some business logic condition by calling setProperty() on an oracle.jbo.ViewCriteriaItem. The method accepts a ViewCriteriaItemHints parameter indicating the view criteria item property to set - in this case CRITERIA_RENDERED_MODE - and a second ViewCriteriaItemHints parameter indicating the property value - in this case any of the CRITERIA_RENDERED_MODE_BOTH, CRITERIA_RENDERED_MODE_BASIC, CRITERIA_RENDERED_MODE_ADVANCED, CRITERIA_RENDERED_MODE_NEVER, CRITERIA_RENDERED_MODE_DEFAULT. To hide or show a criterion, you will have to look for it by iterating through all the criteria rows and all the criteria items for each row. Once found, call setProperty() to set its render mode. Here is an example helper method that illustrates this case.

Example:

    /**
     * Hides a view criterion.
     * Example: The following will hide the SourcePolicyNbr criterio if the condition
     *          is true. If the condition is false, it will show the criterio in BOTH basic and
     *          advanced.
     *        
     *          hideCriteriaItem("SomeCriteria", "SomeCriteriaItem",
     *             someCondition==true, ViewCriteriaItemHints.CRITERIA_RENDERED_MODE_BOTH);
     *
     *
     * @param viewCriteriaName the view criteria name
     * @param criteriaItemName the criterio name
     * @param condition the HIDE condition
     * @param showHint the SHOW hint
     */
     protected void hideCriteriaItem(String viewCriteriaName,
                                    String criteriaItemName, boolean condition,
                                    String showHint) {
        if (viewCriteriaName != null) {
            ViewCriteria v = this.getViewCriteria(viewCriteriaName);
            if (v != null) {
                boolean found = false;
                while (v.hasNext() && !found) {
                    ViewCriteriaRow vcr = (ViewCriteriaRow)v.next();
                    if (vcr != null) {
                        ViewCriteriaItem[] vcis = vcr.getCriteriaItemArray();
                        if (vcis != null && vcis.length > 0) {
                            for (int j = 0; j < vcis.length && !found; j++) {
                                ViewCriteriaItem vci = vcis[j];
                                if (vci != null && criteriaItemName != null &&
                                    criteriaItemName.equals(vci.getName())) {
                                    found = true;
                                    vci.setProperty(ViewCriteriaItemHints.CRITERIA_RENDERED_MODE,
                                                    condition ?
                                                    ViewCriteriaItemHints.CRITERIA_RENDERED_MODE_NEVER :
                                                    showHint);
                                    v.saveState();
                                }
                            }
                        }
                    }
                }
            }
        }
    }


Context:

View Object Implementation Class

Thursday, April 8, 2010

Bit #7 - Reseting the View Criteria associated with a View Object

To reset the View Criteria defined for a specific View Object, first you will need to retrieve the View Criteria from the View Object. You do this by calling the View Object method getViewCriteria() specifying the name of the View Criteria. This method will return a ViewCriteria object. Proceed with removing the criteria from the View Object by calling removeViewCriteria() on it. Call resetCriteria() on the ViewCriteria to reset them and finally re-apply the criteria to the View Object by calling applyViewCriteria() on it. Here is an example.

Example:

        // in the context of the Application Module Implementation

        ViewObjectImpl vo = this.getSomeViewObject();

        ViewCriteria vc = vo.getViewCriteria("criteria_name");
        vo.removeViewCriteria("criteria_name");

        vc.resetCriteria();
        vo.applyViewCriteria(vc);


Context:

Application Module Implementation
View Object Implementation


Related Posts Plugin for WordPress, Blogger...