Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 未在托管Bean中获取文本框值_Jsf 2_Myfaces - Fatal编程技术网

Jsf 2 未在托管Bean中获取文本框值

Jsf 2 未在托管Bean中获取文本框值,jsf-2,myfaces,Jsf 2,Myfaces,我无法获取在ManagedBean的xhtml页面上输入的用户名和密码值 这就是为什么我在检查用户名和密码时在再见方法中得到NullPointerException Login.xhtml faces-config.xml 命令按钮上的immediate=true会导致JSF跳过所有生命周期阶段,直到调用应用程序。因此,您的值未设置。删除此属性,它将按预期工作。您的托管bean应采用以下方式 <managed-bean> <managed-bean-name>lo

我无法获取在ManagedBean的xhtml页面上输入的用户名和密码值

这就是为什么我在检查用户名和密码时在再见方法中得到NullPointerException

Login.xhtml

faces-config.xml


命令按钮上的immediate=true会导致JSF跳过所有生命周期阶段,直到调用应用程序。因此,您的值未设置。删除此属性,它将按预期工作。

您的托管bean应采用以下方式

<managed-bean>
    <managed-bean-name>loginBean</managed-bean-name>
    <managed-bean-class>com.example.ws.ui.LoginBean</managed-bean-class>
    <managed-bean-scope>view</managed-bean-scope>       
</managed-bean>
在您的xhtml页面中:

<td><h:outputLabel for="username">     
 <h:outputText id="usernameLabel" value="Enter Username:" />                           </h:outputLabel>                       </td>      

as id for>是用户名

在validateLongRange验证器中发现的问题。您输入了一个字符串,必须使用validateLength。validateLongRange用于双值


希望这个答案是write

能告诉我们您正在使用的JSF版本吗。。???您还可以展示如何定义托管Bean吗?..@Mango请查找附加的faces-config.xml我正在使用faces-config.xml,因此我在这里指定了ManagedBean。那么它也不起作用了。你能详细解释我吗?或者提供一些链接,让我可以阅读。我建议阅读此文章。非常感谢分享链接。也请尝试从你的网站中删除type=submit和immediate=true
<?xml version="1.0"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
      http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
    version="1.2">
    <managed-bean>
        <description>Login Bean</description>
        <managed-bean-name>loginBean</managed-bean-name>
        <managed-bean-class>com.example.ws.ui.LoginBean</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    <managed-bean>
        <description>EBZ Bean</description>
        <managed-bean-name>getEbzByIdBean</managed-bean-name>
        <managed-bean-class>com.example.ws.ui.GetEbzByIdBean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
    <managed-bean>
        <description>WsListing Bean</description>
        <managed-bean-name>wsListingBean</managed-bean-name>
        <managed-bean-class>com.example.ws.ui.WsListingBean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
    <navigation-rule>
        <description>Navigation from the hello page.</description>
        <from-view-id>/login.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>success</from-outcome>
            <to-view-id>/wsListing.xhtml</to-view-id>
            <redirect />
        </navigation-case>
        <navigation-case>
            <from-outcome>failure</from-outcome>
            <to-view-id>/failure.xhtml</to-view-id>
            <redirect />
        </navigation-case>
    </navigation-rule>
    <navigation-rule>
        <description>Navigation from the hello page.</description>
        <from-view-id>/wsListing.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>ebzService</from-outcome>
            <to-view-id>/ebzinput.xhtml</to-view-id>
            <redirect />
        </navigation-case>
        <navigation-case>
            <from-outcome>filterEbz</from-outcome>
            <to-view-id>/filterebzinput.xhtml</to-view-id>
            <redirect />
        </navigation-case>
    </navigation-rule>


    <navigation-rule>
        <description>Navigation from the hello page.</description>
        <from-view-id>/ebzinput.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>success</from-outcome>
            <to-view-id>/ebzoutput.xhtml</to-view-id>
            <redirect />
        </navigation-case>
    </navigation-rule>
    <application>
        <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
        <locale-config>
            <default-locale>en</default-locale>
            <supported-locale>en</supported-locale>
            <supported-locale>es</supported-locale>
        </locale-config>
        <message-bundle>messages</message-bundle>
    </application>
</faces-config>
<managed-bean>
    <managed-bean-name>loginBean</managed-bean-name>
    <managed-bean-class>com.example.ws.ui.LoginBean</managed-bean-class>
    <managed-bean-scope>view</managed-bean-scope>       
</managed-bean>
<td><h:outputLabel for="username">     
 <h:outputText id="usernameLabel" value="Enter Username:" />                           </h:outputLabel>                       </td>