8 Replies Latest reply on Dec 1, 2009 2:33 PM by ssilvert

    Server#getManagedBeanValue not working

    b.faissal

      Hi ,
      I'm using MyFaces 1.2.7

      I tried toi mplements the exemple in http://labs.jboss.com/jsfunit/gettingstarted.html by I have always

      server.getManagedBeanValue("#{foo.text}")
      null

      What could be the problem ?

      This is my wEb.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
       <context-param>
       <param-name>javax.faces.CONFIG_FILES</param-name>
       <param-value>/WEB-INF/faces-config.xml</param-value>
       </context-param>
       <context-param>
       <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
       <param-value>client</param-value>
       </context-param>
       <filter>
       <filter-name>JSFUnitFilter</filter-name>
       <filter-class>org.jboss.jsfunit.framework.JSFUnitFilter</filter-class>
       </filter>
      
       <filter-mapping>
       <filter-name>JSFUnitFilter</filter-name>
       <servlet-name>ServletTestRunner</servlet-name>
       </filter-mapping>
      
       <filter-mapping>
       <filter-name>JSFUnitFilter</filter-name>
       <servlet-name>ServletRedirector</servlet-name>
       </filter-mapping>
      
       <servlet>
       <servlet-name>ServletRedirector</servlet-name>
       <servlet-class>org.jboss.jsfunit.framework.JSFUnitServletRedirector</servlet-class>
       </servlet>
      
       <servlet>
       <servlet-name>ServletTestRunner</servlet-name>
       <servlet-class>org.apache.cactus.server.runner.ServletTestRunner</servlet-class>
       </servlet>
      
       <servlet-mapping>
       <servlet-name>ServletRedirector</servlet-name>
       <url-pattern>/ServletRedirector</url-pattern>
       </servlet-mapping>
      
       <servlet-mapping>
       <servlet-name>ServletTestRunner</servlet-name>
       <url-pattern>/ServletTestRunner</url-pattern>
       </servlet-mapping>
      
       <servlet>
       <servlet-name>Faces Servlet</servlet-name>
       <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
       <load-on-startup>0</load-on-startup>
       </servlet>
       <servlet-mapping>
       <servlet-name>Faces Servlet</servlet-name>
       <url-pattern>/faces/*</url-pattern>
       </servlet-mapping>
       <servlet-mapping>
       <servlet-name>Faces Servlet</servlet-name>
       <url-pattern>*.faces</url-pattern>
       </servlet-mapping>
       <welcome-file-list>
       <welcome-file>index.jsp</welcome-file>
       </welcome-file-list>
      </web-app>
      




        • 1. Re: Server#getManagedBeanValue not working
          ssilvert

          Please post the full java code for your test class and your jsp or xhtml markup.

          If you want, you can download a working example from here:
          http://www.jboss.org/community/wiki/GettingStartedGuide

          Stan

          • 2. Re: Server#getManagedBeanValue not working

            Hi,
            I have this problem too in Seam 2.2.0-GA with jsfUnit 1.1.0-GA, HtmlUnit 2.5. Result of "#{seamconversation.hotel}" is null. It used to work with jsfUnit 1.0.0-GA-SNAPSHOT, but I'd like to use newer version. So how I can get objects from conversation context? Is there some workaround?

            Petr.

            • 3. Re: Server#getManagedBeanValue not working

              Hi there. I'm afraid I'm having the same problem after upgrading to 1.1.0.GA. All the backing beans return a null. If I go back to 1.0.0.GA the getManagedBeanValue method returns the result I expect.

              It looks like it may be related to this:
              https://jira.jboss.com/jira/browse/JSFUNIT-226

              I can post more details if you need them.

              • 4. Re: Server#getManagedBeanValue not working
                ssilvert

                Hi All,

                Please note that the change made in http://jira.jboss.com/jira/browse/JSFUNIT-226 can cause tests to fail that used to pass in JSFUnit 1.0.0.

                However, if you look closely you will see that these tests should not have passed in JSFUnit 1.0.0. That is, getManagedBeanValue() returned a newly created object when it should have returned null.

                Please post details if you are sure that your problem is not due to the above fix.

                Regards,

                Stan

                • 5. Re: Server#getManagedBeanValue not working

                  Hi Stan,

                  I'm running this on Websphere CE 2.1 with richfaces.

                  When I run the test on 1.0.0 I get this output:
                  running testWelcomePage
                  name is null
                  Clicked login
                  name is Billy

                  When I replace the jars with the 1.1.0 versions I get this:
                  running testWelcomePage
                  name is null
                  Clicked login
                  name is null

                  I'm not quite sure why this is happening. Any advice would be much appreciated.

                  Here's the test class:
                  public class UserTest extends org.apache.cactus.ServletTestCase {
                  private JSFClientSession client;
                  private JSFServerSession server;

                  public static Test suite() {
                  TestSuite testSuite = new TestSuite (UserTest.class);
                  return testSuite;
                  }

                  public void setUp() throws IOException {
                  WebClientSpec wcSpec = new WebClientSpec("/faces/index.jsp");
                  JSFSession jsfSession = new JSFSession(wcSpec);
                  this.client = jsfSession.getJSFClientSession();
                  this.server = jsfSession.getJSFServerSession();
                  }

                  public void testWelcomePage() throws IOException {
                  System.out.println("running testWelcomePage");
                  System.out.println("name is " + server.getManagedBeanValue("#{ testBean.username }"));

                  client.click("login");

                  System.out.println("name is " + server.getManagedBeanValue("#{ testBean.username }"));

                  assertTrue(true);
                  }
                  }

                  Here's the backing bean:
                  public class TestBean {

                  private String username;
                  private String password;
                  public String getUsername() {
                  return username;
                  }
                  public void setUsername(String username) {
                  this.username = username;
                  }
                  public String getPassword() {
                  return password;
                  }
                  public void setPassword(String password) {
                  this.password = password;
                  }

                  public String login() {
                  setUsername("Billy");
                  System.out.println("Clicked login");
                  return("OK");
                  }

                  }


                  And just for completeness here's the jsp:
                  <%@ page language="java" contentType="text/html; charset=UTF-8"
                  pageEncoding="UTF-8"%>
                  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
                  <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
                  <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>


                  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                  Insert title here


                  <f:view>
                  <h:form id="form1">

                  <h:outputText value="Enter your name:" id="prompt"/>

                  <h:inputText value="#{testBean.username}" id="username"/>
                  <h:inputText value="#{testBean.password}" id="password"/>



                  <h:commandButton value="Submit" action="#{testBean.login}" id="login"/>

                  </h:form>
                  </f:view>

                  • 6. Re: Server#getManagedBeanValue not working
                    ssilvert

                    Hi skruffy,

                    Your example looks good and it should work. I know that getManagedBeanValue is not broken on my end. The only thing that jumps out at me is that you are using Websphere CE. I don't have that server as part of my test suite. Perhaps you can try it on Tomcat or something?

                    Can you create a jira for this at https://jira.jboss.org/jira/browse/JSFUNIT?

                    Then post as much code as you can for your failing example. A full maven project would be ideal.

                    Thanks,

                    Stan

                    • 7. Re: Server#getManagedBeanValue not working

                      Hi again,

                      I created a jira for you. The WebSphereCE server is based on Geronimo, so I think it uses Tomcat already. I'll try it on a vanilla tomcat build next.

                      Interestingly I deployed the same test on a full WebSphere 7.0 server (with the workaround posted here: http://www.jboss.org/community/wiki/JSFUnitOnWebSphere) which gave me the same results as for CE:

                      running testWelcomePage
                      name is null
                      Clicked login
                      name is null

                      I have a sneaking suspicion that either IBM have done something weird (although it doesn't look like they changed much of the Geronimo server apart from rebadge it) or I'm doing something wrong...

                      Skruffy

                      • 8. Re: Server#getManagedBeanValue not working
                        ssilvert

                        Got it. I asked for some more info.

                        https://jira.jboss.org/jira/browse/JSFUNIT-234