コード例 #1
0
  protected void encodeMarkup(FacesContext context, Password password) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String clientId = password.getClientId(context);
    boolean disabled = password.isDisabled();

    String inputClass = Password.STYLE_CLASS;
    inputClass = password.isValid() ? inputClass : inputClass + " ui-state-error";
    inputClass = !disabled ? inputClass : inputClass + " ui-state-disabled";
    String styleClass =
        password.getStyleClass() == null ? inputClass : inputClass + " " + password.getStyleClass();

    writer.startElement("input", password);
    writer.writeAttribute("id", clientId, "id");
    writer.writeAttribute("name", clientId, null);
    writer.writeAttribute("type", "password", null);
    writer.writeAttribute("class", styleClass, null);
    if (password.getStyle() != null) {
      writer.writeAttribute("style", password.getStyle(), null);
    }

    String valueToRender = ComponentUtils.getValueToRender(context, password);
    if (!isValueEmpty(valueToRender) && password.isRedisplay()) {
      writer.writeAttribute("value", valueToRender, null);
    }

    renderPassThruAttributes(context, password, HTML.INPUT_TEXT_ATTRS);

    if (disabled) writer.writeAttribute("disabled", "disabled", null);
    if (password.isReadonly()) writer.writeAttribute("readonly", "readonly", null);

    writer.endElement("input");
  }
コード例 #2
0
  protected void encodeMarkup(FacesContext context, Editor editor) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String clientId = editor.getClientId(context);
    String valueToRender = ComponentUtils.getValueToRender(context, editor);
    String inputId = clientId + "_input";

    String style = editor.getStyle();
    style = style == null ? "visibility:hidden" : "visibility:hidden;" + style;

    writer.startElement("div", editor);
    writer.writeAttribute("id", clientId, null);
    writer.writeAttribute("style", style, null);
    if (editor.getStyleClass() != null) {
      writer.writeAttribute("class", editor.getStyleClass(), null);
    }

    writer.startElement("textarea", null);
    writer.writeAttribute("id", inputId, null);
    writer.writeAttribute("name", inputId, null);

    if (valueToRender != null) {
      writer.write(valueToRender);
    }

    writer.endElement("textarea");

    writer.endElement("div");
  }
コード例 #3
0
  protected void encodeMarkup(FacesContext context, Panel panel) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String clientId = panel.getClientId(context);
    String widgetVar = panel.resolveWidgetVar();
    Menu optionsMenu = panel.getOptionsMenu();
    boolean collapsed = panel.isCollapsed();
    boolean visible = panel.isVisible();

    writer.startElement("div", null);
    writer.writeAttribute("id", clientId, null);
    String styleClass =
        panel.getStyleClass() == null
            ? Panel.PANEL_CLASS
            : Panel.PANEL_CLASS + " " + panel.getStyleClass();

    if (collapsed) {
      styleClass += " ui-hidden-container";

      if (panel.getToggleOrientation().equals("horizontal")) {
        styleClass += " ui-panel-collapsed-h";
      }
    }

    if (!visible) {
      styleClass += " ui-helper-hidden";
    }

    writer.writeAttribute("class", styleClass, "styleClass");

    if (panel.getStyle() != null) {
      writer.writeAttribute("style", panel.getStyle(), "style");
    }

    writer.writeAttribute(HTML.WIDGET_VAR, widgetVar, null);

    renderDynamicPassThruAttributes(context, panel);

    encodeHeader(context, panel);
    encodeContent(context, panel);
    encodeFooter(context, panel);

    if (panel.isToggleable()) {
      encodeStateHolder(context, panel, clientId + "_collapsed", String.valueOf(collapsed));
    }

    if (panel.isClosable()) {
      encodeStateHolder(context, panel, clientId + "_visible", String.valueOf(visible));
    }

    if (optionsMenu != null) {
      optionsMenu.setOverlay(true);
      optionsMenu.setTrigger("@(" + ComponentUtils.escapeJQueryId(clientId) + "_menu)");
      optionsMenu.setMy("left top");
      optionsMenu.setAt("left bottom");

      optionsMenu.encodeAll(context);
    }

    writer.endElement("div");
  }
コード例 #4
0
  protected void encodeMarkup(FacesContext context, AccordionPanel acco) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String clientId = acco.getClientId(context);
    String widgetVar = acco.resolveWidgetVar();
    String styleClass = acco.getStyleClass();
    styleClass =
        styleClass == null
            ? AccordionPanel.CONTAINER_CLASS
            : AccordionPanel.CONTAINER_CLASS + " " + styleClass;

    if (ComponentUtils.isRTL(context, acco)) {
      styleClass = styleClass + " ui-accordion-rtl";
    }

    writer.startElement("div", null);
    writer.writeAttribute("id", clientId, null);
    writer.writeAttribute("class", styleClass, null);
    if (acco.getStyle() != null) {
      writer.writeAttribute("style", acco.getStyle(), null);
    }

    writer.writeAttribute("role", "tablist", null);

    writer.writeAttribute(HTML.WIDGET_VAR, widgetVar, null);

    encodeTabs(context, acco);

    encodeStateHolder(context, acco);

    writer.endElement("div");
  }
コード例 #5
0
  @Override
  public void encodeMarkup(FacesContext context, InputTextarea inputTextarea) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String clientId = inputTextarea.getClientId(context);
    String valueToRender = ComponentUtils.getValueToRender(context, inputTextarea);
    String style = inputTextarea.getStyle();
    String styleClass = inputTextarea.getStyle();
    styleClass =
        (styleClass == null)
            ? InputTextarea.MOBILE_STYLE_CLASS
            : InputTextarea.MOBILE_STYLE_CLASS + " " + styleClass;

    writer.startElement("textarea", null);
    writer.writeAttribute("data-role", "none", null);
    writer.writeAttribute("id", clientId, null);
    writer.writeAttribute("name", clientId, null);
    writer.writeAttribute("class", styleClass, null);

    renderPassThruAttributes(context, inputTextarea, HTML.INPUT_TEXTAREA_ATTRS);

    if (inputTextarea.isDisabled()) writer.writeAttribute("disabled", "disabled", "disabled");
    if (inputTextarea.isReadonly()) writer.writeAttribute("readonly", "readonly", "readonly");
    if (style != null) writer.writeAttribute("style", style, null);
    if (valueToRender != null) writer.writeText(valueToRender, "value");

    renderPassThruAttributes(context, inputTextarea, HTML.TEXTAREA_ATTRS);
    renderDomEvents(context, inputTextarea, HTML.INPUT_TEXT_EVENTS);

    writer.endElement("textarea");
  }
コード例 #6
0
 @Override
 public Object getConvertedValue(
     FacesContext context, UIComponent component, Object submittedValue)
     throws ConverterException {
   Renderer renderer =
       ComponentUtils.getUnwrappedRenderer(
           context, "javax.faces.SelectOne", "javax.faces.Listbox", Renderer.class);
   return renderer.getConvertedValue(context, component, submittedValue);
 }
コード例 #7
0
ファイル: WebXmlParser.java プロジェクト: XiuyeLee/primefaces
  private static Map<String, String> parseErrorPages(Element webXml) throws Exception {

    Map<String, String> errorPages = new HashMap<String, String>();

    XPath xpath = XPathFactory.newInstance().newXPath();

    NodeList exceptionTypes =
        (NodeList)
            xpath.compile("error-page/exception-type").evaluate(webXml, XPathConstants.NODESET);

    for (int i = 0; i < exceptionTypes.getLength(); i++) {
      Node node = exceptionTypes.item(i);

      String exceptionType = node.getTextContent().trim();
      String key = Throwable.class.getName().equals(exceptionType) ? null : exceptionType;

      String location = xpath.compile("location").evaluate(node.getParentNode()).trim();

      if (!errorPages.containsKey(key)) {
        errorPages.put(key, location);
      }
    }

    if (!errorPages.containsKey(null)) {
      String defaultLocation =
          xpath.compile("error-page[error-code=500]/location").evaluate(webXml).trim();

      if (ComponentUtils.isValueBlank(defaultLocation)) {
        defaultLocation =
            xpath
                .compile("error-page[not(error-code) and not(exception-type)]/location")
                .evaluate(webXml)
                .trim();
      }

      if (!ComponentUtils.isValueBlank(defaultLocation)) {
        errorPages.put(null, defaultLocation);
      }
    }

    return errorPages;
  }
コード例 #8
0
ファイル: InputRenderer.java プロジェクト: hmunoz/primefaces
  @Override
  public Object getConvertedValue(
      FacesContext context, UIComponent component, Object submittedValue)
      throws ConverterException {
    Converter converter = ComponentUtils.getConverter(context, component);

    if (converter != null) {
      String convertableValue = submittedValue == null ? null : submittedValue.toString();
      return converter.getAsObject(context, component, convertableValue);
    } else {
      return submittedValue;
    }
  }
コード例 #9
0
  @Override
  public Object getConvertedValue(
      FacesContext context, UIComponent component, Object submittedValue)
      throws ConverterException {
    Editor editor = (Editor) component;
    String value = (String) submittedValue;
    Converter converter = ComponentUtils.getConverter(context, component);

    if (converter != null) {
      return converter.getAsObject(context, editor, value);
    }

    return value;
  }
コード例 #10
0
  @Override
  public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    CommandLink link = (CommandLink) component;
    String clientId = link.getClientId(context);
    Object label = link.getValue();

    if (!link.isDisabled()) {
      String request;
      boolean ajax = link.isAjax();
      String styleClass = link.getStyleClass();
      styleClass =
          styleClass == null ? CommandLink.STYLE_CLASS : CommandLink.STYLE_CLASS + " " + styleClass;
      RequestContext requestContext = RequestContext.getCurrentInstance();
      boolean csvEnabled =
          requestContext.getApplicationContext().getConfig().isClientSideValidationEnabled()
              && link.isValidateClient();

      StringBuilder onclick = new StringBuilder();
      if (link.getOnclick() != null) {
        onclick.append(link.getOnclick()).append(";");
      }

      String onclickBehaviors = getOnclickBehaviors(context, link);
      if (onclickBehaviors != null) {
        onclick.append(onclickBehaviors);
      }

      writer.startElement("a", link);
      writer.writeAttribute("id", clientId, "id");
      writer.writeAttribute("href", "#", null);
      writer.writeAttribute("class", styleClass, null);
      if (link.getTitle() != null) {
        writer.writeAttribute("aria-label", link.getTitle(), null);
      }

      if (ajax) {
        request = buildAjaxRequest(context, link, null);
      } else {
        UIComponent form = ComponentUtils.findParentForm(context, link);
        if (form == null) {
          throw new FacesException(
              "Commandlink \"" + clientId + "\" must be inside a form component");
        }

        request = buildNonAjaxRequest(context, link, form, clientId, true);
      }

      if (csvEnabled) {
        CSVBuilder csvb = requestContext.getCSVBuilder();
        request =
            csvb.init()
                .source("this")
                .ajax(ajax)
                .process(link, link.getProcess())
                .command(request)
                .build();
      }

      onclick.append(request);

      if (onclick.length() > 0) {
        if (link.requiresConfirmation()) {
          writer.writeAttribute("data-pfconfirmcommand", onclick.toString(), null);
          writer.writeAttribute("onclick", link.getConfirmationScript(), "onclick");
        } else writer.writeAttribute("onclick", onclick.toString(), "onclick");
      }

      renderPassThruAttributes(context, link, HTML.LINK_ATTRS, HTML.CLICK_EVENT);

      if (label != null) writer.writeText(label, "value");
      else renderChildren(context, link);

      writer.endElement("a");
    } else {
      String styleClass = link.getStyleClass();
      styleClass =
          styleClass == null
              ? CommandLink.DISABLED_STYLE_CLASS
              : CommandLink.DISABLED_STYLE_CLASS + " " + styleClass;

      writer.startElement("span", link);
      writer.writeAttribute("id", clientId, "id");
      writer.writeAttribute("class", styleClass, "styleclass");

      if (link.getStyle() != null) writer.writeAttribute("style", link.getStyle(), "style");

      if (label != null) writer.writeText(label, "value");
      else renderChildren(context, link);

      writer.endElement("span");
    }
  }
コード例 #11
0
  protected void encodeMarkup(FacesContext context, DataTable table) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String clientId = table.getClientId(context);
    boolean scrollable = table.isScrollable();
    boolean hasPaginator = table.isPaginator();
    String style = table.getStyle();
    String paginatorPosition = table.getPaginatorPosition();

    // style class
    String containerClass =
        scrollable
            ? DataTable.CONTAINER_CLASS + " " + DataTable.SCROLLABLE_CONTAINER_CLASS
            : DataTable.CONTAINER_CLASS;
    containerClass =
        table.getStyleClass() != null
            ? containerClass + " " + table.getStyleClass()
            : containerClass;
    if (table.isResizableColumns())
      containerClass = containerClass + " " + DataTable.RESIZABLE_CONTAINER_CLASS;
    if (ComponentUtils.isRTL(context, table))
      containerClass = containerClass + " " + DataTable.RTL_CLASS;

    // default sort
    if (!table.isDefaultSorted() && table.getSortBy() != null && !table.isLazy()) {
      SortFeature sortFeature = (SortFeature) table.getFeature(DataTableFeatureKey.SORT);

      if (table.isMultiSort()) sortFeature.multiSort(context, table);
      else sortFeature.singleSort(context, table);

      table.setDefaultSorted();
    }

    if (hasPaginator) {
      table.calculateFirst();
    }

    writer.startElement("div", table);
    writer.writeAttribute("id", clientId, "id");
    writer.writeAttribute("class", containerClass, "styleClass");
    if (style != null) {
      writer.writeAttribute("style", style, "style");
    }

    encodeFacet(context, table, table.getHeader(), DataTable.HEADER_CLASS);

    if (hasPaginator && !paginatorPosition.equalsIgnoreCase("bottom")) {
      encodePaginatorMarkup(context, table, "top");
    }

    if (scrollable) {
      encodeScrollableTable(context, table);
    } else {
      encodeRegularTable(context, table);
    }

    if (hasPaginator && !paginatorPosition.equalsIgnoreCase("top")) {
      encodePaginatorMarkup(context, table, "bottom");
    }

    encodeFacet(context, table, table.getFooter(), DataTable.FOOTER_CLASS);

    if (table.isSelectionEnabled()) {
      encodeStateHolder(
          context,
          table,
          table.getClientId(context) + "_selection",
          table.getSelectedRowKeysAsString());
    }

    if (table.isDraggableColumns()) {
      encodeStateHolder(context, table, table.getClientId(context) + "_columnOrder", null);
    }

    if (scrollable) {
      encodeStateHolder(
          context, table, table.getClientId(context) + "_scrollState", table.getScrollState());
    }

    writer.endElement("div");
  }
コード例 #12
0
ファイル: DataGridRenderer.java プロジェクト: oyesiji/legacy
  protected void encodeScript(FacesContext facesContext, DataGrid grid) throws IOException {
    ResponseWriter writer = facesContext.getResponseWriter();
    String clientId = grid.getClientId(facesContext);
    String widgetVar = createUniqueWidgetVar(facesContext, grid);

    UIComponent form = ComponentUtils.findParentForm(facesContext, grid);
    if (form == null) {
      throw new FacesException("DataGrid : \"" + clientId + "\" must be inside a form element");
    }

    writer.startElement("script", null);
    writer.writeAttribute("type", "text/javascript", null);

    writer.write(widgetVar + " = new PrimeFaces.widget.DataGrid('" + clientId + "',{");
    writer.write("url:'" + getActionURL(facesContext) + "'");
    writer.write(",formId:'" + form.getClientId(facesContext) + "'");

    if (grid.isPaginator()) {
      writer.write(",paginator:new YAHOO.widget.Paginator({");
      writer.write("rowsPerPage:" + grid.getRows());
      writer.write(",totalRecords:" + grid.getRowCount());
      writer.write(",initialPage:" + grid.getPage());

      if (grid.getPageLinks() != 10) writer.write(",pageLinks:" + grid.getPageLinks());
      if (grid.getPaginatorTemplate() != null)
        writer.write(",template:'" + grid.getPaginatorTemplate() + "'");
      if (grid.getRowsPerPageTemplate() != null)
        writer.write(",rowsPerPageOptions : [" + grid.getRowsPerPageTemplate() + "]");
      if (grid.getFirstPageLinkLabel() != null)
        writer.write(",firstPageLinkLabel:'" + grid.getFirstPageLinkLabel() + "'");
      if (grid.getPreviousPageLinkLabel() != null)
        writer.write(",previousPageLinkLabel:'" + grid.getPreviousPageLinkLabel() + "'");
      if (grid.getNextPageLinkLabel() != null)
        writer.write(",nextPageLinkLabel:'" + grid.getNextPageLinkLabel() + "'");
      if (grid.getLastPageLinkLabel() != null)
        writer.write(",lastPageLinkLabel:'" + grid.getLastPageLinkLabel() + "'");
      if (grid.getCurrentPageReportTemplate() != null)
        writer.write(",pageReportTemplate:'" + grid.getCurrentPageReportTemplate() + "'");
      if (!grid.isPaginatorAlwaysVisible()) writer.write(",alwaysVisible:false");

      String paginatorPosition = grid.getPaginatorPosition();
      String paginatorContainer = null;
      if (paginatorPosition.equals("both"))
        paginatorContainer = clientId + "_paginatorTop','" + clientId + "_paginatorBottom";
      else if (paginatorPosition.equals("top")) paginatorContainer = clientId + "_paginatorTop";
      else if (paginatorPosition.equals("bottom"))
        paginatorContainer = clientId + "_paginatorBottom";

      writer.write(",containers:['" + paginatorContainer + "']");

      writer.write("})");

      if (grid.isEffect()) {
        writer.write(",effect:true");
        writer.write(",effectSpeed:'" + grid.getEffectSpeed() + "'");
      }
    }

    writer.write("});");

    writer.endElement("script");
  }