簡體   English   中英

jsf2中的h:commandLink不調用bean方法,甚至不通過javascript調用

[英]h:commandLink in jsf2 not invoking bean method and not even through javascript call

這是在將我的項目遷移到tomcat7上的jsf2之后發生的。 先前在tomcat5.5 for jsf 1上運行良好。 我有一個.xhtml文件,嘗試從該文件中通過h:commandLink調用托管Bean方法,但未被調用。 我曾嘗試添加EL 2.2罐子,作為與該主題相關的其他stackoverflow論壇中的建議,並且還在web.xml中添加了條目:

<context-param>
    <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
  </context-param>
  <context-param>
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
  </context-param>

但是問題沒有解決。 請幫忙。

.xhtml文件:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core" 
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:t="http://myfaces.apache.org/tomahawk">

    <f:view>
    <f:loadBundle var="text" basename="#{basePage.bundleName}"/>
    <title>#{text['user.passwordHint']}</title>

    <p>Looking up password hint for ${param.username}...</p>

    <h:form id="passwordForm">

        <h:inputHidden id="username" value="#{passwordHint.username}"/>

        <h:commandLink action="#{passworHint.execute}" id="execute">
           <f:param name="username" value="${param.username}"></f:param>
        </h:commandLink>
    </h:form>

    <script type="text/javascript">

        var f = document.forms['passwordForm'];
         f.elements['passwordForm:_link_hidden_'].value='passwordForm:execute';
    f.elements['username'].value='${param.username}';        
f.submit();
    </script>

    </f:view>
    </html>

托管豆:

public class PasswordHint extends BasePage {
    @ManagedProperty(value="#{param.username}")
    private String username;
 /*   private String execute;

    public String getExecute() {
        return execute;
    }

    public void setExecute(String execute) {
        this.execute = execute;
    }*/

    public String getUsername() {
        System.out.println("get username of passwordhint-------"+username);
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }


    public String execute() {
    /*  FacesContext context = FacesContext.getCurrentInstance();
        Map<String,String> params = context.getExternalContext().getRequestParameterMap();
        System.out.println(params.get("username"));
        System.out.println("Inside password hint execute-------------");
        */
        // ensure that the username has been sent
        if (username == null || "".equals(username)) {
            log.warn("Username not specified, notifying user that it's a required field.");

            addError("errors.required", getText("user.username"));
            return null;
        }

        if (log.isDebugEnabled()) {
            log.debug("Processing Password Hint...");
        }

        // look up the user's information
        try {
            User user = userManager.getUserByUsername(username);
            System.out.println("username retrieved---------"+username);
            StringBuffer msg = new StringBuffer();
            msg.append("Your password hint is: " + user.getPasswordHint());
            msg.append("\n\nLogin at: " + RequestUtil.getAppURL(getRequest()));

            message.setTo(user.getEmail());
            String subject = '[' + getText("webapp.name") + "] " + getText("user.passwordHint");
            message.setSubject(subject);
            message.setText(msg.toString());
            mailEngine.send(message);

            addMessage("login.passwordHint.sent", 
                       new Object[] { username, user.getEmail() });

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("In exception----------------");
            // If exception is expected do not rethrow
            //addError("login.passwordHint.error", username);
            addMessage("login.passwordHint.sent", username);
        }

        return "success";
    }

faces-config.xml:



 <navigation-rule>
            <from-view-id>/passwordHint.xhtml</from-view-id>
            <navigation-case>
                <from-outcome>success</from-outcome>
                <to-view-id>/login.jsp</to-view-id>
                <redirect/>
            </navigation-case>
        </navigation-rule>

      <managed-bean>
            <managed-bean-name>passwordHint</managed-bean-name>
            <managed-bean-class>com.webapp.action.PasswordHint</managed-bean-class>
            <managed-bean-scope>request</managed-bean-scope>
            <managed-property>
              <property-name>username</property-name>
              <value>#{param.username}</value>
            </managed-property>
            <managed-property>
                <property-name>userManager</property-name>
                <value>#{userManager}</value>
            </managed-property>
            <managed-property>
                <property-name>mailEngine</property-name>
                <value>#{mailEngine}</value>
            </managed-property>
            <managed-property>
                <property-name>message</property-name>
                <value>#{mailMessage}</value>
            </managed-property>
            <managed-property>
                <property-name>templateName</property-name>
                <value>accountCreated.vm</value>
            </managed-property> 

        </managed-bean>

是的,這是我正在嘗試的實際代碼,這是復制粘貼我的實際代碼時的錯字。 另外,JavaScript錯誤指出: f.elements['passwordForm:_link_hidden_'] is null or not an object.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM