JSF <h:inputtext>值不会更新bean属性</h:inputtext>

时间:2012-06-23 14:14:31

标签: jsf

所以我对JSF很新,我几天前刚刚开始使用它,我正在尝试学习youtube教程和几本书。但我不知道为什么这不起作用。这是我的代码:

    <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只是一个包含3个私有字符串的类(login =“welcome”,名称和密码)及其getter / setter。

单击“登录”按钮后,我被重定向到welcome.xhtml,但是没有对redirectBean.name或redirectBean.password进行任何更改。

有什么想法?我错过了什么?

编辑:所以BalusC已经解释说我需要使用h:commandButton,但这并没有重定向我。经过一些来回试图找出原因后,这​​是我目前正在获取的服务器日志(它现在使用命令按钮重定向我,但仍未将值传递给bean。我也得到了一些关于RI和MyFaces的信息冲突,但在类路径中的一些修补似乎已经修复了):

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

1 个答案:

答案 0 :(得分:2)

您需要使用<h:commandButton>,而不是<h:button><h:button>仅发送GET请求,而<h:commandButton>通过POST提交表单。

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

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

    return "welcome";
}

另见: