Creating a Struts-Dojo Project in IBM RSA 7.0

Hope someday I could publish my experiments with Dojo .And this is the day.

Using IBM RSA 7.0

1.Create  a new dynamic web project with Struts support

2.Add dojo toolkit to project

Dojo toolkit can be obtained from:http://download.dojotoolkit.org/release-1.1.1/dojo-release-1.1.1.tar.gz

Details about Adding explained using screenshot

That means its included in the Webcontent. You can see tons of warning messages caused by silly test html pages inside the toolkit folder,just search around and delete the stuff. Basically it has nothing to do with a struts controller or so.But I just tried using jsp pages,instead of html just to check if we can include toolkit with no problems in the jsp page.

Things to notice.

.Struts link the property of element in the form with form bean.

Like:

<html:text property=”beanprop”></html:text>

Here beanprop is one property in the  form bean.

Here after succesfully deploying the code will be like

<input type=”text” name=”beanprop” size=”20″>    in the html file we are viewing.

Now getting into details:

My JSP page:index.jsp  >> Index.jsp

Here instead of putting property attribute in the text field element ,i have used name because if you are using property here in this jsp page ,your dojo parser wont recognise the tag and the purpose for introducing dojo is defeated.

So our aim is to:

1.retain the dojo functionality

2.Obtain the value from page to formBean

My widget is specified like:

<input type=”text” id=”use” name=”username” size=”30″
dojoType=”dijit.form.ValidationTextBox”
required=”true”
promptMessage=”Enter username”
invalidMessage=”Username is required.”
onchange=”user()”
/>

Here look at the name attribute its username,which is same as my bean property :) and your problem  is solved.The tag itself is self explainatory:

dojoType=”dijit.form.ValidationTextBox” <<Causes dojo parser to recognise it as a ValidationTextbox having validation features included to normal textbox

required=”true” specifies whether field is required( Hurray!U guessed;It helps the parser to recognise whether validation is enabled).(But that alone is not sufficient(We have to specify a regExpression or rule to accept the textbox value)

promptMessage=”Enter username” is the prompting message on clicking the form element it will be visible

invalidMessage=”user()” causes a javascript function user() to be called when text changes in text field.

So inorder to make this all happen,we have to include

<script type=”text/javascript”
src=”dojo-release-1.1.1/dojo/dojo.js”
djConfig=”parseOnLoad: true”></script>
<script type=”text/javascript”>
dojo.require(“dojo.parser”);
dojo.require(“dijit.form.ValidationTextBox”);
</script>

inside your header

Tells dojoParser to load on document load and  parse the html before display

and dojo.require(“dijit.form.ValidationTextBox”) tells parser that  dijit.form.ValidationTextBox is used in the page here,index.html

Output screen

Look at the prompt

Look at the prompt

Now if you have skipped the field this will be the result (beware)

This is the error prompt

This is the error prompt

Advertisement

One Response to Creating a Struts-Dojo Project in IBM RSA 7.0

  1. yugin says:

    Mallu try to include some screen shots! It’ll be really helpful.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.