JSTL Core - How to test for null?
How do I test an attribute for null using JSLT's if statement? The below code does not work (the JSTL if statement does not return true). The scriptlet however does work and displays the statement.
- Chris
index.jsp
<%@ taglib uri="c.tld" prefix="c"%>
<%@ taglib uri="fmt.tld" prefix="fmt"%>
<%@page import="java.util.*"%>
<%
request.setAttribute("null", null);
%>
<html>
<head>
<title>JSTL Test Page</title>
</head>
<body>
<c:if test="${null}==null">
The value was null (JSTL)
</c:if>
<%
if (request.getAttribute("null")==null) out.print("The value was null (Scriptlet)");
%>
</body>
</html>
<%out.flush();%>
Well, I figured out. If anyone is interested, here is the code:
<c:if test="${empty varName}">
Its null
</c:if>
Similar Messages
-
I am trying to do a test for a null result set. Basically if the result set returns a value I want to display a table, otherwise I want to display an error message. The following code does not produce the error message. Either the test for null is incorrect, or for some reason I am not getting a null result set even when I don't enter any text into the following text boxes (this is for a login screen, these text boxes come a login screen):
<input type="text" name="username">
<input type="text" name="password">
This is the code for the action page:
<HTML>
<%@page import="java.sql.*"%>
<%
//define connection
Connection con = null;
String user1 = request.getParameter("username");
String pass1 = request.getParameter("password");
String test = "good";
try{
//get the class
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//get the connection
con = DriverManager.getConnection("jdbc:odbc:errorlog", "admin", "");
//catch your exceptions!
catch(Exception e){
out.println(e.getMessage());
%>
<title>Error Application - Logged Errors</title>
<link href="style/errorstyle.css" rel="stylesheet" type="text/css">
<BODY>
<%
//define resultset and statement
ResultSet rs=null;
Statement stmt=null;
try {
//Using the current database connection create a statement
stmt=con.createStatement();
%>
<%
String sql="SELECT* FROM tblUsers" + " WHERE Username = '"+user1+"' AND Password ='"+pass1+"'";
rs = stmt.executeQuery(sql);
%>
<% //Fetch all the records and print in table
while(rs.next()){
String user2 = rs.getString("FirstName");
String pass2 = rs.getString("LastName");
%>
<table width="100%" border="0" cellspacing="1" cellpadding="6">
<tr >
<td width="67" height="27" bgcolor="#999999"><strong><font size="- 1">First Name</font></strong>
</td>
<td width="89" bgcolor="#999999"><strong><font size="-1">Last
Name</font></strong>
</td>
</tr>
<tr>
<td>
<%out.println(user2);%>
</td>
<td><%out.println(pass2);%></td>
</table>
<%}
if (rs == null)
out.println("Incorrect Username or Password");
//close all your open resultsets, statements, and connection when you are done with them!
rs.close();
stmt.close();
con.close();
//catch all your exceptions
catch (SQLException e) {
out.println(e.getMessage());
%>You simply test the rs.next().
if ( rs.next() )
//spit out the rs row and
//continue processing the resultset 'til empty
else
msg = "invalid username or password
} -
Dropdown List Value Test For Null || " "
I wrote a pre-sign script to test a for a value in a dropdown list before allowing signature of the document. However I want to test for a value of null in addtion to one space aka " ". I added a value in the dropdown list of " " along with the choices of names so users could erase an accidental selection in this list before they were ready. However when I place the or ( || ) operator in the if statement of the script the script doesn't work. If I remove the || " " statement the script works as it is supposed to. How do I test for this value of " " along with the null test so I don't have to write another if statement?
if (form1.Page3.Author.Reviewed.Admin.rawValue == null || " ")
xfa.event.cancelAction = 1
xfa.host.messageBox("You did not select your name on the dropdown list before trying sign the document .");
elseYour if statement is incomplete. You need to put the test in again for the other value:
if (form1.Page3.Author.Reviewed.Admin.rawValue == null || form1.Page3.Author.Reviewed.Admin.rawValue == " ") -
How to test for différent Select into a single PL/SQL block ?
Hi,
I am relatively new to PL/SQL and I am trying to do multiple selects int a single PL/SQL block. I am confronted to the fact that if a single select returns no data, I have to go to the WHEN DATA_NOT_FOUND exception.
Or, I would like to test for different selects.
In an authentification script, I am searching in a table for a USER ID (USERID) and an application ID, to check if a user is registered under this USERID for this APPLICATION.
There are different possibilities : 4 possibilities :
- USERID Existing or not Existing and
- Aplication ID found or not found for this particular USERID.
I would like to test for thes 4 possibilities to get the status of this partiular user regardin this application.
The problem is that if one select returns no row, I go to the exception data not found.
In the example below you see that if no row returned, go to the exception
DECLARE
P_USERID VARCHAR2(400) DEFAULT NULL;
P_APPLICATION_ID NUMBER DEFAULT NULL;
P_REGISTERED VARCHAR2(400) DEFAULT NULL;
BEGIN
SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
WHERE USERID = :P39_USERID AND APPLICATION_ID = :APP_ID ;
:P39_TYPE_UTILISATEUR := 'USER_REGISTERED';
EXCEPTION
WHEN NO_DATA_FOUND THEN
:P39_TYPE_UTILISATEUR := 'USER_NOT_FOUND';
END;I would like to do first this statement :
SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
WHERE USERID = :P39_USERID Then to do this one if the user is found :
SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
WHERE USERID = :P39_USERID AND APPLICATION_ID = :APP_ID ;etc...
I basically don't want to go to the not found exception before having tested the 4 possibilities.
Do you have a suggestion ?
Thank you for your kind help !
ChristianSurely there are only 3 conditions to check?
1. The user exists and has that app
2. The user exists and doesn't have that app
3. The user doesn't exist
You could do this in one sql statement like:
with mimic_data_table as (select 1 userid, 1 appid from dual union all
select 1 userid, 2 appid from dual union all
select 2 userid, 1 appid from dual),
-- end of mimicking your table
params_table as (select :p_userid userid, :p_appid appid from dual)
select pt.userid,
pt.appid,
decode(min(case when dt.userid = pt.userid and dt.appid = pt.appid then 1
when dt.userid = pt.userid then 2
else 3
end), 1, 'User and app exist',
2, 'User exists but not for this app',
3, 'User doesn''t exist') user_app_check
from mimic_data_table dt,
params_table pt
where pt.userid = dt.userid (+)
group by pt.userid, pt.appid;
:p_userid = 1
:p_appid = 2
USERID APPID USER_APP_CHECK
1 2 User and app exist
:p_userid = 1
:p_appid = 3
USERID APPID USER_APP_CHECK
1 3 User exists but not for this app
:p_userid = 3
:p_appid = 2
USERID APPID USER_APP_CHECK
3 2 User doesn't exist -
How to test for existence of AcroXFA test objects?
Hi -
I'm writing scripts to test an XFA form with dynamic subforms. For example, at the end of Part 4, the user hits a Validate button, and if their data is correct, then the Validate button disappears and a Part 5 subform appears.
So my script looks something like this:
Function GetButtonPart4Validate()
Set GetButtonPart4Validate = PDFDoc("TestForm").AcroXFAForm("form").AcroXFAForm("form1")
.AcroXFAForm("sfPart4").AcroXFAButton("sfValidate")
End Function
Function GetPart5()
Set GetPart5 = PDFDoc("TestForm").AcroXFAForm("form").AcroXFAForm("form1").AcroXFAForm("sfPart5")
End Function
GetButtonPart4Validate().Click
PDFDoc( "TestForm" ).WaitProperty "ready", true, 60000 ' Wait for event processing complete
If DataTable("boolValidates", dtLocalSheet) = "TRUE" Then
If( GetPart5().Exist ) Then
' A: Checkpoint Succeeds: Validation was successful
Else
' B: Checkpoint fails: Validation failed
Endif
Else
If( GetPart5().Exist ) Then
' C: Checkpoint Fails: Validation was unexpected
Else
' D: Checkpoint Succeeds: Validation failed as expected
Endif
Endif
Unfortunately it appears that XfaSubForm.Exist always returns TRUE. In other QTP testing domains (eg "Exist Property (WinObject)" in QTP Help), the documented behaviour of the Exist property is to be true if the desired test object can be found in the application-under-test. Typically this means that when the script tries to access an XFA widget which doesn't exist (even something like GetPart5().getROProperty("visible") ), the script stops and thinks for a minute or so, and eventually produces a test error that the object doesn't exist then muddles onward. It is the "stops and thinks for a minute or so" which frustrates me, since these are delays which I am trying to avoid.
Another possible angle I looked into was counting the subforms under Part 5's parent.
PDFDoc("TestForm").AcroXFAForm("form").AcroXFAForm("form1").RefreshObject
PDFDoc("TestForm").AcroXFAForm("form").AcroXFAForm("form1").AcroXFAForm("sfPart5").Refresh Object
' check to see if there is a 'sfPart5'
Dim MyChildren, i
Set MyChildren = PDFDoc("TestForm").AcroXFAForm("form").AcroXFAForm("form1").ChildObjects
For i=0 to MyChildren.Count - 1
print i & " name=" & MyChildren(i).GetROProperty("name")
Next
This also seems to fail: Part5 doesn't appear among its parent's children (at least before QTP actually tries to use it).
The PDF Test Toolkit User Guide doesn't specifically mention that Exist or RefreshObject or ChildObjects are implemented, so I can't say AcroQTP isn't working as designed, but if you're looking for suggestions for improvement, I'll vote for fulfilling these parts to the QTP. Please confirm my conclusions that these are not properly implemented, or whether I'm missing something.
In the meantime, do you have any recommendation on how to proceed? My present workaround is to look for a "validation error" windows dialog that indicates Part 5 won't exist, but this won't work in future test scripts.
Cheers,
BrentHi,
816387 wrote:
... QUERY:- Find all customers who have at most one account at the Perryridge branch.
SOLUTION *1* :-
select customer_name
from depositor,account
where account.account_number=depositor.account_number and
branch_name='Perryridge'
group by customer_name
having count(account.account_number) <=1
ok running correctly
That finds customers who have exactly one account at Perryridge.
The assignment is to find customers who have at most one account at Perryridge. You need to include customers with 0 accounts at Perryridge, as well. You could use an outer join, or MINUS, or a NOT IN subquery, or a NOT EXISTS sub-query (as mentioned above) to do that.
Can there be customers who have no accounts at all, at any branch? If so, you'll need to use the customer table in this problem, as well as depositor and account.
>
SOLUTION *2* :-
select D1.customer_name
from depositor D1
where unique
(select customer_name
from depositor D2,account A1
where D1.customer_name=D2.customer_name
D2.account_number=A1.account_number and
branch_name='Perryridge'
gives error:-
where unique
..........*^*
ERROR at line 3:
ORA-00936: missing expression
Logic of both solution are correct . But Solution 2 gives error in oracle. I want unique construct to work.Sorry, it doesn't in Oracle. I don't know of anything like that in Oracle.
Does "WHERE UNIQUE (SELECT ...)" work in some other database system? Which?
How to do it. Or How can i test for the absence of duplicate tuples ??????
Your Solution 1 is the best way to find customers with exatly 1 account (rather than 0 or 1 accounts) at Perryridge. Is there any reason why you wouldn't want to use it, if you ever needed to find customers with exactly one account there? -
Where condition to test for null
Hi,
I have a query where we were thinking that 2 fields will not have null values even though column allows nulls. So, wrote a query like this:
select.......
From table 1 left outer join table2 on (table1.name = 'I' and table2.accountnum in (table1.creditact, table1.debitact).
Now I need to check for null if table1.creditact and table1.debitact. If both fields are null, then I have to use third column to check because out of 3 column (creditact, debitact, act) one must have account number. How can I do it.
Thanks,
SpunnyI have a query where we were thinking that 2 fields [sic: columns are not fields] will not have NULL values [sic: NULL is not a value] even though column allows NULLs. So, wrote a query like this:
Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on SQL forums. What you did post implies that your design is wrong. Did you actually have debits and credits as separate attributes in RDBMS? No, surely not! I will guess, based 30+ years of SQL, that you have a crappy design
with too many NULLs.
Would you like to obey the Netiquette so we can actually help you, or you do just want a Kludge?
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
I am trying to get some input from a user using:
String name="";
BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
name = in.readLine();Let's say the user inputs nothing other than the enter key, how can I test for this so that I can write output for it?
In Python, one would use something like:
if not name:
<then do something>Thanks,
Harlin SerittThanks for the help. When I try it with an empty
string test, nothing happens. However, the test of
name.length() works perfectly. Thanks!
Harlin SerittI'm guessing you tried this, right?
if (name == "") ...
That's not the way to compare string values. The == operator only compares object references when comparing 2 objects. It's an extremely common mistake. -
How to check for null values in bpel?? Please Help! very urgent!!!
Hello Guys,
I have a problem. I have an external webservice to which I have to post my request. My task is to create an Webservice and Service Assembly to which others would post request and get response. I have to create SA to deploy onto the bus.
The problem is that there are optional elements in the request and response xsd's. In the Response sometimes certain feilds may come or they may not. for Example:- my response could contain a tag like this <firstName></firstName>
I have to copy these feilds in my bpel process from one variable to another.(like in the mapper).
My Question is , Is there any way in BPEL process or BPEL mapper where I could Check for null values in the request or response???
Your inputs would be very helpful.
Thanks
RajeshThanks for replying man :)
Ok I will be more clear.
Here is a snippet of one of the xsd's that I am using.
<xs:element name="returnUrl" nillable="false" minOccurs="0">
<xs:annotation>
<xs:documentation>Partner specifies the return URL to which responses need to be sent to, in case of
Async message model.
</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:anyURI">
<xs:maxLength value="300"/>
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
This means that the return URL field can be there or it may not be there. But if it is there it cant be null because nillable=false. But the whole <returnURL> </returnURL> can be there or it may not be there because minOccurs=0.
My requirement is , if returnURL is there in the response with a value, then in my BPEL mapper I should map it else I should not map it.
Thats the issue.
and Yes kiran, the node be non-existant.
So can you please help me with this.
Thanks
Rajesh -
SESSION VARIABLES : HOW TO TEST FOR MULTIPLE USERS
I have a username session variable set up on a localhost testing envirnoment.
This works fine for one user, but when I open another occurence of the browser (or just another tab) to test for multiple users the system overwrites the session variable with the last username input.
So the question is:
Why doesn't dreamweaver hold an instance of the session variable for each browser session? and if not what are your suggestions?
Thanks
Adam.Thanks for that.
After scouring the internet I found the only way of running 2 instances of firefox without them sharing the session variables is to create 2 new firefox profiles in windows + set the MOZ_NO_REMOTE environment variable.
Internet explorer is much easier as it has a 'new session' option in the file menu, but seems to have more trouble displaying tables correctly.
Hope this helps anyone with a similar problem. -
How to check for null value of output parameter?
Hi guys, I get a test procedure with 2 output parameters and do nothing:
CREATE OR REPLACE PACKAGE BODY p_parameters_test AS
PROCEDURE p_null_output_basetype(p1 OUT NUMBER,p2 OUT VARCHAR2)
AS
BEGIN
DBMS_OUTPUT.PUT_LINE('DO NOTHING');
END p_null_output_basetype;
END;And I have below C# code:
cmd.CommandText = "p_parameters_test.p_null_output_basetype";
OracleParameter p1 = new OracleParameter("p1", OracleDbType.Decimal, System.Data.ParameterDirection.Output);
OracleParameter p2 = new OracleParameter("p2", OracleDbType.Varchar2, System.Data.ParameterDirection.Output);
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
try
conn.Open();
cmd.ExecuteNonQuery();
if (p1.Value==null)
Console.WriteLine("p1.Value==null");
else if (Convert.IsDBNull(p1.Value))
Console.WriteLine("Convert.IsDBNull(p1.Value)");
else
Console.WriteLine("p1 else "+p1.Value);
if (p2.Value==null)
Console.WriteLine("p2.Value==null");
else if (Convert.IsDBNull(p2.Value))
Console.WriteLine("Convert.IsDBNull(p2.Value)");
else
Console.WriteLine("p2 else "+p2.Value);
Console.WriteLine("finished");
catch......The output of it is:
p1 else null
p2 else null
Does anyone have any idea why it always goes to the 'else' of the condition-branching, and how can I check if the output parameter is null?
Thanks in advance.Morven... I ran into similar problems. Maybe you've found a solution of your own by now, but here's what I've learned...
The Value property of output parameters, like p1 and p2 in your code, actually varies, according to (I think) the OracleDbType of the parameter. You've got OracleDbType.Decimal for p1 and OracleDbType.Varchar2 for p2. These look about right, since they match the parameter types in your actual stored procedure.
After cmd.ExecuteNonQuery() executes, the respective Value properties of p1 and p2 are actually of different types. For p1, it's going to be "OracleDecimal" and for p2 it's "OracleString". Keep in miind that these are the types of the Value property of the OracleParameter objects, not the OracleParameter objects themselves.
OracleDecimal and OracleString (and some other types like OracleDate, etc.) have an "IsNull" property you can use if you cast the Value property to its runtime type...
if ((OracleDecimal)cmd.Parameters["p1"].Value).IsNull) { …do something… }
else { …do something else… }
Or maybe something like this...
Decimal p1val = ((OracleDecimal)cmd.Parameters["p1"].Value).IsNull ? 0 : ((OracleDecimal)cmd.Parameters["AVG_SALARY"].Value).Value;
I'll admit that expressions like this: ((OracleDecimal)cmd.Parameters["AVG_SALARY"].Value).Value look a little weird. But the "Value" of the "OracleDecimal" property is a regular .NET decimal type (System.Decimal). So, it's a "Value" of the "Value" property of the OracleParameter class.
Even when the stored procedure returns a null, the Value property is still populated. In the case of p1, it's populated with an OracleDecimal object (actually a struct) where IsNull is true. That's why "p1.Value==null" tests false.
From what I can see, OracleDecimal, OracleString, etc. will never be typed as DbNull, or DBNull.Value. So, that would be why Convert.IsDBNull(p1.Value)) always returns false. btw, it appears that these are Value types. That would suggest that coding something like like this, should be avoided…
OracleString p2val = ((OracleString)cmd.Parameters["p2"].Value;
if (p2val.IsNull) { …do something… }
else { …do something else… }
By assigning the value to another variable, you’d be actually creating an entire copy of the OracleString structure, which is pointless.
I hope that helps
Edited by: 897674 on Jan 3, 2012 10:44 AM
Edited by: 897674 on Jan 3, 2012 10:46 AM -
Beginner question - testing for null string from shell script command
I'm trying to test the result of a shell script command. I want to put out a message if the result is a null string. At present I get this applescript error "The command exited with a non-zero status"
I'm sure this is a simple question ... but I can't figure out how to do it. Help!You can use try clause for the problem:
set _result to ""
try
set _result to do shell script "/blah/andblah"
end -
How to check for null value/field?
Hi!
I have created a form that is designed to calculate the rows using the FormCalc function.
My problem is that if I have no value in the some of the rows, a 0 is automatically display as the calculated output field. If a row has no data, how can I get a null or blank field in the result (calculated field) field?
Let's say, I have 5 rows and each row should have a calculated value in one of the fields; when I fill out only two of the rows, the remaining three rows come out with 0s in the calculated output field. I need a blank output field for the remaining calculated values instead of 0s. I am a newbie so please excuse me if I am not explaining well.
Thanks
Jofar1This is the value that I have on my calculate event: "Rate*Units_of_ServiceRow2".
How should/can I incorporate the two codes? -
NSURL - How to test for directory (in 10.5)?
Hi,
I've used this in 10.6 to test whether the resource pointed to is a directory:
[myURL getResourceValue:&value forKey:NSURLIsDirectoryKey error:NULL];
Is there any way to achieve the same test in 10.5 or earlier? I've pored through the
docs but can''t find anything.
Thanks
SteveThanks. It works, but I'm getting a warning:
warning: passing argument 1 of 'CFURLHasDirectoryPath' from incompatible pointer type
when I pass in an NSURL instance.
From the docs:
"CFURL is “toll-free bridged” with its Cocoa Foundation counterpart, NSURL. This means that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. In other words, in a method where you see an NSURL * parameter, you can pass in a CFURLRef, and in a function where you see a CFURLRef parameter, you can pass in an NSURL instance"
( I'd also been using
[[NSFileManager defaultManager] fileExistsAtPath:[myURL path] isDirectory: &isFolder ];
but CFURLHasDirectoryPath is easier if it's safe to ignore the warning. )
Thanks
Steve -
Query of queries testing for null or empty dates
I'm having problems with this query (within a function). The
last condition in the where clause needs to check for an empty or
null date and then check against the current date (which is fine),
im aware that the syntax is wrong but wondered if someone could
correct it for me to get it working.
<cfquery name="filterQuery" dbtype="query"
maxrows="#arguments.top#">
select * from getAllSaved
where
workFlowStatusId = <cfqueryparam
cfsqltype="CF_SQL_INTEGER"
value="#application.const.WORKFLOW_LIVE#" />
and
dateArchive > <cfqueryparam cfsqltype="CF_SQL_DATE"
value="#now()#" />
and
dateLive <= <cfqueryparam cfsqltype="CF_SQL_DATE"
value="#now()#" />
and
(dateExpiry is null or dateExpiry = '') or dateExpiry >
<cfqueryparam cfsqltype="CF_SQL_DATE" value="#now()#" />
</cfquery>I feel stupid, although i'd put a fiver on having tried that!
thanks -
How to check for null int/null Date
Heres the situation, there is an interface accepting an int value and a time/date that are not required(and are not set to anything automatically, i have no control over that part unfortunately), but I need to set up some sort of null/has value type of check to execute the setter when it does have a value, and ignore it when it doesnt. I am currently getting null pointers. here is my current set up:
//throws null pointer as set up below, I am assuming I might want to eliminate the "getDate" off of the end and that might clear it up.
if(data.getDate().getTime() != null)
tempData.setDate(data.getDate().getTime());
//Not sure on this one yet, the value doesn't get set to anything so I am assuming it automatically gets assigned something like -1.
if(data.getId() >= 0){
tempData.setId(data.getId());
}tsdobbi wrote:
I know data isnt null because it goes through a bunch of other tempData.set(data.get) items prior to hitting a snag on the above date I mentioned, when there is no value input for the date. and that particular null check I do there, does not work because it throws a null pointer in the if statement itself.
i.e. it traces the null pointer to
(if data.getDate().getTime != null) //this is the line the null pointer traces to.{color:#3D2B1F}if data is not null, then it must be the case that data.getDate() is null. Now that's what I call logic. W00t!{color}
Maybe you are looking for
-
Report generation toolkit with openoffice
hello all i would like to know if it is possible to use the report generation toolkit with openoffice instead microsoft office? because i do not have the toolkit already i can't test it and i will only buy it if this is possible... i ask also because
-
How can i print from an ipad to my B109n photosmart printer
how can i print from an ipad to my B109n photosmart printer?
-
Issue about getting discount after subscribing a m...
Hi, I have subscribed a year plan and thought will get a 50% discount for a online number automatically then i payed for the online number with no discount before i realize there is no discount on the bill is there any way to get it back? get refund
-
when i try deleting pictures on my ipod touch i can not choose "selected albums" i can only choose all my albums
-
does anyone know how to import cr2 files directly from a canon 1d-mk3 into aperture. that is, without first batching photos in dpp to tiff/jpeg, but directly sending the cr2 material from camera to aperture?if you have the answer, please email to [em