myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ondrej Svetlik (JIRA)" <...@myfaces.apache.org>
Subject [jira] Created: (TOMAHAWK-450) inputHtml component without a form produces NotNullException - it is able to warn
Date Sat, 27 May 2006 19:56:29 GMT
inputHtml component without a form produces NotNullException - it is able to warn
---------------------------------------------------------------------------------

         Key: TOMAHAWK-450
         URL: http://issues.apache.org/jira/browse/TOMAHAWK-450
     Project: MyFaces Tomahawk
        Type: Bug

  Components: Html Editor  
    Versions: 1.1.3-SNAPSHOT    
 Environment: Doesn't matter
    Reporter: Ondrej Svetlik


Try to use <t:inputHtml /> outside a form, you'll get this:

java.lang.NullPointerException
at org.apache.myfaces.custom.inputHtml.InputHtmlRenderer.encodeEndNormalMode(InputHtmlRenderer.java:235)
at org.apache.myfaces.custom.inputHtml.InputHtmlRenderer.encodeEnd(InputHtmlRenderer.java:87)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:536)
... and so on

File affected is:
http://svn.apache.org/repos/asf/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/inputHtml/InputHtmlRenderer.java

The code is:

    private void encodeEndNormalMode(FacesContext context, InputHtml editor) throws IOException
{
        String clientId = editor.getClientId(context);
        String formId;
        {
            UIComponent tmpComponent = editor.getParent();
            while(!(tmpComponent instanceof UIForm) ){
                tmpComponent = tmpComponent.getParent();
            }
            formId = tmpComponent.getClientId(context);
        }

This is a simple fix that would have spared me a few nightmarish hours:

    private void encodeEndNormalMode(FacesContext context, InputHtml editor) throws IOException
{
        String clientId = editor.getClientId(context);
        String formId;
        {
            UIComponent tmpComponent = editor.getParent();
            while((tmpComponent != null) && !(tmpComponent instanceof UIForm) ){
                tmpComponent = tmpComponent.getParent();
            }
            if (tmpComponent == null) {
            	log.warn("The inputHtml component must be within a form, giving up!");
            	return;
            }
            formId = tmpComponent.getClientId(context);
        }

Or if you like svn diff better:

--- InputHtmlRenderer.java      (revision 409862)
+++ InputHtmlRenderer.java      (working copy)
@@ -231,9 +231,13 @@
         String formId;
         {
             UIComponent tmpComponent = editor.getParent();
-            while(!(tmpComponent instanceof UIForm) ){
+            while((tmpComponent != null) && !(tmpComponent instanceof UIForm) ){
                 tmpComponent = tmpComponent.getParent();
             }
+            if (tmpComponent == null) {
+               log.warn("The inputHtml component must be within a form, giving up!");+  
            return;
+            }
             formId = tmpComponent.getClientId(context);
         }


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Mime
View raw message