Search in sources :

Example 1 with HtmlGraphicImage

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

the class GalleryWidgetBuilder method getComponent.

@Override
public UIComponent getComponent(WidgetDefinition widgetDef, FacesContext context) {
    Div containerDiv = new Div();
    Map properties = widgetDef.getProperties();
    if (properties != null) {
        String widgetId = widgetDef.getWidgetId();
        String caseId = (String) properties.get("caseId");
        String galleryMid = (String) properties.get("galleryMid");
        String imageWidth = (String) properties.get("imageWidth");
        String imageHeight = (String) properties.get("imageHeight");
        String galleryStyle = (String) properties.get("galleryStyle");
        String galleryStyleClass = (String) properties.get("galleryStyleClass");
        if (galleryStyleClass == null)
            galleryStyleClass = "gallery";
        String imagesPerPage = (String) properties.get("imagesPerPage");
        int pageSize = (imagesPerPage != null ? Integer.parseInt(imagesPerPage) : 9);
        try {
            containerDiv.setStyle(galleryStyle);
            containerDiv.setStyleClass(galleryStyleClass);
            Div dataListDiv = new Div();
            dataListDiv.setId(widgetId + "_dataListDiv");
            HtmlDataList dataList = new HtmlDataList();
            dataList.setId(widgetId + "_dataList");
            dataListDiv.getChildren().add(dataList);
            // Data list div
            String sortValue = (String) properties.get("sortImages");
            boolean sort = (sortValue == null ? true : sortValue.equals("true"));
            List<GalleryItem> items = GalleryBean.getGalleryItems(galleryMid, caseId, imageWidth, imageHeight, 0, 0, sort);
            List<GalleryItem> itemsAux = new ArrayList<GalleryItem>();
            itemsAux.addAll((List<GalleryItem>) items.subList(0, pageSize >= items.size() ? items.size() : pageSize));
            dataList.setValue(itemsAux);
            dataList.setVar("item");
            HtmlOutputLink outputLink = new HtmlOutputLink();
            outputLink.setId(widgetId + "_action");
            UIComponentTagUtils.setValueBinding(context, outputLink, "value", "#{item.actionUrl}");
            outputLink.setStyleClass("thumbnail");
            HtmlGraphicImage graphicImage = new HtmlGraphicImage();
            UIComponentTagUtils.setValueBinding(context, graphicImage, "url", "#{item.thumbnailUrl}");
            graphicImage.setId(widgetId + "_image");
            // graphicImage.setTitle(caseId);
            UIComponentTagUtils.setValueBinding(context, graphicImage, "title", "#{galleryBean.itemDescription}");
            UIComponentTagUtils.setValueBinding(context, graphicImage, "alt", "#{galleryBean.itemDescription}");
            outputLink.getChildren().add(graphicImage);
            dataList.getChildren().add(outputLink);
            containerDiv.getChildren().add(dataListDiv);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return containerDiv;
}
Also used : Div(org.apache.myfaces.custom.div.Div) HtmlDataList(org.apache.myfaces.custom.datalist.HtmlDataList) HtmlGraphicImage(javax.faces.component.html.HtmlGraphicImage) ArrayList(java.util.ArrayList) HtmlOutputLink(javax.faces.component.html.HtmlOutputLink) GalleryItem(org.santfeliu.misc.gallery.web.GalleryItem) Map(java.util.Map)

Example 2 with HtmlGraphicImage

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

the class LinkTag method encodeImage.

protected HtmlGraphicImage encodeImage(FacesContext context, HtmlOutcomeTargetLink parent, String imagePath) {
    HtmlGraphicImage img = InputControlManager.createComponent(context, HtmlGraphicImage.class);
    img.setValue(imagePath);
    return img;
}
Also used : HtmlGraphicImage(javax.faces.component.html.HtmlGraphicImage)

Example 3 with HtmlGraphicImage

use of javax.faces.component.html.HtmlGraphicImage 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 4 with HtmlGraphicImage

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

the class LinkTag method encodeBegin.

@Override
public void encodeBegin(FacesContext context) throws IOException {
    // add label and input components when the view is loaded for the first time
    super.encodeBegin(context);
    // begin
    helper.encodeBegin();
    if (isLinkDisabled()) {
        // render disabled
        ResponseWriter writer = context.getResponseWriter();
        Object linkValue = getLinkValue(helper.hasColumn());
        this.disabledTagName = writeStartElement(writer);
        this.encodeLinkChildren = isEncodeLinkChildren(linkValue);
        if (!encodeLinkChildren) {
            writer.write(StringUtils.toString(linkValue, ""));
            writer.endElement(this.disabledTagName);
        }
    } else {
        // Add component
        HtmlOutcomeTargetLink linkComponent = null;
        if (getChildCount() > 0) {
            UIComponent c = getChildren().get(0);
            if (c instanceof HtmlOutcomeTargetLink) {
                // reuse
                linkComponent = (HtmlOutcomeTargetLink) c;
                helper.restoreComponentId(linkComponent);
                // check image
                if (linkComponent.getChildCount() > 0) {
                    // Check HtmlGraphicImage
                    int last = linkComponent.getChildCount() - 1;
                    UIComponent lcc = linkComponent.getChildren().get(last);
                    if (lcc instanceof HtmlGraphicImage)
                        helper.restoreComponentId(lcc);
                }
            } else {
                // Something's wrong here?
                log.info("INFO: Unexpected child node for {}! Child item type is {}.", getClass().getName(), c.getClass().getName());
                // Check facetComponent
                UIPanel facetComponent = (UIPanel) getFacets().get(UIComponent.COMPOSITE_FACET_NAME);
                if (facetComponent == null) {
                    log.warn("WARN: component's facetComponent has not been set! Using Default (javax.faces.Panel).");
                    log.warn("Problem might be related to Mojarra's state context saving for dynamic components (affects all versions > 2.1.6). See com.sun.faces.context.StateContext.java:AddRemoveListener");
                    facetComponent = (UIPanel) context.getApplication().createComponent("javax.faces.Panel");
                    facetComponent.setRendererType("javax.faces.Group");
                    getFacets().put(UIComponent.COMPOSITE_FACET_NAME, facetComponent);
                }
            }
        }
        if (linkComponent == null) {
            try {
                creatingComponents = true;
                linkComponent = createOutcomeTargetLink(context);
                this.getChildren().add(0, linkComponent);
                helper.saveComponentId(linkComponent);
                // encode image
                String imagePath = helper.getTagAttributeString("image");
                if (StringUtils.isNotEmpty(imagePath)) {
                    // Create image
                    HtmlGraphicImage img = encodeImage(context, linkComponent, imagePath);
                    linkComponent.getChildren().add(img);
                    helper.saveComponentId(linkComponent);
                }
            // done
            } finally {
                creatingComponents = false;
            }
        }
        // set params
        setLinkProperties(linkComponent);
        addOrSetParam(linkComponent, "idparam", "id");
        // encode link
        this.encodeLinkChildren = isEncodeLinkChildren(linkComponent.getChildCount() > 0 ? null : linkComponent.getValue());
        if (this.encodeLinkChildren)
            linkComponent.encodeBegin(context);
        else {
            // default rendering (no children)
            linkComponent.setRendered(true);
            linkComponent.encodeAll(context);
            // Don't render twice!
            linkComponent.setRendered(false);
        }
    }
}
Also used : StringResponseWriter(org.apache.empire.jsf2.utils.StringResponseWriter) ResponseWriter(javax.faces.context.ResponseWriter) HtmlOutcomeTargetLink(javax.faces.component.html.HtmlOutcomeTargetLink) HtmlGraphicImage(javax.faces.component.html.HtmlGraphicImage) UIComponent(javax.faces.component.UIComponent) UIPanel(javax.faces.component.UIPanel)

Aggregations

HtmlGraphicImage (javax.faces.component.html.HtmlGraphicImage)4 UIComponent (javax.faces.component.UIComponent)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 FacesException (javax.faces.FacesException)1 EditableValueHolder (javax.faces.component.EditableValueHolder)1 UIPanel (javax.faces.component.UIPanel)1 UISelectMany (javax.faces.component.UISelectMany)1 ValueHolder (javax.faces.component.ValueHolder)1 HtmlCommandLink (javax.faces.component.html.HtmlCommandLink)1 HtmlOutcomeTargetLink (javax.faces.component.html.HtmlOutcomeTargetLink)1 HtmlOutputLink (javax.faces.component.html.HtmlOutputLink)1 ResponseWriter (javax.faces.context.ResponseWriter)1 Converter (javax.faces.convert.Converter)1 StringResponseWriter (org.apache.empire.jsf2.utils.StringResponseWriter)1 HtmlDataList (org.apache.myfaces.custom.datalist.HtmlDataList)1 Div (org.apache.myfaces.custom.div.Div)1 CellEditor (org.primefaces.component.celleditor.CellEditor)1 OverlayPanel (org.primefaces.component.overlaypanel.OverlayPanel)1