5 Replies Latest reply on Aug 31, 2010 12:30 AM by lam nguyen phuc

    NewEntryNotAllowedException happened when accessing Managed Bean property.

    lam nguyen phuc Newbie

      I got this exception when I tried to get the selectionString property of TBean backing bean (its scope is session). My test case looks like this:

       

       

       

      public class ScrollableDataTableTest extends ServletTestCase {
       
          public static TestSuite suite() {
              TestSuite suite = new TestSuite(ScrollableDataTableTest.class);
              return suite;
          }
       
       
          public void testWhenThereAreMoreThanOneRow() throws IOException {
              JSFSession jsfSession = createJSFSession("/scrollableDataTableTest.jsf");
              JSFClientSession clientSession = jsfSession.getJSFClientSession();
              JSFServerSession serverSession = jsfSession.getJSFServerSession();
       
              jsfSession.getWebClient().setAjaxController(new NicelyResynchronizingAjaxController());
       
              // create one row on the table
              clientSession.setValue("rowNum", "2");
              // submit form
              clientSession.click("rowGenerator");
       
              //click the first row of the table
              HtmlTable tbl = (HtmlTable) clientSession.getElement("n");
              //assert table number of row
              assertEquals(tbl.getRowCount(), 2);
              HtmlTableRow row = tbl.getRow(1);
       
              row.click();
       
              TestBackingBean t = (TestBackingBean) serverSession.getManagedBeanValue("#{Tbean.selectionString}");
              System.out.println("String: " + t.getSelectionString());
       
              //click the get table selection button
              clientSession.click("rowSelector");
          }
       
          private JSFSession createJSFSession(String url) throws IOException {
              WebClientSpec wcSpec = new WebClientSpec(url, BrowserVersion.FIREFOX_3);
              wcSpec.getWebClient().setThrowExceptionOnFailingStatusCode(false);
              wcSpec.getWebClient().setThrowExceptionOnScriptError(false);
              JSFSession jsfSession = new JSFSession(wcSpec);
              return jsfSession;
          }
      }
      
      
      

       

      My facelets page looks like this:

       

       

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:rich="http://richfaces.org/rich"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:a4j="http://richfaces.org/a4j">
          <head>
              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
              <title>TODO supply a title</title>
          </head>
          <body>
              <ui:composition template="/template.xhtml">
                  <ui:define name="body">
                      <h:form id="testFrm">
                          <rich:scrollableDataTable
                              id="testTbl"
                              selection="#{Tbean.selection}"
                              value="#{Tbean.products}"
                              var="product"
                              rowKeyVar="tidx">
                              <a4j:support event="onRowClick" reRender="sString">
                                  <f:setPropertyActionListener target="#{Tbean.selectionString}" value="Generated by onclick"/>                            
                              </a4j:support>
                              <rich:column>
                                  <f:facet name="header">
                                      <h:outputText value="Code"/>
                                  </f:facet>
                                  <h:outputText value="#{product.code}"/>
                              </rich:column>
                              <rich:column>
                                  <f:facet name="header">
                                      <h:outputText value="Name"/>
                                  </f:facet>
                                  <h:outputText value="#{product.name}"/>
                              </rich:column>
                          </rich:scrollableDataTable>
                          <h:panelGrid columns="2">
                              <h:inputText value="#{Tbean.generatedRows}" id="rowNum"/>
                              <a4j:commandButton value="Generate Table Content"
                                                 actionListener="#{Tbean.generateTableContent}"
                                                 reRender="testTbl"
                                                 id="rowGenerator"/>
                              <h:outputText value="Selection : #{Tbean.selectionString}" id="sString"/>
                              <a4j:commandButton value="Get Table Selection"
                                                 actionListener="#{Tbean.computeSelection}"
                                                 reRender="sString"
                                                 id="rowSelector"/>
                          </h:panelGrid>
                      </h:form>
                  </ui:define>
              </ui:composition>
          </body>
      </html>
      

       

      I have tried to debug what caused the problem and I found out that on the server side, JSF tried to create another instance of the BackingBean and added it to the sessionMap. However, because the session map of JSFUnit is an instance of NoNewEntryMap, the exception was thrown. Has anyone bumped into the same problem? I use Myfaces 1.2.2, Richfaces 3.3.3.Final.