Embedded
component is intended for displaying images and embedding optional web pages into the screen.
XML name of the component: embedded
The component is implemented for Web Client and Desktop Client. Desktop Client supports image display only.
Below is an example of using the component to display an image from a file located in FileStorage.
-
Declare the component in an XML screen descriptor:
<groupBox caption="Embedded" spacing="true" height="250px" width="250px" expand="embedded"> <embedded id="embedded" width="100%" align="MIDDLE_CENTER"/> </groupBox>
-
In a screen controller, inject the component itself, and the
FileStorageService
interface. Ininit()
method, get theFileDescriptor
passed from the calling code, upload the corresponding file as a byte array, create aByteArrayInputStream
for it, and pass it to thesetSource()
method of the component:@Inject private Embedded embedded; @Inject private FileStorageService fileStorageService; @Override public void init(Map<String, Object> params) { FileDescriptor imageFile = (FileDescriptor) params.get("imageFile"); byte[] bytes = null; if (imageFile != null) { try { bytes = fileStorageService.loadFile(imageFile); } catch (FileStorageException e) { showNotification("Unable to load image file", NotificationType.HUMANIZED); } } if (bytes != null) { embedded.setSource(imageFile.getName(), new ByteArrayInputStream(bytes)); embedded.setType(Embedded.Type.IMAGE); } else { embedded.setVisible(false); } }
Web Client allows image output from any files available to the Web Client block. Define the resource files directory in cuba.web.resourcesRoot application property, and specify the name of the file inside this directory for the Embedded
component
embedded.setSource("my-logo.png")
Pass the URL to the component to embed an external web page into the screen:
try { embedded.setSource(new URL("http://www.cuba-platform.com")); } catch (MalformedURLException e) { throw new RuntimeException(e); }
embedded
attributes: