--
PedroRio - 18 Feb 2011
XEO Web Components - Samples.
This section has snippets of code to perform a certain operation (and explanation of the snippet)
Opening a new viewer
A fairly common operation will be opening a viewer in response to a user clicking a button or something similar. To do so, in the bean method where you want to open the viewer use the following code:
XML Definition
<xvw:menu text='Open Tab' target='tab' serverAction='#{viewBean.openTab}'>
Java Code
public void openTab(){
//Create a XUIViewRoot representing the viewer (viewer can be located in the source code, or in the webapp of the application)
XUIViewRoot viewRoot = getSessionContext().createChildView("viewers/path/to/viewer/Viewer.xvw");
//Set the newly created viewroot as the view root of the request
getRequestContext().setViewRoot(viewRoot);
//Render the response
getRequestContext().renderResponse();
}
_
Opening a new viewer (in a window)
Sometimes you'll want to open a viewer inside a small window (and not in a new tab). To do that you must add the xvw:window component to your viewer, and execute the same code as the previous example.
Viewer Definition
<xvw:viewer beanClass="org.xeoframework.examples.MyBean" beanId="viewBean">
<xeo:formEdit>
<xvw:window width='500' height='300'>
<!-- Remaining components -->
</xvw:window>
</xeo:formEdit>
</xvw:viewer>
Menu (important, notice the absence of the "target" property, which defaults to "self")
<xvw:menu text='Open Window' serverAction='#{viewBean.openWindow}'>
Java Code (same code as above, only change needed to be done for this example is adding the xvw:window component and removing the target property)
XUIViewRoot viewRoot = getSessionContext().createChildView("viewers/Objecto/MyViewer.xvw");
getRequestContext().setViewRoot(viewRoot);
getRequestContext().renderResponse();
_
Finding the selected line in a panel (gridpanel, list, bridge)
A popular programming task with XEO Web Components is to have a gridPanel component (or list/bridge) and have toolbar with a button that will trigger some action on a selected line from the panel. To do that you need the following code in the method invoked by the button.
Required
public void processLine(){
//Find the GridPanel that has the selected line
GridPanel panel = (GridPanel) getViewRoot().findComponent(GridPanel.class);
//Retrieve the current active row (a DataRecordConnecor)
DataRecordConnector currentLine = panel.getActiveRow();
//Find the column that has a meaningful value (i.e. and id, for example)
DataFieldConnector currentColumn = currentLine.getAttribute("BOUI");
//Retrieve the value for that column
String value = currentColumn.getValue().toString();
//Use the value of the BOUI to load and process the instance
try {
XEOApplication app = XEOApplication.getDefaultApplication();
boObject b = app.getSecureObjectManager().
loadObject(getEboContext(), Long.valueOf(value));
//Process the instance
b.update();
} catch (boRuntimeException e) { /* Log or deal with the exception*/}
}
You may need a few modifications if:
- You have more than one instance of a gridPanel/list/bridge component in your viewer
- If you allow multiple lines to be selected and want to process them all
If you fall in situation 1, you'll need to do the following:
- Add an identifier to your form component (in the viewer)
- Add an identifier to your gridPanel/list/bridge
- Use a different find component method
Changing the current active tab
aaa
Refreshing a list after closing a tab
Component Plugins?