You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Geoff Howard <co...@leverageweb.com> on 2003/11/24 17:11:39 UTC
Re: Flow Basic Java language help
JD Daniels wrote:
> I think I need some help with something more basic than I realize...
>
> The idea here is that my form has checkboxes named tickets[]
> When flow gets it, the toString() gives me 2,5,6 or what ever the values
> are.
> basically this function will build the IN sql clause (I know this is very
> hacky, but I am against a noon-type deadline)
>
> The problem is I can't seem to check if it is null (No boxes checked)
> without a nullpointer exception. Which seems really irritating.. I want to
> TEST if it is null.
I don't see an attempt at a null check below - perhaps you took it out?
But without seeing it, are you certain you did "== null" or "!=null"
instead of (assignment) "= null"? Also, I presume you tested tickets
right after var tickets = cocoon.request.get("tickets[]"); and not after
the attempt to call toArray() (which would be too late).
var tickets = cocoon.request.get("tickets[]");
if (tickets == null) {
// Handle no tickets here
}
Throws an NPE? If so, what is the stacktrace?
Geoff
> Same thing to check if it contains a _single_ item. I have a try/catch to
> find the nullpointer... but of course when it has a single item it catches
> it too.
>
> So in short:
>
> How do I test if tickets has no elements?
> How do I check if tickets has one element to skip the for block?
>
> Help :S
>
>
>
> function do()
> {
> var tickets = cocoon.request.get("tickets[]");
> try{
> var s = "tickets.id IN (";
>
> tickets = tickets.toArray();
>
> for (var i = 0; i < tickets.length; i++) {
> tickets[i] = "'" + tickets[i] + "'";
> if (i != "0")
> {
> s = s + "," + tickets[i];
> }
> else
> {
> s = s + tickets[i];
> }
> }
>
> var s = s + ")";
> print(s);
> cocoon.request.setAttribute("sql", s);
> cocoon.sendPage("postInvoice.xsp");
> }
> catch(Exception)
> {
> print("Exception Occured");
> cocoon.sendPage("fail.xml",{error: "Please Select Some Tickets."});
> }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Flow Basic Java language help
Posted by Geoff Howard <co...@leverageweb.com>.
JD Daniels wrote:
> I found a way.. not sure how hacky this is or if there is a better way...
>
> If tickets.length fails.. it returns undefined not null...
In javascript (flowscript) this should be
if (typeof(tickets.length) == 'undefined') {
// handle one value
}
which may be a little cleaner.
Geoff
> function postInvoice()
> {
> var tickets = cocoon.request.get("tickets[]");
> if(tickets != null)
> {
> var s = "tickets.id IN (";
>
> if(tickets.length)
> {
> s = s + "'" + tickets + "'";
> }
> else
> {
> tickets = tickets.toArray();
> for (var i = 0; i < tickets.length; i++)
> {
> tickets[i] = "'" + tickets[i] + "'";
> if (i != "0")
> {
> s = s + "," + tickets[i];
> }
> else
> {
> s = s + tickets[i];
> }
> }
> }
>
> var s = s + ")";
> cocoon.request.setAttribute("sql", s);
> cocoon.sendPage("postInvoice.xsp");
> }
> else
> {
> cocoon.request.setAttribute("error", "Please Select Some Tickets.");
> cocoon.sendPage("failure.xsp");
> }
> }
>
> JD
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
RE: Flow Basic Java language help
Posted by JD Daniels <jd...@datatrio.com>.
I found a way.. not sure how hacky this is or if there is a better way...
If tickets.length fails.. it returns undefined not null...
function postInvoice()
{
var tickets = cocoon.request.get("tickets[]");
if(tickets != null)
{
var s = "tickets.id IN (";
if(tickets.length)
{
s = s + "'" + tickets + "'";
}
else
{
tickets = tickets.toArray();
for (var i = 0; i < tickets.length; i++)
{
tickets[i] = "'" + tickets[i] + "'";
if (i != "0")
{
s = s + "," + tickets[i];
}
else
{
s = s + tickets[i];
}
}
}
var s = s + ")";
cocoon.request.setAttribute("sql", s);
cocoon.sendPage("postInvoice.xsp");
}
else
{
cocoon.request.setAttribute("error", "Please Select Some Tickets.");
cocoon.sendPage("failure.xsp");
}
}
JD
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
RE: Flow Basic Java language help
Posted by JD Daniels <jd...@datatrio.com>.
Yes I tried if (tickets == null)
Throws nullpointerexception
I took it out and put the try / catch in to catch it.. and send fail.xml.
I tried moving the null check to before toArray() - Works great thank you :)
Now If tickets contains only one item, it dies (toArray() is not a function)
it seems that if there is only one item, it is not a list object.... how do
I test for types? I mean to see if it has one item....
JD
-----Original Message-----
From: Geoff Howard [mailto:cocoon@leverageweb.com]
Sent: Monday, November 24, 2003 8:12 AM
To: users@cocoon.apache.org
Subject: Re: Flow Basic Java language help
JD Daniels wrote:
> I think I need some help with something more basic than I realize...
>
> The idea here is that my form has checkboxes named tickets[]
> When flow gets it, the toString() gives me 2,5,6 or what ever the values
> are.
> basically this function will build the IN sql clause (I know this is very
> hacky, but I am against a noon-type deadline)
>
> The problem is I can't seem to check if it is null (No boxes checked)
> without a nullpointer exception. Which seems really irritating.. I want to
> TEST if it is null.
I don't see an attempt at a null check below - perhaps you took it out?
But without seeing it, are you certain you did "== null" or "!=null"
instead of (assignment) "= null"? Also, I presume you tested tickets
right after var tickets = cocoon.request.get("tickets[]"); and not after
the attempt to call toArray() (which would be too late).
var tickets = cocoon.request.get("tickets[]");
if (tickets == null) {
// Handle no tickets here
}
Throws an NPE? If so, what is the stacktrace?
Geoff
> Same thing to check if it contains a _single_ item. I have a try/catch to
> find the nullpointer... but of course when it has a single item it catches
> it too.
>
> So in short:
>
> How do I test if tickets has no elements?
> How do I check if tickets has one element to skip the for block?
>
> Help :S
>
>
>
> function do()
> {
> var tickets = cocoon.request.get("tickets[]");
> try{
> var s = "tickets.id IN (";
>
> tickets = tickets.toArray();
>
> for (var i = 0; i < tickets.length; i++) {
> tickets[i] = "'" + tickets[i] + "'";
> if (i != "0")
> {
> s = s + "," + tickets[i];
> }
> else
> {
> s = s + tickets[i];
> }
> }
>
> var s = s + ")";
> print(s);
> cocoon.request.setAttribute("sql", s);
> cocoon.sendPage("postInvoice.xsp");
> }
> catch(Exception)
> {
> print("Exception Occured");
> cocoon.sendPage("fail.xml",{error: "Please Select Some Tickets."});
> }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org