📄 nullhandler.html
字号:
<html><head><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 8. Null Handler</title><link href="../docbook.css" rel="stylesheet" type="text/css"><meta content="DocBook XSL Stylesheets V1.65.0" name="generator"><link rel="home" href="index.html" title="OGNL Developer Guide"><link rel="up" href="index.html" title="OGNL Developer Guide"><link rel="previous" href="memberAccessManager.html" title="Chapter 7. Member Access"><link rel="next" href="evaluation.html" title="Chapter 9. Other API features"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table summary="Navigation header" width="100%"><tr><th align="center" colspan="3">Chapter 8. Null Handler</th></tr><tr><td align="left" width="20%"><a accesskey="p" href="memberAccessManager.html"><img src="../images/navigation/prev.gif" alt="Prev"></a> </td><th align="center" width="60%"> </th><td align="right" width="20%"> <a accesskey="n" href="evaluation.html"><img src="../images/navigation/next.gif" alt="Next"></a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="nullHandler"></a>Chapter 8. Null Handler</h2></div></div><div></div></div><p>When navigating a chain sometimes properties or methods will evaluate to null, causing subsequent properties or method calls to fail with <tt class="classname">NullPointerException</tt>s. Most of the time this behaviour is correct (as it is
with Java), but sometimes you want to be able to dynamically substitute another object in place of <tt class="constant">null</tt>. The <tt class="classname">NullHandler</tt> interface allows you to specify on a class-by-class basis how nulls are
handled within OGNL expressions. Implementing this interface allows you to intercept when methods return <tt class="constant">null</tt> and properties evaluate to <tt class="constant">null</tt> and allow you to substitute a new value. Since you are
given the source of the method or property a really clever implementor might write the property back to the object so that subsequent invocations do not return or evaluate to <tt class="constant">null</tt>.</p><pre class="programlisting">public interface NullHandler
{
public Object nullMethodResult(Map context, Object target, String methodName, List args);
public Object nullPropertyValue(Map context, Object target, Object property);
}</pre><p><tt class="classname">NullHandler</tt> implementors are registered with <span class="acronym">OGNL</span> using the <tt class="function">OgnlRuntime.setNullHandler()</tt> method.</p></div><div class="navfooter"><hr><table summary="Navigation footer" width="100%"><tr><td align="left" width="40%"><a accesskey="p" href="memberAccessManager.html"><img src="../images/navigation/prev.gif" alt="Prev"></a> </td><td align="center" width="20%"><a accesskey="u" href="index.html"><img src="../images/navigation/up.gif" alt="Up"></a></td><td align="right" width="40%"> <a accesskey="n" href="evaluation.html"><img src="../images/navigation/next.gif" alt="Next"></a></td></tr><tr><td valign="top" align="left" width="40%">Chapter 7. Member Access </td><td align="center" width="20%"><a accesskey="h" href="index.html"><img src="../images/navigation/home.gif" alt="Home"></a></td><td valign="top" align="right" width="40%"> Chapter 9. Other API features</td></tr></table></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -