OverviewSince 4.0 The ace:dynamicResource component serves JSF resources created by custom implementations of javax.faces.application.Resource, allowing for greater control and flexibility.
Getting StartedTo 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
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 ListenersNone. Client Behavior EventsNone. JavaScript APINot applicable. Keyboard SupportNone. CSS ClassesThis 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 IssuesNone. Additional ResourcesTutorialsThis component appears in the following ICEfaces tutorials: None |
DynamicResource
© Copyright 2021 ICEsoft Technologies Canada Corp.