wood burning stoves 2.0
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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

Attempted a bean operation on a null object.

mike bravo

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" %>

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

<bean:message key="apex.title"/>
<bean:message key="apex.user.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)


<body bgcolor="lightblue">
<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 width="150">
<bean:message key="apex.user.lastname"/>
<th width="150">
<bean:message key="apex.user.firstname"/>
<th width="150">
<bean:message key="apex.user.actions"/>
<logic:iterate id="user" name="users">
<tr align="center" bgcolor="FFFFFF">
<td bgcolor="FFFFCC">
<bean:write name="user" property="username"/>
<bean:write name="user" property="lastName"/>
<bean:write name="user" property="firstName"/>
<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)"/>
<html:link property="uedt" action="/editUser.do">
<bean:message key="button.edit"/>
<html:link property="udel" action="/deleteUser.do">
<bean:message key="button.delete"/>

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


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)"/>

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

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

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


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

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

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.
It's not a secret anymore!