public void beforeRenderComponent() {
    super.beforeRenderComponent();

    // Initialize the dashboard (loads all its kpi panels)
    DashboardHandler.lookup().getCurrentDashboard();

    // Get the filter.
    DashboardFilter filter = getFilter();

    // Check all visible properties exist.
    Iterator props = properties.iterator();
    while (props.hasNext()) {
      DashboardFilterProperty dashboardFilterProperty = (DashboardFilterProperty) props.next();
      if (!dashboardFilterProperty.isPropertyAlive()) props.remove();
    }

    // Check if filtered properties for this filter component are already in dashboard filter.
    DashboardFilterProperty[] beingFilteredProps = getBeingFilteredProperties();
    for (int i = 0; i < beingFilteredProps.length; i++) {
      List dfProperties = Arrays.asList(filter.getPropertyIds());
      DashboardFilterProperty beignFilteredProp = beingFilteredProps[i];
      if (!dfProperties.contains(beignFilteredProp.getPropertyId()))
        beignFilteredProp.setBeignFiltered(false);
    }

    // Check filtered properties and hide from available filter properties (set property not
    // visible)
    String[] propIds = filter.getPropertyIds();
    for (int i = 0; i < propIds.length; i++) {
      String propId = propIds[i];
      DashboardFilterProperty prop = getDashboardFilterProperty(propId);
      if (prop == null) {
        DashboardFilterProperty parentProperty = filter.getPropertyInParentDashboards(propId);
        if (parentProperty != null) {
          prop =
              new DashboardFilterProperty(
                  parentProperty.getDataProviderCode(), propId, getFilter(), null, true);
          properties.add(prop);
        }
      } else {
        prop.setBeignFiltered(true);
      }
    }
  }
  // Return if is needed to serialize and save properties after this call because properties that
  // does not exist on current filter or data providers must be deleted from persistence.
  // return: must clear serialized trash properties after deserialize process saving this data.
  public boolean deserializeComponentData(String serializedData) throws Exception {
    // Load options and visible properties
    if (serializedData == null || serializedData.trim().length() == 0) {
      log.info("No data to deserialize.");
      return false;
    }

    DOMParser parser = new DOMParser();
    parser.parse(new InputSource(new StringReader(serializedData)));
    Document doc = parser.getDocument();
    NodeList nodes = doc.getElementsByTagName("dashboard_filter");
    if (nodes.getLength() > 1) {
      log.error("Each dashboard filter component just can parse one <dashboard_filter>");
      return false;
    }
    if (nodes.getLength() == 0) {
      log.info("No data to deserialize.");
      return false;
    }

    boolean needsToSerializeAfter = false;
    serializedProperties = serializedData;
    Node rootNode = nodes.item(0);
    nodes = rootNode.getChildNodes();
    for (int x = 0; x < nodes.getLength(); x++) {
      Node node = nodes.item(x);
      if (node.getNodeName().equals("property")) {
        // Parse visible properties.
        String dataProviderCode = node.getAttributes().getNamedItem("providerCode").getNodeValue();
        String propertyId = node.getAttributes().getNamedItem("id").getNodeValue();
        String sectionId = null;
        boolean visible = false;
        NodeList subnodes = node.getChildNodes();
        for (int i = 0; i < subnodes.getLength(); i++) {
          Node subnode = subnodes.item(i);
          if (subnode.getNodeName().equals("section")) {
            sectionId = subnode.getFirstChild().getNodeValue();
          }
          if (subnode.getNodeName().equals("visible")) {
            visible = Boolean.valueOf(subnode.getFirstChild().getNodeValue()).booleanValue();
          }
        }
        Long lSectionId = sectionId != null ? Long.decode(sectionId) : null;
        DashboardFilterProperty filterProp =
            new DashboardFilterProperty(
                dataProviderCode, propertyId, getFilter(), lSectionId, true);
        filterProp.setVisible(visible);
        if (filterProp.isPropertyAlive()) properties.add(filterProp);
        else needsToSerializeAfter = true;
      } else if (node.getNodeName().equals("options")) {
        // Parse component options.
        NodeList options = node.getChildNodes();
        String showRefreshButton = null;
        String showPropertyNames = null;
        String showClearButton = null;
        String showApplyButton = null;
        String showSubmitOnChange = null;
        String showShortViewMode = null;
        String showLegend = null;
        String showAutoRefresh = null;
        for (int i = 0; i < options.getLength(); i++) {
          Node option = options.item(i);
          if (option.getNodeName().equals("showRefreshButton"))
            showRefreshButton = option.getFirstChild().getNodeValue();
          if (option.getNodeName().equals("showPropertyNames"))
            showPropertyNames = option.getFirstChild().getNodeValue();
          if (option.getNodeName().equals("showClearButton"))
            showClearButton = option.getFirstChild().getNodeValue();
          if (option.getNodeName().equals("showApplyhButton"))
            showApplyButton = option.getFirstChild().getNodeValue();
          if (option.getNodeName().equals("showSubmitOnChange"))
            showSubmitOnChange = option.getFirstChild().getNodeValue();
          if (option.getNodeName().equals("shortViewMode"))
            showShortViewMode = option.getFirstChild().getNodeValue();
          if (option.getNodeName().equals("showLegend"))
            showLegend = option.getFirstChild().getNodeValue();
          if (option.getNodeName().equals("showAutoRefresh"))
            showAutoRefresh = option.getFirstChild().getNodeValue();
        }
        this.showPropertyNames = Boolean.valueOf(showPropertyNames).booleanValue();
        this.showRefreshButton = Boolean.valueOf(showRefreshButton).booleanValue();
        this.showApplyButton = Boolean.valueOf(showApplyButton).booleanValue();
        this.showClearButton = Boolean.valueOf(showClearButton).booleanValue();
        this.showSubmitOnChange = Boolean.valueOf(showSubmitOnChange).booleanValue();
        this.isShortMode = Boolean.valueOf(showShortViewMode).booleanValue();
        this.showLegend = Boolean.valueOf(showLegend).booleanValue();
        this.showAutoRefresh = Boolean.valueOf(showAutoRefresh).booleanValue();

        // Enable auto-refresh if necessary on start.
        if (this.showAutoRefresh) setRefreshEnabled(true);
      }
    }
    return needsToSerializeAfter;
  }
  public CommandResponse actionFilter(CommandRequest request) {
    try {
      // Init attributes for start applying the filter.
      filterPropertyErrors.clear();

      // Parse parameters and set the filter.
      Iterator visiblePropertiesIt = properties.iterator();
      while (visiblePropertiesIt.hasNext()) {
        DashboardFilterProperty dashboardFilterProperty =
            (DashboardFilterProperty) visiblePropertiesIt.next();

        // Is property already in the dashboard filter?. Then is not possible to filter by this
        // property, it's already added to dashboard filter.
        if (dashboardFilterProperty.isBeingFiltered()) continue;
        if (!dashboardFilterProperty.isPropertyAlive()) {
          log.warn(
              "Trying to filter by "
                  + dashboardFilterProperty.getPropertyId()
                  + ". This property is not in any dataset.");
          continue;
        }
        if (!dashboardFilterProperty.isVisible()) continue;

        Object[] result;
        try {
          result =
              requestProcessor.parseDashboardProperty(
                  request.getRequestObject(), dashboardFilterProperty);
        } catch (Exception e) {
          log.error("Error parsing property " + dashboardFilterProperty.getPropertyId() + ".", e);
          continue;
        }

        if (result.length != 3) {
          log.error(
              "Error parsing property: '"
                  + dashboardFilterProperty.getPropertyId()
                  + "' for dataProvider: '"
                  + dashboardFilterProperty.getDataProviderCode()
                  + "'");
          continue;
        }

        Collection allowedValues = (Collection) result[0];
        Object minValue = result[1];
        Object maxValue = result[2];
        if (allowedValues == null && minValue == null && maxValue == null) continue;

        // Set the filter with this property.
        Dashboard currentDashboard = DashboardHandler.lookup().getCurrentDashboard();
        if (currentDashboard.filter(
            dashboardFilterProperty.getPropertyId(),
            minValue,
            true,
            maxValue,
            true,
            allowedValues,
            FilterByCriteria.ALLOW_ANY)) {
          return new ShowCurrentScreenResponse();
        }
      }
    } catch (Exception e) {
      log.error("Error trying to filter properties for dashboard", e);
    }
    return null;
  }