Search in sources :

Example 1 with HtmlCommandLink

use of javax.faces.component.html.HtmlCommandLink in project primefaces by primefaces.

the class Exporter method exportValue.

protected String exportValue(FacesContext context, UIComponent component) {
    if (component instanceof HtmlCommandLink) {
        // support for PrimeFaces and standard HtmlCommandLink
        HtmlCommandLink link = (HtmlCommandLink) component;
        Object value = link.getValue();
        if (value != null) {
            return String.valueOf(value);
        } else {
            // export first value holder
            for (UIComponent child : link.getChildren()) {
                if (child instanceof ValueHolder) {
                    return exportValue(context, child);
                }
            }
            return Constants.EMPTY_STRING;
        }
    } else if (component instanceof ValueHolder) {
        if (component instanceof EditableValueHolder) {
            Object submittedValue = ((EditableValueHolder) component).getSubmittedValue();
            if (submittedValue != null) {
                return submittedValue.toString();
            }
        }
        ValueHolder valueHolder = (ValueHolder) component;
        Object value = valueHolder.getValue();
        if (value == null) {
            return Constants.EMPTY_STRING;
        }
        Converter converter = valueHolder.getConverter();
        if (converter == null) {
            Class valueType = value.getClass();
            converter = context.getApplication().createConverter(valueType);
        }
        if (converter != null) {
            if (component instanceof UISelectMany) {
                StringBuilder builder = new StringBuilder();
                List collection = null;
                if (value instanceof List) {
                    collection = (List) value;
                } else if (value.getClass().isArray()) {
                    collection = Arrays.asList(value);
                } else {
                    throw new FacesException("Value of " + component.getClientId(context) + " must be a List or an Array.");
                }
                int collectionSize = collection.size();
                for (int i = 0; i < collectionSize; i++) {
                    Object object = collection.get(i);
                    builder.append(converter.getAsString(context, component, object));
                    if (i < (collectionSize - 1)) {
                        builder.append(",");
                    }
                }
                String valuesAsString = builder.toString();
                builder.setLength(0);
                return valuesAsString;
            } else {
                return converter.getAsString(context, component, value);
            }
        } else {
            return value.toString();
        }
    } else if (component instanceof CellEditor) {
        return exportValue(context, component.getFacet("output"));
    } else if (component instanceof HtmlGraphicImage) {
        return (String) component.getAttributes().get("alt");
    } else if (component instanceof OverlayPanel) {
        return Constants.EMPTY_STRING;
    } else {
        // This would get the plain texts on UIInstructions when using Facelets
        String value = component.toString();
        if (value != null) {
            return value.trim();
        } else {
            return Constants.EMPTY_STRING;
        }
    }
}
Also used : UISelectMany(javax.faces.component.UISelectMany) CellEditor(org.primefaces.component.celleditor.CellEditor) HtmlCommandLink(javax.faces.component.html.HtmlCommandLink) HtmlGraphicImage(javax.faces.component.html.HtmlGraphicImage) UIComponent(javax.faces.component.UIComponent) ValueHolder(javax.faces.component.ValueHolder) EditableValueHolder(javax.faces.component.EditableValueHolder) FacesException(javax.faces.FacesException) OverlayPanel(org.primefaces.component.overlaypanel.OverlayPanel) Converter(javax.faces.convert.Converter) List(java.util.List) EditableValueHolder(javax.faces.component.EditableValueHolder)

Example 2 with HtmlCommandLink

use of javax.faces.component.html.HtmlCommandLink in project empire-db by apache.

the class TabViewTag method createCommandLink.

protected HtmlCommandLink createCommandLink(FacesContext context, String linkId) {
    // CommandLink link
    HtmlCommandLink link = InputControlManager.createComponent(context, HtmlCommandLink.class);
    link.setId(linkId);
    return link;
}
Also used : HtmlCommandLink(javax.faces.component.html.HtmlCommandLink)

Example 3 with HtmlCommandLink

use of javax.faces.component.html.HtmlCommandLink in project empire-db by apache.

the class TabViewTag method encodeTabLink.

protected void encodeTabLink(FacesContext context, ResponseWriter writer, int index, TabPageTag page, boolean disabled) throws IOException {
    // Add component
    HtmlCommandLink link = null;
    List<UIComponent> tabLinks = getChildren();
    if (tabLinks.size() > index) {
        UIComponent c = tabLinks.get(index);
        if (c instanceof HtmlCommandLink) {
            link = (HtmlCommandLink) c;
        } else {
            // Something's wrong here?
            log.error("INFO: Unexpected child node for {}! Child item type is {}.", getClass().getName(), c.getClass().getName());
            // encode anyway
            c.setRendered(true);
            c.encodeAll(context);
            // Don't render twice!
            c.setRendered(false);
            return;
        }
    }
    if (link == null) {
        // create the tab-Link
        String linkId = this.TABLINK_ID_PREFIX + String.valueOf(index);
        link = createCommandLink(context, linkId);
        tabLinks.add(index, link);
        // Set TabPageActionListener
        TabPageActionListener tpal = new TabPageActionListener(this.getClientId());
        link.addActionListener(tpal);
    }
    // init linkComponent
    link.setValue(page.getTabLabel());
    link.setDisabled(disabled);
    // Set Style
    String styleClass = "eTabLink";
    link.setStyleClass(styleClass);
    // encode link
    link.setRendered(true);
    link.encodeAll(context);
    // Don't render twice!
    link.setRendered(false);
}
Also used : HtmlCommandLink(javax.faces.component.html.HtmlCommandLink) UIComponent(javax.faces.component.UIComponent)

Example 4 with HtmlCommandLink

use of javax.faces.component.html.HtmlCommandLink in project empire-db by apache.

the class TabViewTag method encodeTabs.

/*
    @Override
    public void processDecodes(FacesContext context)
    {
        super.processDecodes(context);
    }
    */
protected void encodeTabs(FacesContext context, ResponseWriter writer) throws IOException {
    Iterator<UIComponent> ci = getFacetsAndChildren();
    if (ci.hasNext() == false) {
        log.warn("Invalid TabPage definition!");
        return;
    }
    UIComponent panel = ci.next();
    int index = 0;
    int activeIndex = getActivePageIndex();
    // Patch for MOJARRA: Remove HtmlCommandLinks
    List<UIComponent> chk = panel.getChildren();
    for (int i = chk.size() - 1; i >= 0; i--) {
        if ((chk.get(i) instanceof HtmlCommandLink))
            chk.remove(i);
    }
    // Create Page Links
    for (UIComponent c : panel.getChildren()) {
        // Find Tab pages
        if (!(c instanceof TabPageTag)) {
            continue;
        }
        // found
        boolean active = (index == activeIndex);
        TabPageTag page = (TabPageTag) c;
        // render tab-link? default is true
        boolean rendered = ObjectUtils.getBoolean(ObjectUtils.coalesce(page.getAttributes().get(this.TAB_RENDERED_ATTRIBUTE), true));
        if (!rendered) {
            // dont render content
            page.setRendered(false);
            continue;
        }
        if (writer != null) {
            // encode Tab
            boolean disabled = ObjectUtils.getBoolean(TagEncodingHelper.getTagAttributeValue(page, "disabled"));
            writer.startElement(InputControl.HTML_TAG_TD, this);
            // tab label
            String styleClass = "eTabLabel";
            if (active) {
                styleClass += " eTabActive";
            } else if (disabled) {
                styleClass += " eTabDisabled";
            }
            writer.writeAttribute(InputControl.HTML_ATTR_CLASS, styleClass, null);
            // encode Link
            encodeTabLink(context, writer, index, page, (active || disabled));
            writer.endElement(InputControl.HTML_TAG_TD);
        }
        // set rendered
        page.setRendered(active);
        // next
        index++;
    }
}
Also used : HtmlCommandLink(javax.faces.component.html.HtmlCommandLink) UIComponent(javax.faces.component.UIComponent)

Example 5 with HtmlCommandLink

use of javax.faces.component.html.HtmlCommandLink in project gdmatrix by gdmatrix.

the class QueryInstanceBean method addExpressionList.

private void addExpressionList(FacesContext context, HtmlPanelGroup subPanelGroup) {
    id++;
    HtmlDataList dataList = new HtmlDataList();
    dataList.setId("data_list_" + id);
    dataList.setVar("expression");
    dataList.setLayout("unorderedList");
    dataList.setStyleClass("data_list");
    ArrayList list = new ArrayList();
    list.add(OPERATOR_PREFIX + Operator.AND);
    list.add(OPERATOR_PREFIX + Operator.OR);
    list.add(OPERATOR_PREFIX + Operator.NOR);
    List<Query.Predicate> predicates = getQuery().getPredicates();
    for (Query.Predicate predicate : predicates) {
        list.add(predicate.getName());
    }
    dataList.setValue(list);
    subPanelGroup.getChildren().add(dataList);
    id++;
    HtmlCommandLink link = new HtmlCommandLink();
    link.setId("expr_link_" + id);
    Application application = context.getApplication();
    MethodBinding method = application.createMethodBinding("#{queryInstanceBean.addExpression}", new Class[0]);
    link.setAction(method);
    ValueBinding valueBinding = application.createValueBinding("#{queryInstanceBean.expressionLabel}");
    link.setValueBinding("value", valueBinding);
    link.setStyleClass("expr_option");
    dataList.getChildren().add(link);
    id++;
    HtmlCommandButton cancelButton = new HtmlCommandButton();
    cancelButton.setId("cancel_link_" + id);
    method = context.getApplication().createMethodBinding("#{queryInstanceBean.cancel}", new Class[0]);
    cancelButton.setAction(method);
    valueBinding = application.createValueBinding("#{objectBundle.cancel}");
    cancelButton.setValueBinding("value", valueBinding);
    cancelButton.setStyleClass("big_button");
    subPanelGroup.getChildren().add(cancelButton);
}
Also used : Query(org.santfeliu.misc.query.Query) HtmlDataList(org.apache.myfaces.custom.datalist.HtmlDataList) HtmlCommandLink(javax.faces.component.html.HtmlCommandLink) ValueBinding(javax.faces.el.ValueBinding) ArrayList(java.util.ArrayList) MethodBinding(javax.faces.el.MethodBinding) HtmlCommandButton(javax.faces.component.html.HtmlCommandButton) Application(javax.faces.application.Application) Predicate(org.santfeliu.misc.query.QueryInstance.Predicate)

Aggregations

HtmlCommandLink (javax.faces.component.html.HtmlCommandLink)5 UIComponent (javax.faces.component.UIComponent)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FacesException (javax.faces.FacesException)1 Application (javax.faces.application.Application)1 EditableValueHolder (javax.faces.component.EditableValueHolder)1 UISelectMany (javax.faces.component.UISelectMany)1 ValueHolder (javax.faces.component.ValueHolder)1 HtmlCommandButton (javax.faces.component.html.HtmlCommandButton)1 HtmlGraphicImage (javax.faces.component.html.HtmlGraphicImage)1 Converter (javax.faces.convert.Converter)1 MethodBinding (javax.faces.el.MethodBinding)1 ValueBinding (javax.faces.el.ValueBinding)1 HtmlDataList (org.apache.myfaces.custom.datalist.HtmlDataList)1 CellEditor (org.primefaces.component.celleditor.CellEditor)1 OverlayPanel (org.primefaces.component.overlaypanel.OverlayPanel)1 Query (org.santfeliu.misc.query.Query)1 Predicate (org.santfeliu.misc.query.QueryInstance.Predicate)1