5 Replies Latest reply on Jul 17, 2007 5:39 PM by Robert Lin

    a4j:include question

    Robert Lin Newbie

      Sorry, I'm new to Ajax4jsf and this may be a trivial question - I'm under the impression that a4j include is supposed to help me re-render a part of the page to a new page depending on the navigation rule. So if my /pages/main.jsp contains something like this -

      <a4j:region id="myRegion">
       <h:panelGroup id="myPanelGroup">
       <a4j:include viewId="/pages/sub1.jsp" />

      And my faces-config contains the navigation rule -
       <description>My Description</description>

      And /pages/sub1.jsp contains this commandButton -
      <a4j:commandButton id="myAJAXButton"
       value="My Button">

      and myBean.action() does some processing and returns the string "result", which means "myPanelGroup" should be re-rendered to include /pages/sub2.jsp. Is that correct?

      However, the behavior I see is that the "myPanelGroup" get re-rendered with the same /pages/sub1.jsp, any ideas why this is happening? Thanks.

      Robert Lin
      Software Engineer

        • 1. Re: a4j:include question
          Sergey Smirnov Master

          You do not need to reRender myPanelGroup explicitly. I.e. remove reRender.
          What else /pages/sub1.jsp has? It might be important to find the reason. Are you sure the action method is invoked?

          • 2. Re: a4j:include question
            Robert Lin Newbie

            Hi Sergey,

            I'll post my complete code. Here it is -

            This is my main page called myReports.jsp -

            <%@ page errorPage="/error" %>
            <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
            <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
            <%@ taglib uri="http://myfaces.apache.org/extensions" prefix="x"%>
            <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
            <%-- Load Resource Bundles --%>
            <f:loadBundle basename="InquiryCenterMessages" var="bundle" />
            <f:loadBundle basename="HelpLocations" var="helpBundle" />
            <a4j:log level="ALL" popup="true" name="_blank" hotkey="y"/>
            <div id="rptCntNvDv" class="contentnav">
             <h:outputText id="NvPgTtlTxt" value="#{message.my_reports_page_title}"/>
             <%@ include file="/WEB-INF/jspf/tiles/reports/myReportsContentNav.jspf" %>
             <form id="rptCntFrm" >
             <div id="rptCntMnDv" class="contentmain">
             <div id="rptCntMnPnTtlDv" class="panetitle">
             <h:outputText id="PnTtlSelRptTxt" value="#{myReportsBean.selectedReport.title}"/>
             <div id="MnPnTtlDtlsDv" class="details">
             <h:panelGroup id="myPanelGroup">
             <a4j:include viewId="/reports/myReportExecuteContent.jsp" />

            And here is the a4j:include page myReportExecuteContent.jsp -
            <%@ page buffer="none" errorPage="/error" %> <%-- No buffer required to included JSF pages. Alternative to verbatim tags --%>
            <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
            <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
            <%@ taglib uri="http://myfaces.apache.org/extensions" prefix="x"%>
            <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
            <f:loadBundle basename="InquiryCenterMessages" var="message"/>
            <div id="ExDtlsHdrDv2" class="sectionheader"><span class="title"><h:outputText id="HdrSttngLblTxt" value="#{message.my_reports_form_report_settings_label}"/></span></div>
             <div id="ExDtlsCntDv2" class="sectioncontent">
             <table id="CntTbl" class="formtable">
             <tr id="CntTblRw" >
             <td id="CntTblRwLblCol" class="label">
             <h:outputText id="CntTblRwShLblTxt" value="#{message.my_reports_form_show_label}"/>
             <td id="CntTblRw2LblCol" class="label">
             <h:outputText id="CntTblRw2FrmBLblTxt" value="#{message.my_reports_form_between_label}"/>
             <td id="CntTblRw2InCol" class="input">
             <h:outputText id="CntTblRw2FrmLblTxt" value="#{message.my_reports_form_and_label}"/>
            <a4j:commandButton id="execReportLink" action="#{reportExecutionBean.executeReport}" actionListener="#{myReportsBean.onExecuteReport}" type="button" value="#{message.my_reports_form_run_report_button_label}"/>

            my faces-config file contains the following navigation case -
             <description>Navigates to the report execution detail results page</description>

            And the action binding for the a4j:commandButton reportExecutionBean.executeReport contains only the following code -
            return "detailResults";

            which is the from-outcome for the navigation case

            And I'm positive that the action is invoked, I've set a breakpoint there and it does hit everytime I click the command button

            Any ideas? Appreciate the help.

            Robert Lin

            • 3. Re: a4j:include question
              Robert Lin Newbie

              I've debugged into IncludeTag.doStartTag() and it seems like when I click on the command button the first two times, the viewId is still the original page, but the third click I get the correct viewId, however I get a NullPointerException inside AjaxViewHandler.restoreView() when it is calling externalContext.redirect(actionURL).

              Has anyone seen this before? I'm using Ajax4jsf 1.1.0 and JSF 1.1

              Any help would be greatly appreciated. Thanks.


              • 4. Re: a4j:include question
                Ilya Shaikovsky Master

                I think ajax4jsf 1.1.0 is too old. To many bugs has been fixed from that time.

                Also check if you have jsf 1.1_02. 1.1_01 is too buggy.

                • 5. Re: a4j:include question
                  Robert Lin Newbie

                  Ok, I got jsf 1.1_02 and ajax4jsf 1.1.1. I got around my initial problem by explicitly specifying an id for the <a4j:include> tag.

                  However, I've ran into a new problem -

                  for some reason when the command button on the included page is clicked, AjaxViewHandler.restoreView() is called with the viewId of the targeted page for the include. On line 150 of AjaxViewHandler, the ViewHandler attemps to restore view and retrieve the viewRoot. However, since this targeted page has never been loaded before, the viewRoot will be null, and on line 154 the if statement will be true, and eventually at line 180 there will be a redirect with the targeted page as the actionURL. This basically is throwing an IllegalStateException. Why is this happening?

                  Any ideas? Thanks.