Interview: Farrukh Ijaz on the Vroom Web Framework
Can you run us through a step-by-step quick start?
Firstly, I assume that you already have installed NetBeans plugin for Vroom Framework. If not then download it from Project Website, decompress the zip file and install the .nbm file using Downloaded Tab under Tools/Plugins menu of NetBeans 6.1 IDE.
As we go through the steps below, click the images to enlarge them as needed.
Step 1: Create a new web project named "VroomDemo":
Step 2: In the frameworks panel, Check Vroom Framework and click Finish:
Step
3: The project will be setup to use the framework. To check that,
simply run the application and you should see the following in the browser:
Now that we have a very basic application, what do we do next?
Step 1: Create a new JSP page named "register.jsp". The page should look like as follows:
If
you notice, firstName and lastName are input tags of type "text" and
nationality is select tag. For gender there is no control but a simple
span with id "divGender". Don't worry this span will contain gender
values as radio buttons.
Step 2: Create a Java class named "RegisterBean" under "com.myco.bean" package and add the following code:
The
above Java class contains "firstName", "lastName", "nationality" and "gender"
properties. There is a method named "register", we'll bind this method
with the form in the configuration file.
Step 3: Create a JSP named "confirmation.jsp". The page contents should look like as follow:
Once the registration is successful, the user will be redirected to this page.
Step 4: Create a Java class named "LookupBean" under "com.myco.bean" package and place the following code:
The purpose of LookupBean is to provide list of values e.g. nationalities and genders.
Step 5: Open "vroom-config.xml" file by right-clicking on the file and select
Open. Delete all existing webpage definitions and defining one for
"register.jsp" as follows:
Use Ctrl+Space to initiate Code Completion. The plugin will automatically detect the web pages available in the web module.
Step 6: Select "RegsiterBean" as bean-class, "rb" as var and "session" as scope:

Step 7: Define the object element for webpage and select document for the name attribute:
Step 8: Define the event element for the object and select "onload" for type and "LookupBean" for the bean-class attribute:

Step 9: Define the call element for the event and select "script" for the type attribute:
You
should select "script" for a call type if you want to execute a script.
For updating the contents/properties of the webpage elements, you
should select "update".
Step 10: Place the cursor between
the opening and closing call tag ( <call type="script"> </call>
) and press Ctrl+F1 or Right+Click and select Edit to invoke the JavaScript Editor:
Step 11: Write the following code in the JavaScript Editor:
The "VroomUtils"
class provide some utility functions that are very helpful to
manipulate HTML DOM objects. populateSelect() takes two arguments,
select name and the json string. The json string must be an array or
list of a bean having "label" and "value" properties. For custom
properties, you may use populateSelectEx() which takes four arguments.
First two are the select name and json string, the third and fourth are
the label and value property name. E.g.
- VroomUtils.populateSelect('nationality', '#{nationalities}'); // assumes the json string is an array of beans having label and value property names.
- VroomUtils.populateSelectEx('nationality', '#{nationalities}', 'name', 'id'); // where the bean contains name and id as properties.
- generateRadioGroup() takes four arguments, the first argument is the div or span id which will contain the radio buttons, the second argument is the name that is assigned to the generated radio buttons. Third argument is the json string which I just explained above and fourth is the no of columns. Since I've two values for gender and I want them to appear on the same line, I've passed 2 as argument value.
For details of the functions you may look into
the Vroom-2.1.4.pdf document available as a download or the Vroom
Framework article avaliable at http://en.wikipedia.org/wiki/Vroom_Framework.
Step 12: Update the event element defined for document object and add var, scope and method attributes as follows:
If
the bean-class has any property available with getter method, the code
completion will show "getProperties" in the completion items. It is
helpful if you want to access multiple properties by name in a single
call. If you select "getNationalities" as method then you won't be able
to get "genders" in the same call and instead of using
#{nationalities.array} you'll simply type #{array}.
Step 13: Define form element for webpage and select "frmRegister" as form id. This is defined in the register.jsp:
Step 14: Complete the form element by defining bean-class, var, scope and method attributes:
For method attribute, select "register" in the list. This will bind the form with "register" method of the RegisterBean class.
Step
15: Define navigation elements for form. For outcome "success" the url
should be "/confirmation.jsp" and for outcome "failure" it should be
the same page i.e. "/register.jsp" with forward attribute set to
"true". The forward attribute is very important to preserve the
information user entered previously.

Step
16: Define the elements which you want to post when the framework
invokes "register" method. The framework automatically populates the
fields of the bean-class. If the fields do not belong to the same bean
class which is used for form, you may define fine grained definition by
defining bean-class, var, scope at the element level. E.g. <element
id="firstName" bean-class="com.myco.bean.SomeOtherBean" var="sob"
scope="session"/>
How do we finish off this Vroom application?
Step
1: Compile and run the web application and type
"http://localhost:port/VroomDemo/register.jsp" url. Replace the port
with the port no. of your tomcat server. You'll see the following
webpage:
Note
that the divGender span tag contains "radio" buttons to select gender.
These are dynamically generated as a result of generateRadioGroup()
method of VroomUtils javascript class.
Step 2: Type the first
name, select nationality and gender and click submit. The server will
display the same webpage populating the fields you entered.
Observe the url in the browser. This is because the response has been forwarded.
Step 3: Enter the last name as well and submit the form, you'll get the "confirmation.jsp" webpage:
It also provides look and feel support?
Yes. Let's see below how we can
play with the look and feel of the web pages using call element:
Define stylesheet element for the webpage as follows:
Observe
that I've added another call element of type "update" for document
object, for which I've selected "frmRegister" as id of the element for
which I want to update the contents/properties, "className" as
attribute and "form" as value. This form is defined as .form in the
stylesheet element of the webpage.
Run the application and see the difference:
| Attachment | Size |
|---|---|
| figure-1.jpg | 4.27 KB |
| figure-2.png | 167.25 KB |
- Login or register to post comments
- 2371 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)









