Пример #1
0
  //
  // Event processing: Creates a datatable and adds a component to it.
  //
  @Override
  public void processEvent(SystemEvent event) throws AbortProcessingException {
    FacesContext context = FacesContext.getCurrentInstance();
    if (!context.isPostback()) {
      Application application = context.getApplication();

      HtmlDataTable dataTable = new HtmlDataTable();
      dataTable.setVar("_internal");
      dataTable.setValueExpression(
          "value",
          application
              .getExpressionFactory()
              .createValueExpression(context.getELContext(), "#{addBean.list}", Object.class));
      getChildren().add(dataTable);

      UIColumn column = new UIColumn();
      column.setId(context.getViewRoot().createUniqueId());
      dataTable.getChildren().add(column);

      HtmlOutputText outputText = new HtmlOutputText();
      outputText.setId(context.getViewRoot().createUniqueId());
      outputText.setValueExpression(
          "value",
          application
              .getExpressionFactory()
              .createValueExpression(context.getELContext(), "#{_internal}", Object.class));
      column.getChildren().add(outputText);
    }
  }
  /**
   * Method that triggers when a section is selected
   *
   * @param event ValueChangeEvent object
   * @throws AbortProcessingException
   */
  public void selectedSection(ValueChangeEvent event) throws AbortProcessingException {
    if ((secObjMap == null) || (secObjMap.size() == 0)) return;

    UIInput sec_Selected = (UIInput) event.getComponent();

    if (((Boolean) sec_Selected.getValue()).booleanValue() == true) count++;
    else count--;
    if (sec_Selected.getParent() != null) {
      UIColumn secColumn = (UIColumn) sec_Selected.getParent();
      List<UIComponent> secChildren = secColumn.getChildren();
      if ((secChildren != null) && (secChildren.size() > 0)) {
        for (Iterator itr = secChildren.listIterator(); itr.hasNext(); ) {
          UIComponent comp = (UIComponent) itr.next();
          if (comp.getId().equals("hacksecid")) {
            UIInput hiddenSec = (UIInput) comp;
            if (selectedSecIds == null) {
              selectedSecIds = new ArrayList();
            }
            selectedSecIds.add((Integer) hiddenSec.getValue());
          }
        }
      }
    }
    if ((selectedSecIds != null) && (selectedSecIds.size() > 0)) {
      sectionSelected = true;
    }
    if ((selectedSecIds != null) && (selectedSecIds.size() == 1)) {
      selectedModId = ((SecModObj) secObjMap.get(selectedSecIds.get(0))).getModuleId();
    }
    return;
  }
Пример #3
0
    /**
     * Return the number of child <code>UIColumn</code> components nested in the specified <code>
     * UIData</code> that have a facet with the specified name.
     *
     * @param name Name of the facet being analyzed
     * @param columns the columns to search
     * @return the number of columns associated with the specified Facet name
     */
    private static boolean hasFacet(String name, List<UIColumn> columns) {

      if (!columns.isEmpty()) {
        for (UIColumn column : columns) {
          if (column.getFacetCount() > 0) {
            if (column.getFacets().containsKey(name)) {
              return true;
            }
          }
        }
      }
      return false;
    }
Пример #4
0
  protected void renderHeader(FacesContext context, UIComponent table, ResponseWriter writer)
      throws IOException {

    TableMetaInfo info = getMetaInfo(table);
    UIComponent header = getFacet(table, "header");
    String headerClass = (String) table.getAttributes().get("headerClass");
    if ((header != null) || (info.hasHeaderFacets)) {
      writer.startElement("thead", table);
      writer.writeText("\n", table, null);
    }
    if (header != null) {
      writer.startElement("tr", header);
      writer.startElement("th", header);
      if (headerClass != null) {
        writer.writeAttribute("class", headerClass, "headerClass");
      }
      writer.writeAttribute("colspan", String.valueOf(info.columns.size()), null);
      writer.writeAttribute("scope", "colgroup", null);
      encodeRecursive(context, header);
      writer.endElement("th");
      renderRowEnd(table, writer);
    }
    if (info.hasHeaderFacets) {
      writer.startElement("tr", table);
      writer.writeText("\n", table, null);
      for (UIColumn column : info.columns) {
        String columnHeaderClass = (String) column.getAttributes().get("headerClass");
        writer.startElement("th", column);
        if (columnHeaderClass != null) {
          writer.writeAttribute("class", columnHeaderClass, "columnHeaderClass");
        } else if (headerClass != null) {
          writer.writeAttribute("class", headerClass, "headerClass");
        }
        writer.writeAttribute("scope", "col", null);
        UIComponent facet = getFacet(column, "header");
        if (facet != null) {
          encodeRecursive(context, facet);
        }
        writer.endElement("th");
        writer.writeText("\n", table, null);
      }
      renderRowEnd(table, writer);
    }
    if ((header != null) || info.hasHeaderFacets) {
      writer.endElement("thead");
      writer.writeText("\n", table, null);
    }
  }
Пример #5
0
  public static void encodeHeader(
      FacesContext facesContext,
      UIComponent component,
      SelectManyRendererBase renderer,
      String rowClass,
      String cellClass)
      throws IOException {
    ResponseWriter writer = facesContext.getResponseWriter();
    AbstractSelectManyComponent select = (AbstractSelectManyComponent) component;
    Iterator<UIColumn> headers = select.columns();

    if (headers.hasNext()) {
      writer.startElement("tr", component);
      StringBuilder headerClass = new StringBuilder(rowClass);
      if (select.getHeaderClass() != null && !select.getHeaderClass().isEmpty()) {
        if (headerClass.length() > 0) {
          headerClass.append(" ");
        }
        headerClass.append(select.getHeaderClass());
      }

      writer.writeAttribute("class", headerClass, null);
      while (headers.hasNext()) {
        UIColumn header = headers.next();
        writer.startElement("th", component);
        writer.writeAttribute("class", cellClass, null);
        UIComponent facet = header.getFacet("header");
        if (facet != null && facet.isRendered()) {
          facet.encodeBegin(facesContext);
          if (facet.getRendersChildren()) {
            facet.encodeChildren(facesContext);
          } else {
            renderer.renderChildren(facesContext, facet);
          }
          facet.encodeEnd(facesContext);
        }
        writer.endElement("th");
      }
      writer.endElement("tr");
    }
  }
Пример #6
0
  protected void renderRow(
      FacesContext context, UIComponent table, UIComponent child, ResponseWriter writer)
      throws IOException {

    // Iterate over the child UIColumn components for each row
    int columnStyleIdx = 0;
    TableMetaInfo info = getMetaInfo(table);
    for (UIColumn column : info.columns) {

      // Render the beginning of this cell
      boolean isRowHeader = Boolean.TRUE.equals(column.getAttributes().get("rowHeader"));
      if (isRowHeader) {
        writer.startElement("th", column);
        writer.writeAttribute("scope", "row", null);
      } else {
        writer.startElement("td", column);
      }

      if (info.columnClasses.length > 0) {
        writer.writeAttribute("class", info.columnClasses[columnStyleIdx++], "columnClasses");
        if (columnStyleIdx >= info.columnClasses.length) {
          columnStyleIdx = 0;
        }
      }

      // Render the contents of this cell by iterating over
      // the kids of our kids
      for (Iterator<UIComponent> gkids = getChildren(column); gkids.hasNext(); ) {
        encodeRecursive(context, gkids.next());
      }

      // Render the ending of this cell
      if (isRowHeader) {
        writer.endElement("th");
      } else {
        writer.endElement("td");
      }
      writer.writeText("\n", table, null);
    }
  }
Пример #7
0
    public UIComponent buildWidget(
        String elementName, Map<String, String> attributes, UIMetawidget metawidget) {

      FacesContext context = FacesContext.getCurrentInstance();
      Application application = context.getApplication();
      Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, null);

      if (clazz == null) {
        return null;
      }

      // Colors (as of RichFaces 3.3.1)

      if (Color.class.equals(clazz)) {
        if (WidgetBuilderUtils.isReadOnly(attributes)) {
          return FacesContext.getCurrentInstance()
              .getApplication()
              .createComponent(HtmlOutputText.COMPONENT_TYPE);
        }

        return application.createComponent("org.richfaces.ColorPicker");
      }

      // Suggestion box
      //
      // Note: for suggestion box to work in table column footer facets, you need
      // https://jira.jboss.org/jira/browse/RF-7700

      if (String.class.equals(clazz)) {
        String facesSuggest = attributes.get(FACES_SUGGEST);

        if (facesSuggest != null) {
          UIComponent stubComponent = application.createComponent(UIStub.COMPONENT_TYPE);
          List<UIComponent> children = stubComponent.getChildren();

          // Standard text box

          HtmlInputText inputText =
              (HtmlInputText) application.createComponent(HtmlInputText.COMPONENT_TYPE);
          inputText.setStyle(((HtmlMetawidget) metawidget).getStyle());
          inputText.setStyleClass(((HtmlMetawidget) metawidget).getStyleClass());
          children.add(inputText);

          UISuggestionBox suggestionBox =
              (UISuggestionBox) application.createComponent(HtmlSuggestionBox.COMPONENT_TYPE);

          // Lock the 'id's so they don't get changed. This is important for the
          // JavaScript getElementById that RichFaces generates. Also, do not just use
          // 'viewRoot.createUniqueId' because, as per the RenderKit specification:
          //
          // "If the value returned from component.getId() is non-null and does not start
          // with UIViewRoot.UNIQUE_ID_PREFIX, call component.getClientId() and render
          // the result as the value of the id attribute in the markup for the component."
          //
          // Therefore the 'id' attribute is never rendered, therefore the JavaScript
          // getElementById doesn't work. Add our own prefix instead

          inputText.setId("suggestionText_" + FacesUtils.createUniqueId());
          suggestionBox.setId("suggestionBox_" + FacesUtils.createUniqueId());

          // Suggestion box

          suggestionBox.setFor(inputText.getId());
          suggestionBox.setVar("_internal");
          children.add(suggestionBox);

          try {
            // RichFaces 3.2/JSF 1.2 mode
            //
            // Note: we wrap the MethodExpression as an Object[] to stop link-time
            // dependencies on javax.el.MethodExpression, so that we still work with
            // JSF 1.1
            //
            // Note: according to JavaDocs returnType is only important when literal
            // (i.e. without #{...}) expression is used, otherwise Object.class is fine
            // (http://community.jboss.org/message/516830#516830)

            Object[] methodExpression =
                new Object[] {
                  application
                      .getExpressionFactory()
                      .createMethodExpression(
                          context.getELContext(),
                          facesSuggest,
                          Object.class,
                          new Class[] {Object.class})
                };
            ClassUtils.setProperty(suggestionBox, "suggestionAction", methodExpression[0]);
          } catch (Exception e) {
            // RichFaces 3.1/JSF 1.1 mode

            MethodBinding methodBinding =
                application.createMethodBinding(facesSuggest, new Class[] {Object.class});
            suggestionBox.setSuggestionAction(methodBinding);
          }

          // Column
          //
          // Note: this must be javax.faces.component.html.HtmlColumn, not
          // org.richfaces.component.html.HtmlColumn. The latter displayed okay, but when
          // a value was selected it did not populate back to the HtmlInputText

          UIColumn column =
              (UIColumn)
                  application.createComponent(javax.faces.component.html.HtmlColumn.COMPONENT_TYPE);
          column.setId(FacesUtils.createUniqueId());
          suggestionBox.getChildren().add(column);

          // Output text box

          UIComponent columnText = application.createComponent(HtmlOutputText.COMPONENT_TYPE);
          columnText.setId(FacesUtils.createUniqueId());
          ValueBinding valueBinding = application.createValueBinding("#{_internal}");
          columnText.setValueBinding("value", valueBinding);
          column.getChildren().add(columnText);

          return stubComponent;
        }
      }

      return null;
    }
Пример #8
0
  public void encodeChildren(FacesContext context, UIComponent component) throws IOException {

    if ((context == null) || (component == null)) {
      throw new NullPointerException(
          Util.getExceptionMessageString(Util.NULL_PARAMETERS_ERROR_MESSAGE_ID));
    }
    if (log.isTraceEnabled()) {
      log.trace("Begin encoding children " + component.getId());
    }
    if (!component.isRendered()) {
      if (log.isTraceEnabled()) {
        log.trace(
            "No encoding necessary "
                + component.getId()
                + " since "
                + "rendered attribute is set to false ");
      }
      return;
    }
    UIData data = (UIData) component;

    ValueBinding msgsBinding = component.getValueBinding("value");
    List msgBeanList = (List) msgsBinding.getValue(context);

    // Set up variables we will need
    String columnClasses[] = getColumnClasses(data);
    int columnStyle = 0;
    int columnStyles = columnClasses.length;
    String rowClasses[] = getRowClasses(data);
    int rowStyles = rowClasses.length;
    ResponseWriter writer = context.getResponseWriter();
    Iterator kids = null;
    Iterator grandkids = null;

    // Iterate over the rows of data that are provided
    int processed = 0;
    int rowIndex = data.getFirst() - 1;
    int rows = data.getRows();
    int rowStyle = 0;

    writer.startElement("tbody", component);
    writer.writeText("\n", null);
    int hideDivNo = 0;
    while (true) {
      //			PrivateMessageDecoratedBean dmb = null;
      //			if(msgBeanList !=null && msgBeanList.size()>(rowIndex+1) &&
      // rowIndex>=-1)
      //			{
      //				dmb = (PrivateMessageDecoratedBean)msgBeanList.get(rowIndex+1);
      //			}
      //			boolean hasChildBoolean = false;
      //			if(dmb != null)
      //			{
      //				for(int i=0; i<msgBeanList.size(); i++)
      //				{
      //					PrivateMessageDecoratedBean tempDmb =
      // (PrivateMessageDecoratedBean)msgBeanList.get(i);
      //					if(tempDmb.getUiInReply() != null &&
      // tempDmb.getUiInReply().getId().equals(dmb.getMsg().getId()))
      //					{
      //						hasChildBoolean = true;
      //						break;
      //					}
      //				}
      //			}
      // Have we displayed the requested number of rows?
      if ((rows > 0) && (++processed > rows)) {
        break;
      }
      // Select the current row
      data.setRowIndex(++rowIndex);
      if (!data.isRowAvailable()) {
        break; // Scrolled past the last row
      }

      PrivateMessageDecoratedBean dmb = null;
      dmb = (PrivateMessageDecoratedBean) data.getRowData();
      boolean hasChildBoolean = false;
      if (dmb != null) {
        // if dmb has depth = 0, check for children
        if (dmb.getDepth() == 0) {
          // first, get the index of the dmb
          int index = -1;

          for (int i = 0; i < msgBeanList.size(); i++) {
            PrivateMessageDecoratedBean tempDmb = (PrivateMessageDecoratedBean) msgBeanList.get(i);
            if (dmb.getMsg().getId().equals(tempDmb.getMsg().getId())) {
              index = i;
              break;
            }
          }
          if (index < (msgBeanList.size() - 1) && index >= 0) {
            PrivateMessageDecoratedBean nextDmb =
                (PrivateMessageDecoratedBean) msgBeanList.get(index + 1);

            if (nextDmb.getDepth() > 0) {
              hasChildBoolean = true;
            }
          }
        }
      }

      if (dmb != null && dmb.getDepth() > 0) {
        writer.write(
            "<tr style=\"display:none\" id=\"_id_"
                + new Integer(hideDivNo).toString()
                + "__hide_division_"
                + "\">");
      } else {
        writer.write("<tr>");
      }

      if (rowStyles > 0) {
        writer.writeAttribute("class", rowClasses[rowStyle++], "rowClasses");
        if (rowStyle >= rowStyles) {
          rowStyle = 0;
        }
      }
      writer.writeText("\n", null);

      // Iterate over the child UIColumn components for each row
      columnStyle = 0;
      kids = getColumns(data);
      while (kids.hasNext()) {

        // Identify the next renderable column
        UIColumn column = (UIColumn) kids.next();

        // Render the beginning of this cell
        writer.startElement("td", column);
        if (columnStyles > 0) {
          writer.writeAttribute("class", columnClasses[columnStyle++], "columnClasses");
          if (columnStyle >= columnStyles) {
            columnStyle = 0;
          }
        }

        if (dmb != null && dmb.getDepth() > 0) {
          if (column.getId().endsWith("_msg_subject")) {
            StringBuilder indent = new StringBuilder();
            int indentInt = dmb.getDepth() * 4;
            for (int i = 0; i < indentInt; i++) {
              indent.append("&nbsp;");
            }
            writer.write(indent.toString());
          }
        } else {
          if (column.getId().endsWith("_msg_subject")) {
            if (hasChildBoolean && dmb.getDepth() == 0) {
              writer.write(
                  " <img src=\""
                      + BARIMG
                      + "\" style=\""
                      + CURSOR
                      + "\" id=\"_id_"
                      + Integer.valueOf(hideDivNo).toString()
                      + "__img_hide_division_\""
                      + " onclick=\"");
              int childNo = getTotalChildNo(dmb, msgBeanList);
              String hideTr = "";
              for (int i = 0; i < childNo; i++) {
                hideTr +=
                    "javascript:showHideDiv('_id_"
                        + (hideDivNo + i)
                        + "', '"
                        + RESOURCE_PATH
                        + "');";
              }
              writer.write(hideTr);
              writer.write("\" />");
            }
          }
        }
        // Render the contents of this cell by iterating over
        // the kids of our kids
        grandkids = getChildren(column);
        while (grandkids.hasNext()) {
          encodeRecursive(context, (UIComponent) grandkids.next());
        }

        // Render the ending of this cell
        writer.endElement("td");
        writer.writeText("\n", null);
      }

      // Render the ending of this row
      writer.endElement("tr");
      writer.writeText("\n", null);
      if (dmb != null && dmb.getDepth() > 0) {
        ////
        /*ValueBinding expandedBinding =
        	component.getValueBinding("expanded");
        String expanded = "";
        if(expandedBinding != null)
        	expanded = (String)expandedBinding.getValue(context);

        if(expanded.equalsIgnoreCase("true"))
        {*/
        writer.write("<script type=\"text/javascript\">");
        writer.write(" showHideDiv('_id_" + hideDivNo + "', '" + RESOURCE_PATH + "');");
        writer.write("</script>");
        //////				}

        hideDivNo++;
      }
    }
    writer.endElement("tbody");
    writer.writeText("\n", null);

    // Clean up after ourselves
    data.setRowIndex(-1);
    if (log.isTraceEnabled()) {
      log.trace("End encoding children " + component.getId());
    }
  }
Пример #9
0
  public static void encodeOneRow(
      FacesContext facesContext,
      UIComponent component,
      SelectManyRendererBase renderer,
      ClientSelectItem clientSelectItem,
      String cssPrefix)
      throws IOException {
    AbstractSelectManyComponent table = (AbstractSelectManyComponent) component;
    String defaultItemCss = cssPrefix + ITEM_CSS;
    String defaultItemCssDis = cssPrefix + ITEM_CSS_DIS;

    ResponseWriter writer = facesContext.getResponseWriter();
    String clientId = table.getClientId(facesContext);
    String itemClientId = clientId + "Item" + clientSelectItem.getSortOrder();
    clientSelectItem.setClientId(itemClientId);
    writer.startElement(HtmlConstants.TR_ELEMENT, table);
    writer.writeAttribute("id", itemClientId, null);
    String itemCss;
    if (!table.isDisabled()) {
      itemCss = HtmlUtil.concatClasses(table.getItemClass(), defaultItemCss);
    } else {
      itemCss = HtmlUtil.concatClasses(table.getItemClass(), defaultItemCss, defaultItemCssDis);
    }
    writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, itemCss, null);

    String cellClassName = cssPrefix + CELL_CSS;

    String[] columnClasses;
    if (table.getColumnClasses() != null) {
      columnClasses = table.getColumnClasses().split(",");
    } else {
      columnClasses = new String[0];
    }
    int columnCounter = 0;
    Iterator<UIColumn> columnIterator = table.columns();
    while (columnIterator.hasNext()) {
      UIColumn column = columnIterator.next();
      if (column.isRendered()) {
        writer.startElement(HtmlConstants.TD_ELEM, table);

        Object width = column.getAttributes().get("width");
        if (width != null) {
          writer.writeAttribute(
              "style", "width: " + HtmlDimensions.formatSize(width.toString()), null);
        }

        String columnClass;
        if (columnClasses.length > 0) {
          columnClass =
              HtmlUtil.concatClasses(
                  cellClassName,
                  columnClasses[columnCounter % columnClasses.length],
                  column.getAttributes().get("styleClass"));
        } else {
          columnClass =
              HtmlUtil.concatClasses(cellClassName, column.getAttributes().get("styleClass"));
        }
        writer.writeAttribute("class", columnClass, null);
        renderer.renderChildren(facesContext, column);
        writer.endElement(HtmlConstants.TD_ELEM);
        columnCounter++;
      }
    }
    writer.endElement(HtmlConstants.TR_ELEMENT);
  }