DynamicResource

compared with
Current by Arturo Zambrano
on Dec 11, 2018 15:19.


 
Key
These lines were removed. This word was removed.
These lines were added. This word was added.

View page history


There are 2 changes. View first change.

 h2. Overview
 _Since 4.0_
  
 The ace:dynamicResource component serves JSF resources created by custom implementations of javax.faces.application.Resource, allowing for greater control and flexibility.
  
 {tip}See the ICEfaces Showcase [Live Demo|http://icefaces-showcase.icesoft.org/showcase.jsf?grp=aceMenu&exp=dynamicResourceBean] of this component, complete with source code.{tip}
  
  
 h2. 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.
 {code:java}
  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;
  }
  }
 {code}
  
 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.
  
 {code:xml}
 <ace:dynamicResource id="dynamicResource"
  resource="#{bean.resource}"
  type="link"
  label="Download resource"
  attachment="true"
  fileName="MyCustomFileName.pdf" />
 {code}
  
 h2. Attributes
  
 {tip:title=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|http://res.icesoft.org/docs/v4_latest/ace/tld/ace/dynamicResource.html].{tip}
  
 {panel}
 The *resource* attribute references the instance of the Resource object to serve.
 {panel}
  
 {panel}
 The *type* attribute specifies if a {{link}}, {{image}}, or {{button}} is displayed to the user to activate and download the resource.
 {panel}
  
 {tip}Note that if you intend to produce a dynamic resourced based on some user input at the moment of clicking on this component, then you have to use the {{button}} type, in order to submit the form and process all input fields before generating and saving the resource, based on such input.{tip}
  
 {panel}
 The *label* attribute specifies the label of the link or button when the resource is presented in these ways.
 {panel}
  
 {panel}
 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.
 {panel}
  
 {panel}
 The *fileName* attribute specifies the name used to save this file as, when downloading it as an attachment.
 {panel}
  
 h2. Event Listeners
  
 None.
  
 h2. Client Behavior Events
  
 None.
  
 h2. JavaScript API
  
 Not applicable.
  
 h2. Keyboard Support
  
 None.
  
 h2. 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.
  
 h2. Known Issues
  
 None.
  
 h2. Additional Resources
  
 {panel}Note that if you intend to produce a dynamic resourced based on some user input at the moment of clicking on this component, then you have to use the {{button}} type, in order to submit the form and process all input fields before generating and saving the resource, based on such input.{panel}
  
  
 h4. Tutorials
  
 This component appears in the following ICEfaces tutorials:
  
 *None*

© Copyright 2021 ICEsoft Technologies Canada Corp.