示例#1
0
 public void updateModel(FacesContext context, UIComponent comp) {
   // System.out.println(getDesc(comp, "UPDATE"));
   // System.out.println("  valid: " + isComponentValid(comp));
   // System.out.println("  setLocalValueInValueBinding: " + setLocalValueInValueBinding);
   if (!isComponentValid(comp) || !setLocalValueInValueBinding) {
     return;
   }
   // System.out.println("  value: " + value);
   ValueBinding vb = comp.getValueBinding(name);
   // System.out.println("  vb: " + vb);
   if (vb == null) return;
   try {
     vb.setValue(context, value);
     // System.out.println("  vb.setValue worked");
     clearValue();
   } catch (PropertyNotFoundException e) {
     // System.out.println("PropertyNotFoundException: " + e);
     // It's ok for the application to not use a settable ValueBinding,
     //  since the UIComponent can keep the value. But they probably
     //  don't mean to, so we should log something
     log.info(e);
     // Don't keep trying to set it
     discontinueSettingLocalValueInValueBinding();
   } catch (Exception e) {
     // System.out.println("Exception: " + e);
     String msgId = comp.getClass().getName() + '.' + name;
     Object label = MessageUtils.getComponentLabel(context, comp);
     FacesMessage msg = MessageUtils.getMessage(context, msgId, new Object[] {label, value});
     if (msg != null) context.addMessage(comp.getClientId(context), msg);
     setInvalid(comp);
   }
 }
示例#2
0
 /**
  * @param context FacesContext
  * @param component UIComponent
  * @param name String
  * @return Object
  */
 private static Object get(FacesContext context, UIComponent component, String name) {
   ValueBinding binding = component.getValueBinding(name);
   if (binding != null) {
     return binding.getValue(context);
   } else {
     return component.getAttributes().get(name);
   }
 }
示例#3
0
  private String encodeParentAndChildrenAsString(FacesContext fc, UIComponent uic) {
    StringBuffer str = new StringBuffer();
    if (uic instanceof CommandSortHeader) {
      if (uic.getChildCount() > 0) {
        Iterator iter = uic.getChildren().iterator();
        while (iter.hasNext()) {
          UIComponent child = (UIComponent) iter.next();
          str.append(encodeParentAndChildrenAsString(fc, child));
        }
      }
    }
    Object value = uic.getAttributes().get("value");
    if (value == null) {
      ValueBinding vb = uic.getValueBinding("value");
      if (vb != null) {
        value = vb.getValue(fc);
      }
    }
    if (value == null) {
      return str.toString();
    }
    Converter converter = null;
    if (uic instanceof ValueHolder) {
      converter = ((ValueHolder) uic).getConverter();
    }
    if (converter == null) {
      converter =
          FacesContext.getCurrentInstance().getApplication().createConverter(value.getClass());
    }
    if (converter != null) {
      str.append(converter.getAsString(FacesContext.getCurrentInstance(), uic, value));
    } else {
      str.append(value);
    }

    // don't process selectItems or f:param for uiCommand)
    if (uic instanceof UISelectBoolean
        || uic instanceof UISelectMany
        || uic instanceof UISelectOne
        || uic instanceof UICommand) {
      return str.toString();
    }

    if (uic.getChildCount() > 0) {
      Iterator iter = uic.getChildren().iterator();
      while (iter.hasNext()) {
        UIComponent child = (UIComponent) iter.next();
        str.append(encodeParentAndChildrenAsString(fc, child));
      }
    }
    return str.toString();
  }
示例#4
0
 public Object getValue(FacesContext context, UIComponent comp) {
   // System.out.println(getDesc(comp, "GET"));
   // System.out.println("  value: " + value);
   if (value != null) {
     return value;
   }
   ValueBinding vb = comp.getValueBinding(name);
   // System.out.println("  vb: " + vb);
   if (vb != null) {
     Object modelValue = vb.getValue(context);
     // System.out.println("  modelValue: " + modelValue);
     return modelValue;
   }
   return null;
 }
  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());
    }
  }
 private Object get(UIComponent component, FacesContext context, String name) {
   ValueBinding binding = component.getValueBinding(name);
   if (binding != null) return binding.getValue(context);
   else return component.getAttributes().get(name);
 }
  @SuppressWarnings("deprecation")
  public UIComponent processWidget(
      UIComponent component,
      String elementName,
      Map<String, String> attributes,
      UIMetawidget metawidget) {

    // Actions don't get converters

    if (ACTION.equals(elementName)) {
      return component;
    }

    // Recurse into stubs...

    if (component instanceof UIStub) {
      // ...whose children have the same value binding as us...
      //
      // (this is important because choice of Converter is based off the attributes Map, and
      // if the value binding is different then all bets are off as to the accuracy of the
      // attributes)

      javax.faces.el.ValueBinding valueBinding = component.getValueBinding("value");

      if (valueBinding != null) {
        String expressionString = valueBinding.getExpressionString();

        List<UIComponent> children = component.getChildren();

        for (UIComponent componentChild : children) {
          javax.faces.el.ValueBinding childValueBinding = componentChild.getValueBinding("value");

          if (childValueBinding == null) {
            continue;
          }

          if (!expressionString.equals(childValueBinding.getExpressionString())) {
            continue;
          }

          // ...and apply the Converter to them

          processWidget(componentChild, elementName, attributes, metawidget);
        }
      }

      return component;
    }

    // Ignore components that cannot have Converters

    if (!(component instanceof ValueHolder)) {
      return component;
    }

    // Defer evaluation of EL-based converters, else we will fail trying to store/restore them
    // from the ViewState

    ValueHolder valueHolder = (ValueHolder) component;
    String converterId = attributes.get(FACES_CONVERTER);

    if (converterId != null && FacesUtils.isExpression(converterId)) {

      FacesContext context = FacesContext.getCurrentInstance();
      component.setValueBinding(
          "converter", context.getApplication().createValueBinding(converterId));
      return component;
    }

    // Standard Converter

    valueHolder.setConverter(getConverter(valueHolder, attributes));

    return component;
  }