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