6 Replies Latest reply: Mar 1, 2013 4:34 PM by jmsjr RSS

    Action for commented out h:commandButton is being executed on page load

    jmsjr
      Mojarra 2.1.7-jbossorg
      JBoss 7.1.1

      This is weird. I have the following piece of code that I have temporarily commented out
                <!--h:commandButton
                      id="supremeCourtTribunalDecision"
                      type="button"
                      immediate="true"
                      value="Supreme Court Tribunal Decision"
                      image="/resources/images/Plus.gif"
                      rendered="#{!caseFormStateManager.claimStakingFormState.renderSupremeCourtTribunalDecisionButton(insuranceCase)}" 
                      action="#{caseFormStateManager.claimStakingFormState.triggerSupremeCourtTribunalDecisionButton(insuranceCase)}">
                      <f:ajax render="claimStakingDetails currentPercentagesMouseOver currentPercentagesMouseOut"/>
                </h:commandButton-->
      However, it seems that the action method in the above is being executed as I load the page.

      When I put a break-point on the action method, I get the following stack trace ( Notice the line the says "CommentInstruction.write(FacesContext) line: 77" )
      Daemon Thread [http--0.0.0.0-8081-3] (Suspended (breakpoint at line 36 in ClaimStakingFormState))     
           ClaimStakingFormState.triggerSupremeCourtTribunalDecisionButton(InsuranceCase) line: 36     
           NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]     
           NativeMethodAccessorImpl.invoke(Object, Object[]) line: 57     
           DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43     
           Method.invoke(Object, Object...) line: 601     
           BeanELResolver.invokeMethod(Method, Object, Object[]) line: 735     
           BeanELResolver.invoke(ELContext, Object, Object, Class<?>[], Object[]) line: 467     
           DemuxCompositeELResolver(CompositeELResolver).invoke(ELContext, Object, Object, Class<?>[], Object[]) line: 246     
           AstValue.getValue(EvaluationContext) line: 159     
           ValueExpressionImpl.getValue(ELContext) line: 189     
           ELText$ELTextVariable.toString(ELContext) line: 217     
           ELText$ELTextComposite.toString(ELContext) line: 157     
           CommentInstruction.write(FacesContext) line: 77     
           UIInstructions.encodeBegin(FacesContext) line: 82     
           UIInstructions(UILeaf).encodeAll(FacesContext) line: 183     
           PanelRenderer(RendererBase).renderChildren(FacesContext, UIComponent) line: 276     
           PanelRenderer.encodeEnd(FacesContext, UIComponent) line: 181     
           UIPanel(UIComponentBase).encodeEnd(FacesContext) line: 875     
           UIPanel(UIComponent).encodeAll(FacesContext) line: 1786     
           UIGraphValidator(UIComponent).encodeAll(FacesContext) line: 1782     
           UIDisablePanelComponent(UIComponent).encodeAll(FacesContext) line: 1782     
           TabRenderer(RendererBase).renderChildren(FacesContext, UIComponent) line: 276     
           TabRenderer(TogglePanelItemRenderer).doEncodeChildren(ResponseWriter, FacesContext, UIComponent) line: 136     
           TabRenderer.doEncodeChildren(ResponseWriter, FacesContext, UIComponent) line: 107     
           TabRenderer(RendererBase).encodeChildren(FacesContext, UIComponent) line: 157     
           UITab(UIComponentBase).encodeChildren(FacesContext) line: 845     
           UITab(UIComponent).encodeAll(FacesContext) line: 1779     
           TabPanelRenderer(RendererBase).renderChildren(FacesContext, UIComponent) line: 276     
           TabPanelRenderer(TogglePanelRenderer).doEncodeChildren(ResponseWriter, FacesContext, UIComponent) line: 127     
           TabPanelRenderer(RendererBase).encodeChildren(FacesContext, UIComponent) line: 157     
           UITabPanel(UIComponentBase).encodeChildren(FacesContext) line: 845     
           UITabPanel(UIComponent).encodeAll(FacesContext) line: 1779     
           PanelRenderer(RendererBase).renderChildren(FacesContext, UIComponent) line: 276     
           PanelRenderer.encodeEnd(FacesContext, UIComponent) line: 181     
           UIPanel(UIComponentBase).encodeEnd(FacesContext) line: 875     
           UIPanel(UIComponent).encodeAll(FacesContext) line: 1786     
           FormRenderer(Renderer).encodeChildren(FacesContext, UIComponent) line: 168     
           HtmlForm(UIComponentBase).encodeChildren(FacesContext) line: 845     
           HtmlForm(UIComponent).encodeAll(FacesContext) line: 1779     
           UIOutput(UIComponent).encodeAll(FacesContext) line: 1782     
           UIViewRoot(UIComponent).encodeAll(FacesContext) line: 1782     
           FaceletViewHandlingStrategy.renderView(FacesContext, UIViewRoot) line: 402     
           MultiViewHandler.renderView(FacesContext, UIViewRoot) line: 125     
           GlobalResourcesViewHandler(ViewHandlerWrapper).renderView(FacesContext, UIViewRoot) line: 288     
           RenderResponsePhase.execute(FacesContext) line: 121     
           RenderResponsePhase(Phase).doPhase(FacesContext, Lifecycle, ListIterator<PhaseListener>) line: 101     
           LifecycleImpl.render(FacesContext) line: 139     
           FacesServlet.service(ServletRequest, ServletResponse) line: 594     
           ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 329     
           ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 248     
           StandardWrapperValve.invoke(Request, Response) line: 275     
           StandardContextValve.invoke(Request, Response) line: 161     
           SecurityContextAssociationValve.invoke(Request, Response) line: 153     
           StandardHostValve.invoke(Request, Response) line: 155     
           ErrorReportValve.invoke(Request, Response) line: 102     
           AccessLogValve.invoke(Request, Response) line: 567     
           StandardEngineValve.invoke(Request, Response) line: 109     
           CoyoteAdapter.service(Request, Response) line: 368     
           Http11Processor.process(Socket) line: 877     
           Http11Protocol$Http11ConnectionHandler.process(Socket) line: 671     
           JIoEndpoint$Worker.run() line: 930     
           Thread.run() line: 722     
      From the above stack trace, if I go and look at the value of CommentInstruction.text.txt, the String output is the h:commandButton that is commented out!

      [h:commandButton
                      id="supremeCourtTribunalDecision"
                      type="button"
                      immediate="true"
                      value="Supreme Court Tribunal Decision"
                      image="/resources/images/Plus.gif"
                      rendered=", #{!caseFormStateManager.claimStakingFormState.renderSupremeCourtTribunalDecisionButton(insuranceCase)}, " 
                      action=", #{caseFormStateManager.claimStakingFormState.triggerSupremeCourtTribunalDecisionButton(insuranceCase)}, ">
                      <f:ajax render="claimStakingDetails currentPercentagesMouseOver currentPercentagesMouseOut"/>
                </h:commandButton]
      So I thought:

      1) Maybe JBoss still has the old version of the XHTML page where the commandButton is NOT commented out. So I touched the file, still the same. Restarted JBoss, still the same.

      2) What if I completey remove the commented out code ? Did that, and of course, the problem above no longer happens. Put back the commented out code, and it happens again.

      3) What if I UNcomment the commented out code. Did that, and the problem above no longer happens.

      So from the above, there appears to be a bug when dealing when dealing with comments

      There are two issues here:

      A) The commented out code should be ignored.

      B) Even if it was not ignored, why was the method being called still ... since the method should only be called when I click the button as it is the EL expression of the action attribute .. which I have not clicked since the page was being loaded.

      I'll try to create a very simple test case ... but has anyone seen this before ?

      Edited by: jmsjr on 28-Feb-2013 22:24

      Edited by: jmsjr on 28-Feb-2013 22:26

      Edited by: jmsjr on 28-Feb-2013 22:27
        • 1. Re: Action for commented out h:commandButton is being executed on page load
          r035198x
          That's how facelets behave, they ignore comments when building the the JSF component tree by default.
          To make it skip comments add
           <context-param>
                  <param-name>facelets.SKIP_COMMENTS</param-name>
                  <param-value>true</param-value>
              </context-param>
          to your web.xml. Alternatively you can use the <ui:remove> tag for the comments. I would still suggest setting the facelets.SKIP_COMMENTS parameter regardless.
          • 2. Re: Action for commented out h:commandButton is being executed on page load
            jmsjr
            r035198x wrote:
            That's how facelets behave, they ignore comments when building the the JSF component tree by default.
            To make it skip comments add
            <context-param>
            <param-name>facelets.SKIP_COMMENTS</param-name>
            <param-value>true</param-value>
            </context-param>
            to your web.xml. Alternatively you can use the <ui:remove> tag for the comments. I would still suggest setting the facelets.SKIP_COMMENTS parameter regardless.
            OK .. that makes some sense ... but evaluating the EL expressions even for an action ( not value ) attribute ??
            • 3. Re: Action for commented out h:commandButton is being executed on page load
              r035198x
              jmsjr wrote:

              OK .. that makes some sense ... but evaluating the EL expressions even for an action ( not value ) attribute ??
              I suppose at the end of the day value expressions still call methods so the difference isn't much. I do think the default should have been to skip comments rather than not to!
              • 4. Re: Action for commented out h:commandButton is being executed on page load
                jmsjr
                r035198x wrote:
                jmsjr wrote:

                OK .. that makes some sense ... but evaluating the EL expressions even for an action ( not value ) attribute ??
                I suppose at the end of the day value expressions still call methods so the difference isn't much. I do think the default should have been to skip comments rather than not to!
                Although the web.xml context-parameter fixes the issues, I'll mark this thread as answered, but I beg to differ that there isn't much difference.

                The method on the action attribute should only be called ... in this case ...when the button is clicked.

                That is, whether it was commented out or not, the method on the action attribute should NOT have been called UNLESS I click on the button. I have another h:commandButton just beside the one that was commented out, and the method on THAT one is not called unless I click the button.
                • 5. Re: Action for commented out h:commandButton is being executed on page load
                  r035198x
                  I see what you mean, could be that the way the page is structured with the commented code added makes facelets think that your expression is for a value not an action.
                  • 6. Re: Action for commented out h:commandButton is being executed on page load
                    jmsjr
                    r035198x wrote:
                    I see what you mean, could be that the way the page is structured with the commented code added makes facelets think that your expression is for a value not an action.
                    After thinking about it more ... I think I know what happened / happens when you have a comment.

                    I was assuming, incorrectly, that the parser KNEW that the commented out code was an h:commandButton, and that the EL expression is for an action attribute.
                    What I believe is happening is that, if that context-parameter in WEB-INF is false, and it encounters a comment, it just looks for any EL expressions within the comment, and executes / evaluates them . It does not care or know that it was commenting out an h:commandButton.

                    Thus, a simple:
                    <!-- "#{someELexpressionhere}" -->
                    would have evaluated the EL expression.