How to Add the Ability to Insert Text into a richTextEditor Component

9-36 Web User Interface Developers Guide for Oracle Application Development Framework Figure 9–34 inputFile Component Once a file has been uploaded, and so the value of the inputFile is not null either after the initial load is successful or it has been specified as an initial value, you can create an Update button that will be displayed instead of the Browse button, as shown in Figure 9–35 . This will allow the user to modify the value of the inputFile component. Figure 9–35 inputFile Component in Update Mode You can also specify that the component be able to load only a specific file by setting the readOnly property to true, In this mode, only the specified file can be loaded, as shown in Figure 9–36 . Figure 9–36 inputFile Component in Read-Only Mode For security reasons, the following attributes cannot be set from the client: ■ disabled unless the unsecure property is set. For more information, see Section 3.6.2, How to Unsecure the disabled Property. ■ immediate ■ readOnly ■ requiredMessageDetail ■ value The inputFile component can be placed in either an h:form tag or an af:form tag, but in either case, you have to set the form tag to support file upload. If you use the JSF basic HTML h:form, set the enctype to multipartform-data. This would make the request into a multipart request to support file uploading to the server. If you are using the ADF Faces af:form tag, set usesUpload to true, which performs the same function as setting enctype to multipartform-data to support file upload. The rich client framework performs a generic upload of the file. You should create an actionListener or action method to process the file after it has been uploaded for example, processing xml files, pdf files, and so on. The value of an inputFile component is an instance of the org.apache.myfaces.trinidad.model.UploadedFile interface. The API lets you get at the actual byte stream of the file, as well as the files name, its MIME type, and its size. The uploaded file may be stored as a file in the file system, but may also be stored in memory; the API hides that difference. The filter ensures that the UploadedFile content is cleaned up after the request is complete. Because of this, you cannot usefully Note: The API does not allow you to get path information from the client about from where the file was uploaded. Using Input Components and Defining Forms 9-37 cache UploadedFile objects across requests. If you need to keep the file, you must copy it into persistent storage before the request finishes. For example, instead of storing the file, add a message stating the file upload was successful using a managed bean as a response to the ValueChangeEvent event, as shown in Example 9–10 . Example 9–10 Using valueChangeListener to Display Upload Message JSF Page Code ----- af:form usesUpload=true af:inputFile label=Upload: valueChangeListener={managedBean.fileUploaded} af:commandButton text=Begin af:form Managed Bean Code ---- import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import javax.faces.event.ValueChangeEvent; import org.apache.myfaces.trinidad.model.UploadedFile; public class ABackingBean { ... public void fileUploadedValueChangeEvent event { UploadedFile file = UploadedFile event.getNewValue; if file = null { FacesContext context = FacesContext.getCurrentInstance; FacesMessage message = new FacesMessage Successfully uploaded file + file.getFilename + + file.getLength + bytes; context.addMessageevent.getComponent.getClientIdcontext, message; Heres where we could call file.getInputStream } } } You can also handle the upload by binding the value directly to a managed bean, as shown in Example 9–11 . Example 9–11 Binding the Value to a Managed Bean JSF Page Code ---- af:form usesUpload=true af:inputFile label=Upload: value={managedBean.file} af:commandButton text=Begin action={managedBean.doUpload} af:form Managed Bean Code ---- import org.apache.myfaces.trinidad.model.UploadedFile; public class AManagedBean { public UploadedFile getFile { return _file; }