home
products
education
support
partners
company

articles

tutorials

screenshots


SourceForge.net Logo

home

forums

downloads

bugs

mailing list
Kalideoscope Zone - knowledge base

number of ratings 0
average rating 0.00

Passing parameters to pages

There are numerous ways of sharing data between pages within the XUI platform. Bindings can be used to persist data to the XModel structure which can be used throughout the application. Another method is to use library functions as outlined in a previous knowledge base article here

In this article we will be passing parameters to XPage objects with use of the setAttribute and getAttribute functions.

We'll start with creating the a start page called Welcome as shown in Listing 1

Listing 1 - The welcome page declaration


  
  

The class attribute of the page declaration shows that the net.xoetrope.pagetest.Welcome class is being used for the page and this class is shown in Listing 2.

Listing 2 - The Welcome XPage class

package net.xoetrope.pagetest;

import net.xoetrope.xui.*;
import net.xoetrope.swing.*;

public class Welcome extends XPage
{
  public void next()
  {
    XPage page = ( XPage )pageMgr.loadPage( "page2" );
    page.setAttribute( "param", null, getValue() );
    pageMgr.showPage( "page2" );
  }

  public String getValue()
  {
    XEdit testEdit = ( XEdit ) findComponent( "testEdit" );
    return testEdit.getText();
  }
  
}
                

The next function begins by calling the loadPage function of the XPageManager in order to load the page2 page. Next the setAttribute function of the XPage is called with the name param and with the value of the page text component. Finally the page2 XPage is shown by using the showPage function. The page2 declaration can be seen below in Listing 3

Listing 3 - The page2 XML declaration


  
  

The net.xoetrope.pagetest.Page2 class can be seen below in Listing 4

Listing 4 - The Page2 class

package net.xoetrope.pagetest;

import net.xoetrope.xui.*;
import net.xoetrope.swing.*;

public class Page2 extends XPage
{
  public void pageActivated()
  {
  XLabel testLabel = ( XLabel )findComponent( "testLabel" );
  testLabel.setText( ( String ) getAttribute( "param", null ) );
  }
  
  public void back()
  {
  pageMgr.showPrevious();
  }
  
}
                

The page2 class uses the pageActivated method of the XPage class in order to retrieve the parameter by using the getAttribute function.

Any Object can be passed between pages in this way. In order to illustrate this the page shown in Listing 5 sets up items in a Vector and passes it to another page.

Listing 5 - Passing a Vector Object to an XPage

  Vector vector;
  XEdit testEdit;
  
  public void pageCreated()
  {
  testEdit = ( XEdit ) findComponent( "testEdit" );
  vector = new Vector();
  }
  
  public void next()
  {
    XPage page = ( XPage )pageMgr.loadPage( "page2V" );
    page.setAttribute( "param", null, vector );
    pageMgr.showPage( "page2V" );
  }

  public void addItem()
  {
  vector.add( testEdit.getText() );
  testEdit.setText( "" );
  }             

And the Vector is retrieved and used as shown in Listing 6

Listing 6 - Retrieving and using the Vector

  public void pageActivated()
  {
  Vector vector = ( Vector ) getAttribute( "param", null );
  for ( int i = 0; i < vector.size(); i++ ) {
    System.out.println( vector.get( i ) );
  }
  }             

Files

You need to be logged in to download the files for this article

comments


If you were logged in you could rate this article or add a comment.