Tags:
create new tag
, view all tags
-- 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 a component in the component tree

One regular task when implementing a method using the Java API in a bean is to find a given component and retrieve a certain property value, or changing a set of properties (as well as adding a new child to the component). In order to do that, you must be able to find the component in the component tree of a viewer. There are two ways of finding a component: By type and by identifier.

Find a component by type

In this situation, if you only have one instance of a given type/class, you can find the component by its class. If you were looking for a TreePanel component you could use the following code:

XUIComponentBase myComp = getViewRoot().findComponent(TreePanel.class);
TreePanel panel = (TreePanel) myComp;
if (panel != null){
    // Do normal processing
}

You could also just use:

TreePanel panel = (TreePanel) getViewRoot().findComponent(TreePanel.class);

Beware that you should only use the findComponent method with the class as parameter if you're certain there's only one instance of the component in the current viewer. If there are more than one, it's undefined which one will be returned by the method. If you have more than one instance of a given type/class of components you should see the following section.

Find a component by identifier

In case there's a

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.

//import netgest.bo.xwc.components.connectors.*;
//import netgest.bo.xwc.components.classic.GridPanel;

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:

  1. You have more than one instance of a gridPanel/list/bridge component in your viewer
  2. 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 findComponent method that takes the component identifier as a parameter

Add an identifier to your form component:

<xvw:form id='myForm'>

or

<xeo:formEdit id='myForm'>

Add an identifier to your panel

<xvw:gridPanel id='panel'>

or

<xeo:bridge id='panel'>

Then use the find component with

Changing the current active tab

aaa

Refreshing a list after closing a tab

Component Plugins?

Edit | Attach | Print version | History: r9 | r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r4 - 2011-02-21 - PedroRio
 

No permission to view TWiki.WebTopBar

This site is powered by the TWiki collaboration platform Powered by Perl

No permission to view TWiki.WebBottomBar