Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Attempted a bean operation on a null object.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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'm sure glad that he's gone. Now I can read this tiny ad in peace!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic