Here is the Action.java Velocity template and the properties file. If
anyone want's more send me your email address and I'll send you a copy
of it. I don't want my entire code on the web.
_______________________________
InfoAction.java
_______________________________
package actions;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import beans.*;
import logic.*;
import forms.*;
public class InfoAction extends Action
{
public ActionForward execute (ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
String action;
HttpSession session;
DB database = new DB ();
try
{
session = request.getSession();
action = ((InfoForm)form).getAction();
if(action.equals("Enter Information"))
{
InfoBean bean = (InfoBean)session.getAttribute("info");
if(bean == null)
{
bean = new InfoBean ();
session.setAttribute("info", bean);
}
bean.setFirst(((InfoForm)form).getFirst());
bean.setLast(((InfoForm)form).getLast());
bean.setStreet(((InfoForm)form).getStreet());
bean.setCity(((InfoForm)form).getCity());
bean.setState(((InfoForm)form).getState());
bean.setZip(((InfoForm)form).getZip());
database.insert(bean);
return (mapping.findForward("Enter Information"));
}
else
{
return (mapping.findForward("done"));
}
}
catch (Exception e)
{
e.printStackTrace();
}
return (mapping.findForward("done"));
}
}
_________________________
info.vm
______________________
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
#* velocity document *#
<html>
<head>
<title>$title.get("title")</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<h1>Personal Information</h1>
<form name="info" action="$link.setAction("Info")"
method="get">
<input type="hidden" name="action" value="list">
<table width="263" border="0" align="center">
<tr>
<td>$text.get("first")</td>
<td><input type="text" name="first"
value="$!info.first"></td>
</tr>
<tr>
<td>$text.get("last")</td>
<td><input type="text" name="last"
value="$!info.last"></td>
</tr>
<tr>
<td>$text.get("street")</td>
<td><input type="text" name="street"
value="$!info.street"></td>
</tr>
<tr>
<td>$text.get("city")</td>
<td><input type="text" name="city"
value="$!info.city"></td>
</tr>
<tr>
<td>$text.get("state")</td>
<td><input type="text" name="state" value="$!info.state"
size="2" maxlength="2" ></td>
</tr>
<tr>
<td>$text.get("zip")</td>
<td><input type="text" name="zip" value="$!info.zip"
size="5" maxlength="5"></td>
</tr>
</table>
<input type="submit" name="Submit" value=" $text.get("enter") "
onclick="info.action.value='Enter Information'; document.info.submit(); return false;">
<input type="submit" name="Submit2" value=" $text.get("done") "
onclick="info.action.value='done'; document.info.submit(); return false;">
</form>
<p> </p>
</div>
</body>
</html>
_______________________________________
ApplicationResources.properties
__________________________________
# Sample ResourceBundle properties file
title=Gathering Personal Information
first=First Name
last=Last Namestreet=Street Address
city=City
state=State
zip=Zip
enter=Enter Information
done=Done
Paul
Shinobu Kawai wrote:
Hi Paul,
I have written a few java files and rewrote a template to be more like a
template rather then standard html. When I tried to view the webpage I
found that I have a NullPointerException. Usually when there is a NPE
the compiler tells me where in my code the NPE is coming from. However
it just starts out with
"org.apache.velocity.tools.struts.StrutsUtils.getMessageResources(StrutsUtils.java:211)"
Source says, you didn't give it a ServletContext, or a ModuleConfig
could not be found.
return (MessageResources)app.getAttribute(Globals.MESSAGES_KEY +
moduleConfig.getPrefix());
I think the problem is that the properties file I defined is not moved
to the classes directory when the javacode is compiled. How do I do
that if I am using Ant to compiule my source code? However when I did
move the properties file into the right directory, I still get the same
error. Oh yeah this happens on all velocity pages that I created
before I changed the code.
If you need to see the entire error please let me know and I will
provide it.
I think it would. Better yet, you could show us some minimal code to
reproduce your problem. ;)
As for the Ant question, the Ant User List would be a better place to ask.
http://ant.apache.org/mail.html
Best regards,
-- Shinobu
--
Shinobu Kawai <[EMAIL PROTECTED]>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]