0

在我的代码的某个地方我犯了一个愚蠢的错误,但我找不到它。我使用 jsf 页面将新电影添加到数据库中。

<h:form id="MovieForm">
    <h:panelGrid columns="4" columnClasses="fixed-column">
        Titel  <h:inputText id="title">#{moviePM.title}</h:inputText>
        Direktor <h:inputText id="director">#{moviePM.director}</h:inputText>
        Erscheinungsjahr <h:inputText id="year">#{moviePM.year}</h:inputText>
        Altersbeschränkung <h:selectOneMenu value="#{moviePM.rating}">
            <f:selectItems value="#{moviePM.ratings}" />
        </h:selectOneMenu>
    </h:panelGrid>
    <h:commandButton value="Film hinzufügen" action="#{moviePM.addMovie()}" />
</h:form>

我使用以下类来获取 jsf 页面的结果

import business.MovieService;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
import model.Movie;
import model.Rating;

@Named
@SessionScoped
public class MoviePM implements Serializable {

    @EJB
    private MovieService service;

    private String director;
    private String title;
    private int year;
    private Rating rating;

    public void addMovie() {
        Logger.getLogger(MoviePM.class.getName()).log(Level.INFO, "###" + director + " " + title + " " + year + " " + rating + "###");
        Movie movie = new Movie();
        movie.setDirector(director);
        movie.setTitle(title);enter code here
        movie.setYear(year);
        movie.setRating(rating);
        service.create(movie);

    }

我也有吸气剂和二传手,但我把它们排除在这篇文章之外。

记录器提供以下结果:信息:###null null 0 FSKAB16###

有人能帮我吗?

4

1 回答 1

1

您需要使用value="..."将输入连接到 bean 属性。就像你为评级所做的那样。

<h:form id="MovieForm">
    <h:panelGrid columns="4" columnClasses="fixed-column">
        Titel: <h:inputText id="title" value="#{moviePM.title}" />
        Direktor: <h:inputText id="director" value="#{moviePM.director}" />
        Erscheinungsjahr: <h:inputText id="year" value="#{moviePM.year}" />
        Altersbeschränkung: <h:selectOneMenu value="#{moviePM.rating}">
            <f:selectItems value="#{moviePM.ratings}" />
        </h:selectOneMenu>
    </h:panelGrid>
    <h:commandButton value="Film hinzufügen" action="#{moviePM.addMovie()}" />
</h:form>
于 2013-10-09T12:48:29.323 回答