struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From struts2problems <charitha.nagell...@gmail.com>
Subject Struts2 multiple submit buttons in One action class
Date Sat, 22 Mar 2014 10:31:14 GMT
I wrote code for multiple submit buttons of one form in one Action class by
using java bean. But when I was running the application first time its
working fine After that I am getting NullPointerException . Please Help me.
Here is My code.

*Exception:*
*!st time running.*
calling bean getterinfo.struts2.pinfo.PInfoDTO@16ea269
calling bean getterinfo.struts2.pinfo.PInfoDTO@16ea269
calling bean getterinfo.struts2.pinfo.PInfoDTO@16ea269
calling bean getterinfo.struts2.pinfo.PInfoDTO@16ea269
calling bean getterinfo.struts2.pinfo.PInfoDTO@16ea269
calling bean getterinfo.struts2.pinfo.PInfoDTO@16ea269
calling bean getterinfo.struts2.pinfo.PInfoDTO@16ea269
calling bean getterinfo.struts2.pinfo.PInfoDTO@16ea269
We are in add
calling bean getterinfo.struts2.pinfo.PInfoDTO@16ea269
add
*2nd time running*
we are in edit
calling bean getternull
edit
java.lang.NullPointerException
	at info.struts2.pinfo.DAO.edit(DAO.java:37)
	at info.struts2.pinfo.PInfoBean.editOperation(PInfoBean.java:23)
	at info.struts2.pinfo.PersonalInfoAction.edit(PersonalInfoAction.java:103)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:446)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:285)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
	at
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
	at
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
	at
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)

//PersonalInfoAction.java


package info.struts2.pinfo;

import sun.security.action.GetBooleanAction;

import com.opensymphony.xwork2.ActionSupport;

public class PersonalInfoAction extends ActionSupport {
	
	private static PInfoDTO bean;
	
	
	
	public PInfoDTO getBean() {
		System.out.println("calling bean getter"+bean);
		return bean;
	}
	public void setBean(PInfoDTO bean) {
		this.bean = bean;
		
	}
	/*private String name;
	  private String city;
	  private String street;
	  private String district;
	  private String country;
	  private String pincode;
	  private String pno;
	  private String mno;
	  private String email; 
	  private PInfoDTO pdto=new PInfoDTO();
	 
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
		pdto.setName(name);
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
		pdto.setCity(city);
	}
	public String getStreet() {
		return street;
	}
	public void setStreet(String street) {
		this.street = street;
		pdto.setStreet(street);
	}
	public String getDistrict() {
		return district;
	}
	public void setDistrict(String district) {
		this.district = district;
		pdto.setDistrict(district);
	}
	public String getCountry() {
		return country;
	}
	public void setCountry(String country) {
		this.country = country;
		pdto.setCountry(country);
	}
	public String getPincode() {
		return pincode;
	}
	public void setPincode(String pincode) {
		this.pincode = pincode;
		pdto.setPincode(pincode);
	}
	public String getPno() {
		return pno;
	}
	public void setPno(String pno) {
		this.pno = pno;
		pdto.setPno(pno);
	}
	public String getMno() {
		return mno;
	}
	public void setMno(String mno) {
		this.mno = mno;
		pdto.setMno(mno);
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
		pdto.setEmail(email);
		
	}*/
	public String add() {
		 System.out.println("We are in add");
		PInfoBean.addOperation(this.getBean());
		return "success";
	}
	public String edit(){
		System.out.println("we are in edit");
		PInfoBean.editOperation(this.getBean());
		return "success";
	}
	public String delete(){
		System.out.println("we are in delete");
		PInfoBean.deleteOperation(this.getBean());
		return "success";
	}
	public String execute(){
		return "success";
	}
	
	/*public void validate(){
		//System.out.println(getPdto().getName());
		if(getName()==null || getName().equals("")){
			addFieldError("name", getText("required.name"));
		}
		if(getCity()==null || getCity().equals("")){
			addFieldError("city", getText("required.city"));
		}
		if(getDistrict()==null || getDistrict().equals("")){
			addFieldError("district", getText("required.district"));
		}
		if(getStreet()==null || getStreet().equals("")){
			addFieldError("street", getText("required.street"));
		}
		if(getCountry()==null || getCountry().equals("")){
			addFieldError("country", getText("required.country"));
		}
	}
*/
}

And My java Bean Code is

//PInfoDTO.java


package info.struts2.pinfo;

public class PInfoDTO {
	
  private String name;
  private String city;
  private String street;
  private String district;
  private String country;
  private String pincode;
  private String pno;
  private String mno;
  private String email;
  private String add;
  private String edit;
  private String delete;
  
public String getAdd() {
	return add;
}
public void setAdd(String add) {
	this.add = add;
}
public String getEdit() {
	return edit;
}
public void setEdit(String edit) {
	this.edit = edit;
}
public String getDelete() {
	return delete;
}
public void setDelete(String delete) {
	this.delete = delete;
}
public String getName() {
	System.out.println("calling getName"+name);
	return name;
}
public void setName(String name) {
	System.out.println("calling setName"+name);
	this.name = name;
}
public String getCity() {
	return city;
}
public void setCity(String city) {
	System.out.println("calling setCity"+city);
	this.city = city;
}
public String getStreet() {
	return street;
}
public void setStreet(String street) {
	System.out.println("calling setStreet"+street);
	this.street = street;
}
public String getDistrict() {
	return district;
}
public void setDistrict(String district) {
	System.out.println("calling setDistrict"+district);
	this.district = district;
}
public String getCountry() {
	return country;
}
public void setCountry(String country) {
	System.out.println("calling setCountry"+country);
	this.country = country;
}
public String getPincode() {
	return pincode;
}
public void setPincode(String pincode) {
	System.out.println("calling setPincode"+pincode);
	this.pincode = pincode;
}
public String getPno() {
	return pno;
}
public void setPno(String pno) {
	System.out.println("calling setPno"+pno);
	this.pno = pno;
}
public String getMno() {
	return mno;
}
public void setMno(String mno) {
	System.out.println("calling setMno"+mno);
	this.mno = mno;
}
public String getEmail() {
	return email;
}
public void setEmail(String email) {
	System.out.println("calling setEmail"+email);
	this.email = email;
}

  
  
}

//pinfo1.jsp

<%@ taglib uri="/struts-tags" prefix="s"%>

<s:form action="pinfo"   >


<s:textfield label="Name" name="bean.name"/>
<s:textfield label="City" name="bean.city"/>
<s:textfield label="District" name="bean.district" />
<s:textfield label="Street" name="bean.street" />
<s:textfield label="Country" name="bean.country" />
<s:textfield label="Pincode" name="bean.pincode" />
<s:textfield label="Phno" name="bean.pno" />
<s:textfield label="Mobile No" name="bean.mno" />
<s:textfield label="Email" name="bean.email" />



<s:submit action="pinfoAdd"  key="lbl.add" theme="simple"   />
<s:submit action="pinfoEdit" key="lbl.edit" theme="simple"  />
<s:submit action="pinfoDelete" key="lbl.delete" theme="simple"  />





</s:form>

//struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
&quot;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&quot;
&quot;http://struts.apache.org/dtds/struts-2.0.dtd&quot;>
<struts>
 <constant name="struts.custom.i18n.resources" value="ApplicationResources"
/>
<package name="default" extends="struts-default">

    <action name="pinfo" method="execute" 
class="info.struts2.pinfo.PersonalInfoAction">
		<result name="success">pinfo.jsp</result>
		<result name="input">pinfo.jsp</result>
 	</action>
 	<action name="pinfoAdd" method="add"
class="info.struts2.pinfo.PersonalInfoAction">
			<result name="success">pinfo.jsp</result>
			<result name="input">pinfo.jsp</result>
	</action>
		
		<action name="pinfoEdit" method="edit"
			class="info.struts2.pinfo.PersonalInfoAction">
			<result name="success">pinfo.jsp</result>
			<result name="input">pinfo.jsp</result>
		</action>
		<action name="pinfoDelete" method="delete"
			class="info.struts2.pinfo.PersonalInfoAction">
			<result name="success">pinfo.jsp</result>
			<result name="input">pinfo.jsp</result>
		</action>
       
</package>
</struts>

How to resolve this problem please help me. 





--
View this message in context: http://struts.1045723.n5.nabble.com/Struts2-multiple-submit-buttons-in-One-action-class-tp5715568.html
Sent from the Struts - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message