ATG Forms

ATG forms are similar to any typical form in web application and does the following:

  • Validating user input
  • Format of input
  • Handle form errors
  • Invoke Servlet / JSP
  • Pass information to persistent storage
  • Display nucleus properties in form elements
  • Assigning user input to properties of nucleus component
  • Interact directly with database.

ATG forms defined by <dsp:form> tag and typically contains one more input elements and one or more submit elements for form submission.

ATG forms must specify an action which is attribute of <dsp:form>.ATG forms can include other JSPs, however they must be complete pages and JSP fragments are not allowed.

ATG forms can assign value of input elements to properties of nucleus components during form submission. The input elements can be single values from form elements such as check box, text, text area, radio buttons, drop down lists (single selection) or multiple values such as grouped check boxes, multiple check boxes.

Similar to HTML forms ATG forms also assign values hidden elements.

ATG forms can have more than on submit options and you can use either button or image as your submit choice. The submit form element can also set property on a bean during submission specified in submitvalue attribute.

In ATG forms you can control the processing of form elements using priority of form elements. The submit and image elements have the lowest priority (default is 10).

Posted in Uncategorized | Leave a comment

Default thread group

Every thread in Java has a thread group. The default thread group is ‘main’.

public static void main(String[] args) {
  System.out.printf("ThreadGroup of main thread is: %s\n", Thread
.currentThread().getThreadGroup().getName());
}

Output of above code:
ThreadGroup of main thread is: main

If a thread ‘t’ is spawned from a main thread then the thread group of ‘t’ is ‘main’ as long as ‘t’ doesn’t belongs to another thread group.

public static void main(String[] args) {
  System.out.printf("ThreadGroup of main thread is: %s\n", Thread
.currentThread().getThreadGroup().getName());
  Thread t = new Thread(new WorkerTask());
  t.start();
}

Output of above code:
ThreadGroup of main thread is: main
ThreaGroup of spawned thread is: main

The following snippet showing a spawned thread can be part of a different thread group.

public static void main(String[] args) {
  System.out.printf("ThreadGroup of main thread is: %s\n", Thread
.currentThread().getThreadGroup().getName());
  ThreadGroup tg = new ThreadGroup("OtherThreadGroup");
  Thread t = new Thread(tg, new WorkerTask());
  t.start();
}

Output of above code:
ThreadGroup of main thread is: main
ThreaGroup of spawned thread is: OtherThreadGroup

Posted in Uncategorized | Tagged , , , | Leave a comment

Commonly commands in Git

Here are some of the commonly used in Git:

git status – displays modified files and staged files.
git commit – commits all staged files to current remote branch
git log – history of commits in the current branch
git show <commit-number> – displays commit information for a particular commit.
git show-branch – one line summary of current branch
git diff <commit-number1> <commit-number2> – difference of two commits
git mv old-file-name new-file-name – renames a file / directory, retains all commit history.
git clone <repository_name> <workspace_name> – makes a full copy of a repository

Posted in Uncategorized | Tagged , | Leave a comment

3n+1 path

While reading Programming Challenges I thought of implementing the path of 3n+1 for a given number. Here is my first stab in Java. I am not trying to solve the problem, however I thought it is interesting to print the sequence for a given number.

public class ThreeNPlusOne {

public static void main(String[] args) {

ThreeNPlusOne driver = new ThreeNPlusOne();
int counter = 0;
int i = 9;
while (i > 0) {
System.out.print(i + " ");
++counter;
if (i == 1)
break;
i = driver.getNextNumber(i);
}
System.out.println("\nMaxmimum cycle length: " +counter);
}

private boolean isEven(int n) {
return n % 2 == 0;
}

private int getNextNumber(int n) {

if (isEven(n)) {
return n / 2;
}
return (n * 3) + 1;
}
}

Posted in Uncategorized | Tagged , | Leave a comment

Ant war task

Many of us build war files as part of the project, however some projects stilll use jar and copy ant tasks to assemble war file. However ant has a built-in war task which takes care of web.xml, classes, libraries etc.,

Here is sample of ant war task.

<war destfile=”myapp.war” webxml=”myapp/web.xml”>

<classes dir=”myapp/classes” />

<lib dir=”myapp/lib”>

<exclude name=”whatever you need to exclude” />

</lib>

<fileset dir=”myapp/jsp” />

<fileset dir=”myapp/html” />

</war>

Posted in Uncategorized | Tagged | Leave a comment

Validation and erroror reporting in Struts 1.1

One of the benefits of using Struts framework is declarative validation mechanism and error reporting. Struts provides validation hook so that you can implement your own validation logic in action classes. The validation can be turned on/off in action mapping using validate property.

In action class you can override validate() and it’s signature is:

public  ActionErrors validate(ActionMapping mapping, HttpServletRequest request)

Typically you validate presentation related information such as missing text or wrong format etc., If a validation error occurred for an input field, you can create an ActionError class  with message key (for internationalization purposes ) and the name of the input field. In the JSP you can use Struts <html:errors /> tag to display these errors.

Sometimes you need to validate business validation such as ‘check user alredy existed in the system’, these should be performed in actions’ perform(), I will post the details in my next blog.

Posted in Uncategorized | Tagged , , | Leave a comment

Internationalization in Struts 1.1

How do you internationalize your struts 1.1 application?  Here are simple steps:

  1. Prepare you language speicific resource bundles.
  2. Provide default resource bundle in struts-config.xml using message-resources
  3. Include struts bean tag lib in your web.xml using taglib
  4. In JSP,  include your struts bean tag lib directive
  5. In JSP,  replace all hard-coded string … values with interntaionalized property keys using message property of bean tag
Posted in Uncategorized | Tagged , | 1 Comment

Implicit objects in JavaServer Pages.

In JSP you can get access to the following implicit objects:

  1. request – HttpServletRequest
  2. response  – HttpServletResponse
  3. Session – HttpSession
  4. out – JspWriter
  5. application – ServletContext
  6. config – ServletConfig
  7. pageContext
  8. page
  9. exception (available only to error pages).
Posted in Uncategorized | Tagged , , | 1 Comment

Scopes in JSP

In JSP you can create attributes in four scopes: page, request, session and application. If you need to access them Expression Language such as c:out tag, you can specify the scope explicitly.

Here are some examples:
<c:out value=”${pageScope.maxAttempts}” />
<c:out value=”${requestScope.maxAttempts}” />
<c:out value=”${sessionScope.maxAttempts}” />
<c:out value=”${applicationScope.maxAttempts}” />

If you try to display a value without specifying a scope, it first looks the value in the pageScope, requestScope, sessionScope and finally applicationScope. If it finds a value it displays otherwise it display ‘empty‘. Remember you won’t see null in the expression language.

Posted in Uncategorized | Tagged , | 1 Comment

ATG: How to pass parameters from JSP to Droplet

With tag , you can pass static value or object from JSP to droplet.

Passing a constant:
<dsp:param name=”maxProducts” value=”100″ />
You can retrieve the “maxProducts” parameter in the droplet by calling request.getParamter(“maxProducts”) which returns value of 100.

Passing a bean:
<dsp:param name=”order” bean=”ShoppingCart.current” />
You can retrieve the order object by calling request.getParamter(“order”)

Passing another parameter as parameter:
<dsp:param name=”lastOrder” param=”order” />
Here the lastOrder contains the reference to order which is also parameter

Posted in Uncategorized | Tagged , | Leave a comment