为什么p:commandLink在页面加载时调用bean动作

时间:2017-06-29 16:12:24

标签: jsf primefaces jsf-2

当页面加载为什么它会调用Action?由于此页面未加载,因为它在内部抛出nullpointer。如何避免加载动作?

我正在使用JBOSS wildfly-10.1.0.Final

这实际上是我从另一个项目中复制的工作代码,并且此代码工作正常。

以下是我的代码的信息。我不会把整个文件放大,因为它有点大。

<html xmlns="http://www.w3.org/1999/xhtml" lang="en"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html">

<body>
<ui:composition template="/template/master-layout.xhtml">
<ui:define name="head">
   <script src="https://apis.google.com/js/platform.js" async="async defer">     </script>
<meta name="google-signin-client_id" content="63091603994-mlh4mm45b0ept7ci0pg0051qurl4c765.apps.googleusercontent.com"> </meta>

    <script type='text/javascript' src='#{uiHelperBean.cssjsRootUrl}/js/jquery.tipsy.js'></script>
    <script type='text/javascript' src='#{uiHelperBean.cssjsRootUrl}/js/app.js'></script>
    <link href="#{uiHelperBean.cssjsRootUrl}/css/login.css" rel="stylesheet" type="text/css" />
</ui:define>

<ui:define name="mainContainer">

  <h:form id="login-form">
     <div class="col-sm-10  ">
       <h:inputText id="username" maxlength="50"  placeholder="Enter email" styleClass="emailAddressOnly cust-email form-control login-input "
      tabindex="1">
         <f:validator validatorId="emailValidator"/>
         <f:attribute name="label" value="Email Address"/>
       </h:inputText>
       <span class="glyphicon glyphicon-user "></span>
     </div>
     <div class="col-sm-10">
        <div class="inner-addon left-addon">
            <span class="glyphicon glyphicon-lock form-control-feedback1"></span>
            <h:inputSecret id="password" redisplay="true" maxlength="20" autocomplete="off"styleClass="form-control login-input cust-password" tabindex="2">
              <f:validator validatorId="passwordValidator"/>
              <f:attribute name="label" value="Password"/>
            </h:inputSecret>
        </div>
      </div>
     <div class="form-group">                
       <div class="col-sm-10  ">
        <p:commandLink id="login" tabindex="3" update="@form" value="Sign In" action="#{userBean.login()}" styleClass="btn btn-danger signin custom-width" onstart="showSpinner('Please wait');" oncomplete="hideSpinner();" onmouseover="">
          <i class="glyphicon glyphicon-play-circle"></i>
        </p:commandLink>
       </div>
     </div>

   </h:form>
  </ui:define>
</ui:composition>
</body>
</html>

faces-config.xml中

 

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- This file is not required if you don't need any extra configuration. -->
<faces-config version="2.0" 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_2_0.xsd">

<navigation-rule>
<from-view-id>/*</from-view-id>
<navigation-case>
    <from-outcome>login</from-outcome>
    <to-view-id>/login.xhtml</to-view-id>
    <redirect/>
</navigation-case>
<navigation-case>
    <from-outcome>registration</from-outcome>
    <to-view-id>/login/reg.xhtml</to-view-id>
    <redirect/>
</navigation-case>
<navigation-case>
    <from-outcome>forgetpassword</from-outcome>
    <to-view-id>/login/reset-password.xhtml</to-view-id>
    <redirect/>
</navigation-case>
<navigation-case>
    <from-outcome>logout</from-outcome>
    <to-view-id>/logout.xhtml</to-view-id>
    <redirect/>
</navigation-case>
<navigation-case>
    <from-outcome>contact-us</from-outcome>
    <to-view-id>/contact-us.xhtml</to-view-id>
    <redirect/>
</navigation-case>
</navigation-rule>

<navigation-rule>
    <from-view-id>/login.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>login_force_change_password</from-outcome>
        <to-view-id>/login/change-password.xhtml</to-view-id>
        <redirect/>
    </navigation-case>
</navigation-rule>
<navigation-rule>
    <from-view-id>/login/pin-activation.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>validatepin_success</from-outcome>
        <to-view-id>/login/pin-activation-success.xhtml</to-view-id>
        <redirect/>
    </navigation-case>
</navigation-rule>
<navigation-rule>
    <from-view-id>/login.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>login_force_change_password</from-outcome>
        <to-view-id>/login/change-password.xhtml</to-view-id>
        <redirect/>
    </navigation-case>
</navigation-rule>

0 个答案:

没有答案