Tuesday, 13 August 2013

Compare value using Struts 2 If, ElseIf, Else tag


Struts 2 If, ElseIf, Else perform basic condition flow. 'If' tag could be used by itself or with 'Else If' Tag and/or single/multiple 'Else' Tag.


Parameters
1. test :- Expression to determine if body of tag is to be displayed.

Action Class :- containing a nameList of name
package com.struts2;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class RetrieveAction extends ActionSupport{
 
 /**
  * @author Arun
  */
 
 private List nameList = null;
   
 public String fetchName(){
  nameList =  new ArrayList();
  {
   nameList.add("Arun");
   nameList.add("Anu");
   nameList.add("Aryan");
   nameList.add("Anu");
   nameList.add("Aranv");
   nameList.add("Arun");
   nameList.add("Aryan");
   nameList.add("Aryan");
   nameList.add("Aarus");
   nameList.add("Aranv");
   nameList.add("Aryan");
   nameList.add("Anu");
  }
  return SUCCESS;
 }

 public List getNameList() {
  return nameList;
 }

 public void setNameList(List nameList) {
  this.nameList = nameList;
 }
 
}


Result.jsp


Struts2


Spring3


Hibernate3


Core Java


While running project you will following output :-

Hope This Help You :)