You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by James Scott <js...@hnt.com> on 2000/11/30 15:53:02 UTC
NullPointerException with query parameters
Hi all-
I didn't see this one in the FAQ or in my personal mail archive. Sorry if it's a
duplicate.
I quite often set the value of XML tags from query parameters, or perform
actions based on a query param's value. I'm sure this is common practice:
<xsp:logic>
String action = request.getParameter("action");
if (action.equals("option1"))
{
//do action
}
else if (action.equals("option2"))
{
//do something else
}
...
</xsp:logic>
However, Cocoon (v 1.8, BTW) doesn't do very well when that query parameter
isn't set. I invariably get a NullPointerException from the populateDocument
method. Have I unknowingly violated some design rules? Should I use another
method for communicating control parameters?
I know in general it's not good practice to use parameters as control switches -
you're better off separating those two actions into two different
methods/functions/whatever. In this case I'm dealing with a confirmation before
an action - "Is this really what you want to do?" or "Please fill in these
details so I can perform the action." I thought it would be better from a
readability/maintainability standpoint to have one XSP perform those functions.
HTTP query parameters seemed to be the best way to communicate the state. I
could use session variables but then I'd have to clean up after myself.
JLS