Aarthi Msincs
Aarthi Msincs

Reputation: 35

Please help in resolving this null pointer exception. This projct involves with struts2, jsp, java and struts.xml

The following jsp displays 4 text fields from the corresponding data base

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts2-jquery-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<p>This is for fun</p>


<s:form action="eAction" name="eSites">
    <s:textfield value="%{l.Name}" label="Name" id="name" ></s:textfield>
    <s:textfield value="%{l.plan}" label="t Plan" id="plan" ></s:textfield>

</s:form>

<s:form action="updateAction" name="eSite">

<button onclick="output()">Update</button>
<script>
function output(){
         eSite.submit();    
    }
</script>
</s:form>


</body>
</html>

Following is the database:

INSERT INTO engagement(PId, S_Id, P_Name, Pa_Plan, Pa_Method, PDate) 
    VALUES(2, 1, 'erferef', 'ergregre', 'egregref', '2012-9-19');

Followign is the struts.xml code.

    <action name="eAction"   class="com.fr.actions.EEngagement">
        <result name ="resultedfunc">/jsp/EParentEngagement.jsp</result> 
    </action>

    <action name="updateAction" class="com.fr.actions.EEngagement" method="update">
        <result name ="UPDATE">/jsp/Engagement.jsp</result>
    </action>

The problem arises is when I give xxx.eAction, I could see 4 text fields with data populated from db. After that if I click update button(code for this button is present in jsp file), the url is updateAction.action and I get null pointer exception in the following line.

        System.out.println(li.gett_Name());

Could some one please resolve this. I have spent almost 6+ hrs. I have tried autogenerating getters and setters and refactoring everything. But still I could not figure out. Please Please help me.

Upvotes: 0

Views: 266

Answers (1)

Satheesh Cheveri
Satheesh Cheveri

Reputation: 3679

Looks like below operation missing in your update method

EditParentEngagementDAO editParentEngagementDAO = new EditParentEngagementDAO();
listSiteDetails = editParentEngagementDAO.aSiteIdDetails(getParentengid());

You may need to call this before calling listsitedetails.get..

Upvotes: 1

Related Questions