DynamicResource

You are viewing an old version (v. 6) of this page.
The latest version is v. 10, last edited on Dec 11, 2018 (view differences | )
<< View previous version | view page history | view next version >>

Overview

The ace:dynamicResource component serves JSF resources created by custom implementations of javax.faces.application.Resource, allowing for greater control and flexibility.

See the ICEfaces Showcase Live Demo of this component, complete with source code.

Getting Started

To use the DynamicResource component, it is necessary to first make a custom implementation of javax.faces.application.Resource, as the basic example below. The implementation can modify the behaviour of the Resource in any way to better suit the purposes of the application.

    public class MyResource extends Resource implements java.io.Serializable {

        private String path = "";
        private HashMap<String, String> headers;
        private byte[] bytes;
        
        public MyResource(byte[] bytes) {
            this.bytes = bytes;
            this.headers = new HashMap<String, String>();
        }
        
        public InputStream getInputStream() {
            return new ByteArrayInputStream(this.bytes);
        }

        public String getRequestPath() {
            return path;
        }
        
        public void setRequestPath(String path) {
            this.path = path;
        }

        public Map<String, String> getResponseHeaders() {
            return headers;
        }

        public URL  getURL() {
            return null;
        }

        public boolean userAgentNeedsUpdate(FacesContext context) {
            return false;
        }
    }

Once this is done and an instance is initialized, the component is added to the page, specifying this Resource instance, as well as other attributes that specify the way the resource is delivered.

<ace:dynamicResource id="dynamicResource"
	resource="#{bean.resource}" 
	type="link"
	label="Download resource" 
	attachment="true"
	fileName="MyCustomFileName.pdf"  />

Attributes

TagLib Documentation
This section covers attributes involved in the typical use-cases for this component. For reference, the complete taglib documentation for this component is available here.

The resource attribute references the instance of the Resource object to serve.

The type attribute specifies if a link, image, or button is displayed to the user to activate and download the resource.

The label attribute specifies the label of the link or button when the resource is presented in these ways.

The attachment flag indicates whether the resource should be downloaded as an attachment, in order to force the browser to save the resource instead of trying to open it.

The fileName attribute specifies the name used to save this file as, when downloading it as an attachment.

Event Listeners

None.

Client Behavior Events

None.

JavaScript API

None.

Keyboard Support

None.

CSS Classes

This component doesn't use any default CSS class names. The custom class names and styling specified in styleClass and style are applied on the a or input element, depending on the value of the type attribute.

Known Issues

None.

Additional Resources

Tutorials

This component appears in the following ICEfaces tutorials:

None

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

© Copyright 2017 ICEsoft Technologies Canada Corp.