2

私は JSF とその仲間に不慣れです。

私の開発環境は次のとおり Java 6 Tomcat 6 Eclipse Primeface 2.5

インスタント プライムフェイス スターターで説明されているテスト Web アプリケーションを試しています。

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">

<display-name>PrimeFaces Web Application</display-name>

<!-- Change to "Production" when you are ready to deploy -->
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

<!-- Welcome page -->
<welcome-file-list>
    <welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>

<!-- JSF mapping -->
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- Map these files with JSF -->
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

顔-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<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_2_1.xsd" 
          version="2.1">

ビーンズ.xml

空のファイルです

index.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head />
<body>
<ui:composition template="/WEB-INF/templates/main.xhtml">
    <ui:define name="title">Welcome to our site</ui:define>
    <ui:define name="content">
        <h:form>
            <h:panelGrid columns="2" border="0">
                <p:panel header="Please Sign In">
                    <p:panelGrid columns="2" styleClass="no-border"
                        columnClasses="no-border,no-border">
                        <p:outputLabel value="Username" for="username" />
                        <p:inputText id="username" label="Username"
                            value="#{credentials.username}" />
                        <p:outputLabel value="Password" for="password" />
                        <p:password id="password" label="Password"
                            value="#{credentials.password}" />
                        <h:outputText value="" />
                        <p:commandLink value="Forgot your password?" />
                        <h:outputText value="" />
                        <p:commandButton value="Login" action="members"
                            actionListener="#{loginController.login}" />
                        <h:outputText value="" />
                    </p:panelGrid>
                </p:panel>
                <ul>
                    <li>Find out what's happening</li>
                    <li>Rate and review shows</li>
                    <li>Invite your friends</li>
                    <li><a href="/faces/register.xhtml">Join today!</a>
                    </li>
                </ul>
            </h:panelGrid>
        </h:form>
    </ui:define>
</ui:composition>
</body>
</html>

loginController.java

package com.example.starterexample.controller;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;

import com.example.starterexample.model.Credentials;

/**
 * Controller class for desktop and mobile login functionality.
 * 
 * @uml.dependency supplier="com.mycompany.controller.AbstractController"
 */
@ManagedBean(name="loginController", eager=true)
//@ViewScoped
@RequestScoped
/*
 * @ViewScoped  means the object is created by JSF 
 *              and its lifecycle is scoped to the current view.
 *          Once the user navigates to another view, the LoginControllerobject     is released and 
 *          will eventually be garbage-collected by the JVM
 */
public class LoginController extends AbstractController {

private static final long serialVersionUID = -6710063228036238737L;

@ManagedProperty(value = "#{credentials}")
private Credentials credentials;

public String login() {
    String outcome = null;
    try {
        String username = credentials.getUsername();
        String password = credentials.getPassword();
        //User user = userService.findUser(username, password);
        //if (user == null) {
        //  addErrorMessage("Invalid login");
        //  userSession.setUser(null);
        //} else {
        //  userSession.setUser(user);
        //  if (!activeUsers.contains(user)) {
        //      activeUsers.add(user);
        //  }
            //outcome = "members";
        //}

            addErrorMessage("Invalid login");
    } catch (Exception e) {
        logger.error("Unable to login:", e);
    }
    return outcome;
}

public void setCredentials(Credentials credentials) {
    this.credentials = credentials;
}


}

Credentials.java

package com.example.starterexample.model;

import javax.enterprise.inject.Model;

@Model
public class Credentials {

private String username;
private String password;

public String getUsername() {
    return username;
}
public void setUsername(String username) {
    this.username = username;
}
public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
}


}

エラー:

Sep 21, 2013 5:03:34 PM com.sun.faces.lifecycle.ProcessValidationsPhase execute
WARNING: /index.xhtml @19,67 value="#{credentials.username}": Target Unreachable, identifier 'credentials' resolved to null
javax.el.PropertyNotFoundException: /index.xhtml @19,67 value="#{credentials.username}": Target Unreachable, identifier 'credentials' resolved to null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
at             org.primefaces.renderkit.InputRenderer.findImplicitConverter(InputRenderer.java:170)
at org.primefaces.renderkit.InputRenderer.findConverter(InputRenderer.java:190)
at org.primefaces.renderkit.InputRenderer.getConvertedValue(InputRenderer.java:196)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
at javax.faces.component.UIInput.validate(UIInput.java:960)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1233)
at javax.faces.component.UIInput.processValidators(UIInput.java:698)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at org.primefaces.component.panel.Panel.processValidators(Panel.java:297)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)

足りないものを見つけるのを手伝ってください。

同様の問題を探しましたが、何もうまくいきませんでした。

作成したwarファイルを確認したところ、クラスファイルはWEB-INF/classesにあります

前もって感謝します。

4

3 に答える 3

1

JSF アノテーションを使用して CDI Bean にアクセスしようとしていることを行うことは許可されていません。javax.enterprise.inject.modelは CDI ベースのアノテーションであるため、JSF のバージョンに応じて、次のオプションがあります。

  1. loginController@Inject を使用して CDI Bean に変換し、@Named次に @Inject を使用してモデルを取得します - JSF 2.1

  2. CDI Bean@Injectを使用できる JSF 2.2 にアップグレードします。@ManagedProperty

于 2013-09-22T22:54:53.480 に答える