JBoss Seam Validation Problems
visakh8 Jun 3, 2009 2:56 PMAction files arunme88
package demo.action;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
public class AddDAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
DynaActionForm f = (DynaActionForm)form;
//Create object of ActionMesssages
ActionMessages errors = new ActionMessages();
//Check and collect errors
if(((String)f.get("deptname")).equals("")) {
errors.add("deptname",new ActionMessage("error.name.required"));
}
if(((String)f.get("deptid")).equals("")) {
errors.add("deptid",new ActionMessage("error.address.required"));
}
//Saves the error
saveErrors(request,errors);
//Forward the page
if(errors.isEmpty()){
try
{
javax.sql.DataSource dataSource;
java.sql.Connection myConnection=null;
dataSource = getDataSource(request);
myConnection = dataSource.getConnection();
String deptid=(String)f.get("deptid");
int id=Integer.parseInt(deptid);
String deptname=(String)f.get("deptname");
PreparedStatement stmt=myConnection.prepareStatement("insert into department values(?,?);");
stmt.setInt(2,id);
stmt.setString(1,deptname);
stmt.executeUpdate();
}
catch (SQLException sqle)
{
getServlet().log("Connection.process", sqle);
}
return mapping.findForward("success");
}else{
return mapping.findForward("invalid");
}
}
}
---------------another one---
package demo.action;
/**
* @author Deepak Kumar
* @Web http://www.roseindia.net
* @Email roseindia_net@yahoo.com
*/
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
public class AddEAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
DynaActionForm f = (DynaActionForm)form;
//Create object of ActionMesssages
ActionMessages errors = new ActionMessages();
//Check and collect errors
if(((String)f.get("empid")).equals("")) {
errors.add("empid",new ActionMessage("error.name.required"));
}
if(((String)f.get("empname")).equals("")) {
errors.add("empname",new ActionMessage("error.address.required"));
}
if(((String)f.get("deptid")).equals("")) {
errors.add("deptid",new ActionMessage("error.name.required"));
}
if(((String)f.get("address")).equals("")) {
errors.add("address",new ActionMessage("error.address.required"));
}
if(((String)f.get("ph")).equals("")) {
errors.add("ph",new ActionMessage("error.name.required"));
}
//Saves the error
saveErrors(request,errors);
//Forward the page
if(errors.isEmpty()){
try
{
javax.sql.DataSource dataSource;
java.sql.Connection myConnection=null;
dataSource = getDataSource(request);
myConnection = dataSource.getConnection();
String deptid=(String)f.get("deptid");
int idd=Integer.parseInt(deptid);
String empid=(String)f.get("empid");
int ide=Integer.parseInt(empid);
String ph=(String)f.get("ph");
int phe=Integer.parseInt(ph);
String empname=(String)f.get("empname");
String address=(String)f.get("empname");
PreparedStatement stmt=myConnection.prepareStatement("insert into employee values(?,?,?,?,?);");
stmt.setInt(1,ide);
stmt.setString(2,empname);
stmt.setInt(3,idd);
stmt.setString(4,address);
stmt.setInt(5,phe);
stmt.executeUpdate();
}
catch (SQLException sqle)
{
getServlet().log("Connection.process", sqle);
}
return mapping.findForward("success");
}
else
{
return mapping.findForward("invalid");
}
}
}
--------------- Another one---------------
package demo.action;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
public class AddUAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
DynaActionForm f = (DynaActionForm)form;
//Create object of ActionMesssages
ActionMessages errors = new ActionMessages();
//Check and collect errors
if(((String)f.get("userid")).equals("")) {
errors.add("userid",new ActionMessage("error.name.required"));
}
if(((String)f.get("password")).equals("")) {
errors.add("password",new ActionMessage("error.address.required"));
}
if(((String)f.get("usertype")).equals("")) {
errors.add("usertype",new ActionMessage("error.name.required"));
}
//Saves the error
saveErrors(request,errors);
//Forward the page
if(errors.isEmpty()){
try
{
javax.sql.DataSource dataSource;
java.sql.Connection myConnection=null;
dataSource = getDataSource(request);
myConnection = dataSource.getConnection();
String deptid=(String)f.get("userid");
int idu=Integer.parseInt(deptid);
String password=(String)f.get("password");
String usertype=(String)f.get("usertype");
PreparedStatement stmt=myConnection.prepareStatement("insert into user values(?,?,?);");
stmt.setInt(1,idu);
stmt.setString(2,password);
stmt.setString(3,usertype);
stmt.executeUpdate();
}
catch (SQLException sqle)
{
getServlet().log("Connection.process", sqle);
}
return mapping.findForward("success");
}
else
{
return mapping.findForward("invalid");
}
}
}
-----------------Another One-----------------
package demo.action;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
public class AddDAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
DynaActionForm f = (DynaActionForm)form;
//Create object of ActionMesssages
ActionMessages errors = new ActionMessages();
//Check and collect errors
if(((String)f.get("deptname")).equals("")) {
errors.add("deptname",new ActionMessage("error.name.required"));
}
if(((String)f.get("deptid")).equals("")) {
errors.add("deptid",new ActionMessage("error.address.required"));
}
//Saves the error
saveErrors(request,errors);
//Forward the page
if(errors.isEmpty()){
try
{
javax.sql.DataSource dataSource;
java.sql.Connection myConnection=null;
dataSource = getDataSource(request);
myConnection = dataSource.getConnection();
String deptid=(String)f.get("deptid");
int id=Integer.parseInt(deptid);
String deptname=(String)f.get("deptname");
PreparedStatement stmt=myConnection.prepareStatement("insert into department values(?,?);");
stmt.setInt(2,id);
stmt.setString(1,deptname);
stmt.executeUpdate();
}
catch (SQLException sqle)
{
getServlet().log("Connection.process", sqle);
}
return mapping.findForward("success");
}else{
return mapping.findForward("invalid");
}
}
}
---------------another one---
package demo.action;
/**
* @author Deepak Kumar
* @Web http://www.roseindia.net
* @Email roseindia_net@yahoo.com
*/
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
public class AddEAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
DynaActionForm f = (DynaActionForm)form;
//Create object of ActionMesssages
ActionMessages errors = new ActionMessages();
//Check and collect errors
if(((String)f.get("empid")).equals("")) {
errors.add("empid",new ActionMessage("error.name.required"));
}
if(((String)f.get("empname")).equals("")) {
errors.add("empname",new ActionMessage("error.address.required"));
}
if(((String)f.get("deptid")).equals("")) {
errors.add("deptid",new ActionMessage("error.name.required"));
}
if(((String)f.get("address")).equals("")) {
errors.add("address",new ActionMessage("error.address.required"));
}
if(((String)f.get("ph")).equals("")) {
errors.add("ph",new ActionMessage("error.name.required"));
}
//Saves the error
saveErrors(request,errors);
//Forward the page
if(errors.isEmpty()){
try
{
javax.sql.DataSource dataSource;
java.sql.Connection myConnection=null;
dataSource = getDataSource(request);
myConnection = dataSource.getConnection();
String deptid=(String)f.get("deptid");
int idd=Integer.parseInt(deptid);
String empid=(String)f.get("empid");
int ide=Integer.parseInt(empid);
String ph=(String)f.get("ph");
int phe=Integer.parseInt(ph);
String empname=(String)f.get("empname");
String address=(String)f.get("empname");
PreparedStatement stmt=myConnection.prepareStatement("insert into employee values(?,?,?,?,?);");
stmt.setInt(1,ide);
stmt.setString(2,empname);
stmt.setInt(3,idd);
stmt.setString(4,address);
stmt.setInt(5,phe);
stmt.executeUpdate();
}
catch (SQLException sqle)
{
getServlet().log("Connection.process", sqle);
}
return mapping.findForward("success");
}
else
{
return mapping.findForward("invalid");
}
}
}
--------------- Another one---------------
package demo.action;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
public class AddUAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
DynaActionForm f = (DynaActionForm)form;
//Create object of ActionMesssages
ActionMessages errors = new ActionMessages();
//Check and collect errors
if(((String)f.get("userid")).equals("")) {
errors.add("userid",new ActionMessage("error.name.required"));
}
if(((String)f.get("password")).equals("")) {
errors.add("password",new ActionMessage("error.address.required"));
}
if(((String)f.get("usertype")).equals("")) {
errors.add("usertype",new ActionMessage("error.name.required"));
}
//Saves the error
saveErrors(request,errors);
//Forward the page
if(errors.isEmpty()){
try
{
javax.sql.DataSource dataSource;
java.sql.Connection myConnection=null;
dataSource = getDataSource(request);
myConnection = dataSource.getConnection();
String deptid=(String)f.get("userid");
int idu=Integer.parseInt(deptid);
String password=(String)f.get("password");
String usertype=(String)f.get("usertype");
PreparedStatement stmt=myConnection.prepareStatement("insert into user values(?,?,?);");
stmt.setInt(1,idu);
stmt.setString(2,password);
stmt.setString(3,usertype);
stmt.executeUpdate();
}
catch (SQLException sqle)
{
getServlet().log("Connection.process", sqle);
}
return mapping.findForward("success");
}
else
{
return mapping.findForward("invalid");
}
}
}
-----------------Another One-----------------