Products Downloads


French version


 

 

To manually create a list containing data from the Adelia Javabean :

 

1.   Create a blank new JSP page.

This page must have the ".jsp" extension. In our example, this page is called "listcust.jsp".

 

 

2.   Build the page in HTML only, placing a single row in the table that will be dynamically filled.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

This example gives a template for the future HTML-only list page. There is not yet any Java code to incorporate the JSP page.

The table contains two rows: the first is the header, with the second acting as a model, which will be dynamically repeated as necessary.

 

3.   Next, declare the Adelia JavaBean in the JSP page's source code.

N.B.: In the source code shown below, the lines that must be added are highlighted in yellow.

 

 

<TITLE> Customer list </TITLE>

<BODY>

 

<jsp:useBean class=" com.hardis.training.FLSTCL " id=" fLSTCL "></jsp:useBean>

 

<P align="center"><BR>

<IMG src="/images/banniereweb.gif" width="468" height="60" border="0"></P>

<HR width="70%" size="4" style="color : navy;">

 

 

In this example, the Adelia JavaBean is declared just after the <BODY> HTML tag; you must specify the exact class name (including the package) and the name of any variables.

Class name: FLSTCL

Package name: com.hardis.training

Variable name: fLSTCL

 

Important: JAVA language is case-sensitive.

 

4.   Declare the Adelia Web Pool manager: This tool is supplied in the Adelia Web runtime. It provides optimized communication between the Adelia JavaBean and the server part.

 

 

<TITLE>Customer list</TITLE>

<BODY>

 

<jsp:useBean class="com.hardis.training.FLSTCL" id="fLSTCL"></jsp:useBean>

 

<jsp:useBean class="com.hardis.adelia.pool.PoManager" id="Manager" scope="application"></jsp:useBean>

 

<%

Manager.refresh(fLSTCL);

%>

 

<P align="center"><BR>

<IMG src="/images/banniereweb.gif" width="468" height="60" border="0"></P>

<HR width="70%" size="4" style="color : navy;">

 

 

A second JavaBean declaration is placed in the source code, this time for the Adelia pool.

      • Use the same syntax as before, again specifying the class, package name and variable name (in this case "Manager"), plus an additional characteristic (scope="application").
      • Then insert the first Java instruction, which calls the components just declared.
      • The "Manager" object's "refresh" method is used to call the server part of the JavaBean set as a parameter (in our example, this method is applied to the "fLSTCL" object, the aim being to retrieve all the customer records and display them in a list.

 

 

5.    The next step is to build the dynamic table. The aim is to repeat the second row in the table (created statically in HTML) for each record in the CUSTOMER file. This is done by inserting the code shown below:

<%

Manager.refresh(fLSTCL);

%>

 

<P align="center"><BR>

<IMG src="/images/banniereweb.gif" width="468" height="60" border="0"></P>

<HR width="70%" size="4" style="color : navy;">

 

….

 

<%

   try {

// Retrieving the first element in the customer list

com.hardis.training.FLSTCL$StructLST_CUST _p0 =
fLSTCL.getLST_CUSTEnumeration(0);

%>

 

<TABLE border="0" width="70%">

   <TBODY>

       <TR>

<TD align="center" bgcolor="#cccc00" width="82"><B>Code</B></TD>

<TD align="center" bgcolor="#cccc00" width="157"><B>Name</B></TD>

<TD align="center" bgcolor="#cccc00" width="76"><B>Zip</B></TD>

<TD align="center" bgcolor="#cccc00" width="145"><B>City</B></TD>

       </TR>

 

<%

   // Loop on the number of elements in the list

   for (int _i0 = 0; ; ) {

   %>

 

<TR>

   <TD>

         <A href="detailcust.jsp?CODECLI=

                   <%= java.net.URLEncoder.encode(_p0.getCU_CUS_CODE()) %>

                  >

          <%= _p0.getCU_CUS_CODE() %>

         </A></TD>

   <TD> <%= _p0.getCU_CUS_NAME() %> </TD>

   <TD> <%= _p0.getCU_CUS_ZIP() %> </TD>

   <TD> <%= _p0.getCU_CUS_CITY() %> </TD>

</TR>

 

<%

          // Incrementing the counter and retrieving the next element

          _i0++;

          try {

                   _p0 = fLSTCL.getLST_CUSTEnumeration(_i0);

          }

          catch (java.lang.ArrayIndexOutOfBoundsException _e0) {

                   break;

          }

          }

%>

 

         </TBODY>

   </TABLE>

<%

}

catch (java.lang.ArrayIndexOutOfBoundsException _e0) { }

%>

 

 

This code creates a list page dynamically. By nesting the static HTML and the Java code, the table is populated using a "for" loop to build each row with a different customer's characteristics. Note that we have decided to include a hypertext link for each customer's code reference:

 

<A href="detailcust.jsp?CODECLI=

<%= java.net.URLEncoder.encode(_p0.getCU_CUS_CODE()) %>

>

<%= _p0.getCU_CUS_CODE() %>

</A>

 

Just keep the code that displays the property if you want to remove the hyperlink

(<%= _p0.getCU_CUS_CODE() %>).

 

↑ Top of page

  • Aucune étiquette