Tutorials : NetBeans Visual Web Pack: Learning by Example :

Implementing Your Drop Down List

Follow these steps to insert some Java code for implement the functionality of drop down list:
  • Double-click on the drop down list component (now you should see the cursor in the dropDown1_processValueChange method)
  • Paste this code into it:
           Object categoryId = dropDown1.getSelected();
           
           try {
               categoriesDataProvider.setCursorRow
    		   (categoriesDataProvider.
               findFirst("CATEGORIES.CATEGORYID", categoryId));
               getSessionBean1().getProductsRowSet().setObject(1, categoryId);
               productsDataProvider.refresh();
               form1.discardSubmittedValues("virtualProducts");
               } catch (Exception e) 
                   {
          error("You can't select the " + categoryId + " category!");
          log("You can't select the " + categoryId + " category!", e);
                   }        
    
  • Locate the prerender method (in the upper part of the window) and paste this code into it:
    if (dropDown1.getSelected() == null) 
              {
              Object firstCategoryId = null;
              try {
                  categoriesDataProvider.cursorFirst();
                  firstCategoryId =
    			   categoriesDataProvider.getValue
    			   ("CATEGORIES.CATEGORYID");
                  dropDown1.setSelected(firstCategoryId);
                  getSessionBean1().getProductsRowSet().setObject
    			  (1, firstCategoryId);
                  productsDataProvider.refresh();
                  } catch (Exception e) 
                     {
                     error
    	("You can't select the " + firstCategoryId + " category!");
                     log
    	("You can't select the " + firstCategoryId + " category!", e);
                     }
           }
    
Now, you should be able to run the application for the first time. Simply right-click on the project name in the Projects window and select the Run Project item (or, in the Run menu select Run Main Project item). Notice that the table displays the products from the first category. If you choose a different category, the table is automatically updated (see Figure 4).


Figure 4: Running the application.

Implementing insert

Following these steps:
  • Place four Label components on the scene. They should have the following characteristics:
    • Label 1: text: Product Name, Top: 120px, Left: 10px
    • Label 2: text: Product Code, Top: 120px, Left: 200px
    • Label 3: text: Product Price, Top: 120px, Left: 390px
    • Label 4: text: Product Image, Top: 120px, Left: 580px.
  • Place four Text Field components on the scene. They should have the following characteristics:
    • Text Field 1: Top: 140px, Left: 10px
    • Text Field 2: Top: 140px, Left: 200px
    • Text Field 3: Top: 140px, Left: 390px
    • Text Field 4: Top: 140px, Left: 580px, disabled true (this property is in the Properties window. Activate it by marking its checkbox).
  • Place a Button component on the scene. It should have the following characteristics:
    • Button: text: Add Product, Top: 264px, Left: 575px
  • From the Runtime window select the PRODUCTS table and drag it over the SessionBean1 from the Outline window (this will open the Add New Data Provider with RowSet for Table PRODUCTS window)
  • Mark the first Create radio button (SessionBean1::productsRowSet1) and type maximProductsRowSet1 into the corresponding text field. Click OK.
  • In the Outline window, select the maximProductsRowSet1 node, under the SessionBean node
  • Right-click on this node and select the Edit SQL Statement item from the popup menu.
  • Delete the current SQL statement and place this one instead:
    SELECT MAX(MYSTORE.PRODUCTS.PRODUCTID)+1 AS MAXPRODUCTID FROM MYSTORE.PRODUCTS
    
  • Close the window. An alert box will appear. Click Continue.
  • Now double-click the Add Product button. Insert the code found in Listing 1 in the button1_action method.
  • Right-click on the code and select the Fix imports item from the popup menu.
Home / Articles / NetBeans Visual Web Pack: Learning by Example / 1 / 2 / 3 / 4 / Next Page

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.