TWiki
>
WebXEO Web
>
XeoPrimer
>
XeoPrimerWebComponentsAPI
(revision 4) (raw view)
Edit
Attach
Tags:
tag this topic
create new tag
,
view all tags
-- Main.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* <pre><verbatim><xvw:menu text='Open Tab' target='tab' serverAction='#{viewBean.openTab}'></verbatim> </pre> *Java Code* <verbatim>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(); }</verbatim> _ ---++++++ 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* <verbatim><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></verbatim> *Menu (important, notice the absence of the "target" property, which defaults to "self")* <pre><verbatim><xvw:menu text='Open Window' serverAction='#{viewBean.openWindow}'> </verbatim> </pre> <strong>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)<br /></strong> <verbatim>XUIViewRoot viewRoot = getSessionContext().createChildView("viewers/Objecto/MyViewer.xvw"); getRequestContext().setViewRoot(viewRoot); getRequestContext().renderResponse();</verbatim> _ ---++++++ 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: <verbatim>XUIComponentBase myComp = getViewRoot().findComponent(TreePanel.class); TreePanel panel = (TreePanel) myComp; if (panel != null){ // Do normal processing }</verbatim> You could also just use: <verbatim>TreePanel panel = (TreePanel) getViewRoot().findComponent(TreePanel.class);</verbatim> 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. <verbatim>//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*/} }</verbatim> You may need a few modifications if: 1 You have more than one instance of a gridPanel/list/bridge component in your viewer 1 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
|
P
rint version
|
H
istory
:
r9
|
r6
<
r5
<
r4
<
r3
|
B
acklinks
|
V
iew topic
|
Raw edit
|
More topic actions...
Topic revision: r4 - 2011-02-21
-
PedroRio
WebXEO
XEO Primer
-
Instalation
-
Introduction
-
Concepts
-
Architecture
-
XEO Library
-
Deploy to EAR
-
PreferenceStore
XEO - Core
-
XEO Model Reference
-
Security
-
Java API
-
BOL
-
XEOQL (BOQL)
-
Administrating
-
Background Tasks
-
boConfig.xml
-
Web.xml
-
Known Issues
-
XEO Flags
XEO - XWC
- Web Components
- Java Samples
- Custom Components
- Component Plugins
- Internationalization
- Viewer Events
- Value Change Listeners
- XUIServlet
- XeoLocalization
- XvwTemplates
Create New Topic
WebXEO Web
No permission to view
TWiki.WebTopBar
No permission to view
TWiki.WebBottomBar