File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Attempted a bean operation on a null object. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Attempted a bean operation on a null object." Watch "Attempted a bean operation on a null object." New topic
Author

Attempted a bean operation on a null object.

mike bravo
Greenhorn

Joined: Jul 03, 2007
Posts: 2
Hi all, I am a new to web and struts programming and just starting to learn how to program in struts by making some simple WEB programs taken from the tutorials I had gotten from the web.

I have a JSP that displays the list of users and in the last column of each row, theres an html link that allows it to View, Edit or Delete each row. Here's my JSP.

<%@ taglib uri="/WEB-INF/taglibs/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/taglibs/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/taglibs/struts-logic.tld" prefix="logic" %>

<html:html>
<head>
<base href="<%=basePath%>">

<title>
<bean:message key="apex.title"/>
<bean:message key="apex.user.title"/>
</title>


<script type="text/javascript">
function showRow(r)
{
var i=r.parentNode.rowIndex
var x=document.getElementById('tblUser').rows [i].cells
return (x[0].innerHTML)
}
</script>

</head>

<body bgcolor="lightblue">
<center>
<p><h1><bean:message key="apex.user.list"/></h1></p>

<table border="1" cellpadding="3" id="tblUser">
<tr bgcolor="CCCCFF">
<th width="100">
<bean:message key="apex.user.username"/>
</th>
<th width="150">
<bean:message key="apex.user.lastname"/>
</th>
<th width="150">
<bean:message key="apex.user.firstname"/>
</th>
<th width="150">
<bean:message key="apex.user.actions"/>
</th>
</tr>
<logic:iterate id="user" name="users">
<tr align="center" bgcolor="FFFFFF">
<td bgcolor="FFFFCC">
<bean:write name="user" property="username"/>
</td>
<td>
<bean:write name="user" property="lastName"/>
</td>
<td>
<bean:write name="user" property="firstName"/>
</td>
<td bgcolor="FFFFCC">
<html:link property="uvwe" action="/viewUser.do">
<bean:message key="button.view"/>
<jsp:useBean id="personUserName" class="com.training.bdo.User" scope="request">
<jsp:setProperty name="personUserName" property="username" param="showRow(r)"/>
</jsp:useBean>
</html:link>
<html:link property="uedt" action="/editUser.do">
<bean:message key="button.edit"/>
</html:link>
<html:link property="udel" action="/deleteUser.do">
<bean:message key="button.delete"/>
</html:link>
</td>
</tr>
</logic:iterate>
</table>

<button property="uadd">
<bean:message key="apex.user.new"/>
</button>
<button property="main">
<bean:message key="apex.main.page"/>
</button>

</center>
</body>
</html:html>


What I want is that when I click the link like view user, it will forward me to the url = "/viewUser.do" defined in the struts-config.xml. This will just basically display complete user data. But before I could forward it I want to save the data of the username.

So what I have thought was to save it in a java bean using <jsp:usebean>. I use javascript so I could have a reference on the rows that I have click. I dont know if this is the right way of doing it

<jsp:useBean id="personUserName" class="com.training.bdo.User">
<jsp:setProperty name="personUserName" property="username" param="showRow(this)"/>
</jsp:useBean>

The jsp that I want to forward this just basically displays the username

<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'viewUserProfile.jsp' starting page</title>


</head>

<body>
<h1>This page will show user data. </h1><br>

<p>
Your user Name is: ${personUserName.username}
<!--Other data to follow upon retrieval of the user name attribute-->
</p>
</body>
</html>

I am receiving an error: Attempted a bean operation on a null object.
Please pardon me if my question maybe too simple to others. I am just working this out on my own through web tutorials.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Attempted a bean operation on a null object.