2

So I'm very new to JSF, I just started using it a few days ago and I'm trying to learn off of youtube tutorials and a couple of books. But I can't tell why this isn't working. Here's my code:

    <h:form styleClass="formStyle">
        <h1>Log In</h1>
        <fieldset id="inputs">
            <h:inputText id="username" type="text"  value="#{redirectBean.name}">
            </h:inputText>
            <h:inputSecret id="password" type="password"  value="#{redirectBean.password}">
            </h:inputSecret>
        </fieldset>
        <fieldset id="actions">
            <h:button type="submit" styleClass="test" value="Log in" outcome="#{redirectBean.login}">
            </h:button>
        </fieldset>
    </h:form>

redirectBean.java is simply a class containing 3 private strings (login="welcome", name and password) and their getters/setters.

Upon clicking the Login button I am redirected to welcome.xhtml but there are no changes made to redirectBean.name or redirectBean.password.

Any thoughts? What am I missing?

Edit: so BalusC has explained that I need to use h:commandButton instead, but that wasn't redirecting me. After some back-and-forth trying to figure out why, this is the server log I'm currently getting (It's redirecting me now with the command button but still not passing the value to the bean. I also got something about RI and MyFaces conflicting, but some tinkering in the classpath seems to have fixed that):

SEVERE: ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException:
java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
org.apache.myfaces.webapp.StartupServletContextListener     at
org.apache.catalina.core.StandardContext.start(StandardContext.java:5332)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:498)   at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
    at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
    at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
    at
com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2018)
    at
com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
    at
com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at
org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at
com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at
com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at
org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
    at
com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
    at
com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
    at
com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
    at
com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
    at
com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
    at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at
com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)     at
com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at
com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:662) Caused by:
java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
org.apache.myfaces.webapp.StartupServletContextListener     at
org.apache.catalina.core.StandardContext.addListener(StandardContext.java:2743)
    at
org.apache.catalina.core.StandardContext.addApplicationListener(StandardContext.java:1966)
    at
com.sun.enterprise.web.TomcatDeploymentConfig.configureApplicationListener(TomcatDeploymentConfig.java:235)
    at
com.sun.enterprise.web.TomcatDeploymentConfig.configureWebModule(TomcatDeploymentConfig.java:94)
    at
com.sun.enterprise.web.WebModuleContextConfig.start(WebModuleContextConfig.java:274)
    at
com.sun.enterprise.web.WebModuleContextConfig.lifecycleEvent(WebModuleContextConfig.java:172)
    at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:149)
    at
org.apache.catalina.core.StandardContext.start(StandardContext.java:5329)
    ... 39 more Caused by: java.lang.ClassNotFoundException:
org.apache.myfaces.webapp.StartupServletContextListener     at
org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1509)
    at
org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359)
    at
org.apache.catalina.core.StandardContext.loadListener(StandardContext.java:4806)
    at com.sun.enterprise.web.WebModule.loadListener(WebModule.java:1599)
    at
org.apache.catalina.core.StandardContext.addListener(StandardContext.java:2740)
    ... 46 more

WARNING: java.lang.IllegalStateException: ContainerBase.addChild:
start: org.apache.catalina.LifecycleException:
java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
org.apache.myfaces.webapp.StartupServletContextListener
java.lang.IllegalStateException: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException:
java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
org.apache.myfaces.webapp.StartupServletContextListener     at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:921)
    at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
    at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
    at
com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2018)
    at
com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
    at
com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at
org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at
com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at
com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at
org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
    at
com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
    at
com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
    at
com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
    at
com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
    at
com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
    at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at
com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)     at
com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at
com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:662)

SEVERE: Exception while invoking class
com.sun.enterprise.web.WebApplication start method
java.lang.Exception: java.lang.IllegalStateException:
ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
org.apache.myfaces.webapp.StartupServletContextListener     at
com.sun.enterprise.web.WebApplication.start(WebApplication.java:138)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at
org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at
com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at
com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at
org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
    at
com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
    at
com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
    at
com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
    at
com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
    at
com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
    at
com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
    at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at
com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)     at
com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at
com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:662)

SEVERE: Exception while loading the app SEVERE: Exception while
loading the app : java.lang.IllegalStateException:
ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
org.apache.myfaces.webapp.StartupServletContextListener
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Skates
  • 23
  • 1
  • 4
  • Welcome to the site. I know you've stated your RedirectBean is a POJO, but could you post that code as well; it may be helpful to see your annotations especially. Also, what implementation and version of JSF are you using (i.e. Mojarra 2.0, MyFaces 2.1, etc..)? – cobaltduck Jun 23 '12 at 14:22

1 Answers1

2

You need to use <h:commandButton>, not <h:button>. The <h:button> merely sends a GET request, while the <h:commandButton> submits the form by POST.

<h:commandButton styleClass="test" value="Log in" action="#{redirectBean.login}" />

with

public String login() {
    // Do your business job.

    return "welcome";
}

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I tried commandButton but I wasn't being redirected at all. After reading the answers for that particular problem and getting confused, I figured I'd try with button. – Skates Jun 23 '12 at 14:34
  • Note that you should be using `action` attribute which is bound to an action method, not a property. Use exactly the code as shown in my answer. – BalusC Jun 23 '12 at 14:38
  • I'm still not getting redirected. "login" is now a method which returns "welcome" in the .java file, I'm calling it with the action parameter from the h:commandButton. "welcome.xhtml" is in the same folder as "login.xhtml" (I gather that was a problem for some versions or glassfish or something along those lines). It keeps refreshing login.xhtml – Skates Jun 23 '12 at 14:59
  • Okay, then the problem is caused by something else which is not visible in the information provided so far. Start with reading the server logs for any hints related to this problem. If in vain, read this answer for all possible causes: http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked/2120183#2120183 – BalusC Jun 23 '12 at 15:08
  • Well, I think I've narrowed it down. I tried making a couple new .xhtml pages meant only to transfer a parameter between each other using a bean. It didn't work. I copied the same pages inside a new project and it worked. As for the server logs, I get a few "SEVERE" errors but I have no clue how to fix them. I guess I'm making a new project and transferring all the code. Thanks for the help. – Skates Jun 23 '12 at 15:44
  • You should not be ignoring errors. They are the whole answer at its own. If you don't understand what the error is trying to tell you, then you should be copypasting the exact message here in your question, so that we can translate them in layman's terms for you. – BalusC Jun 23 '12 at 16:23
  • I edited the original post to include the server logs. I tried to wrap my head around them but I didn't have much luck. For some reason h:commandButton redirects me now but the bean's properties are not changed. – Skates Jun 23 '12 at 17:10
  • I also looked through your other post but I'm not using f:ajax, I don't have forms within forms, there are no iterating components and my UICommands and UIInputs are all inside the form. – Skates Jun 23 '12 at 17:21
  • No, your concrete problem is already answered by that exception. That's a different matter. The aforelinked answer with all possible causes expects a normal working webapplication wherein no exception is been thrown (simply because exceptions are already the whole answer at its own, you just need to learn how to interpret them). To fix the exception you got, you just need to tell Glassfish to use bundled JSF instead. You apparently bundled MyFaces with your webapp for some reason instead of using Glassfish-buitin Mojarra. Alternatively, just get rid of MyFaces. – BalusC Jun 24 '12 at 12:08