类'de.workshop.sales_tool.Model.Antwort'没有可读属性'text'。 JSF

时间:2014-10-26 09:08:55

标签: jsf

嗨,我发现错误,该课程' ***。Model.Antwort'没有可读的属性' text'。

这是代码:

xhtml文件:

<?xml version="1.0" encoding= "Utf-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                template="templates/default.xhtml"
                xmlns:h="http://xmlns.jcp.org/jsf/html">
    <ui:define name="content">
        <h1>Wizard</h1>
        <h:form>
                <ui:repeat value="#{wizardControler.fragen}" var="frage">
                    <h:outputText value="#{frage.text}"/>
                    <br/>
                    <ui:repeat value="#{frage.antworten}" var="antwort">
                        <h:outputText value="#{antwort.text}"/>
                        <br/>
                        <ui:repeat value="#{answer.teile}" var="teil">
                            <h:outputText value="#{teil.name}"/>
                            <br/>
                        </ui:repeat>
                    </ui:repeat>
                </ui:repeat>
        </h:form>
    </ui:define>
</ui:composition>

控制器:

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import lombok.Data;

@Data
@ManagedBean
@ViewScoped
public class WizardControler {

    private List<Frage> fragen;

    public void setFragen(List<Frage> fragen) {
        this.fragen = fragen;
    }



    public List<Frage> getFragen() {
        fragen = new ArrayList<>();
        try {
            Connection con = DatabaseConector.getConnection();

            Statement stm = con.createStatement();

            String statement = "SELECT * FROM Fragen";

            ResultSet res = stm.executeQuery(statement);

            while(res.next()){
                String text = res.getString(2);
                int nr = res.getInt(1);
                Frage frage = new Frage(text,nr);
                fragen.add(frage);
            }


        } catch (SQLException ex) {
            Logger.getLogger(WizardControler.class.getName()).log(Level.SEVERE, null, ex);
        }
        return fragen;
    }

}

其他java类:

Frage:

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import lombok.Data;

@Data
@ManagedBean
@RequestScoped
public class Frage {

    private String text;
    private int nr;
    List<Antwort> antworten = new LinkedList<>();

    public Frage(String text,int nr) {
        this.text = text;
        this.nr = nr;
        try {
            Connection con = DatabaseConector.getConnection();

            Statement stm = con.createStatement();

            String statement = "SELECT * FROM Antworten WHERE FragenID = "+nr;

            ResultSet res = stm.executeQuery(statement);

            while(res.next()){
                Antwort antwort = new Antwort(res.getString(2),res.getInt(1));
                antworten.add(antwort);
            }


        } catch (SQLException ex) {
            Logger.getLogger(WizardControler.class.getName()).log(Level.SEVERE, null, ex);
        }
    }



}

Antwort:

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import lombok.Data;

@Data
@ManagedBean
@RequestScoped
class Antwort {


    private String text;
    private int nr;
    List<Teil> teile = new LinkedList<>();

    public Antwort(String text, int nr) {
        this.text = text;
        this.nr = nr;
        try {
            Connection con = DatabaseConector.getConnection();

            Statement stm = con.createStatement();

            String statement = "SELECT * FROM Teile WHERE TID = (SELECT TID FROM setztvoraus WHERE AntwortID = "+nr+")";

            ResultSet res = stm.executeQuery(statement);

            while(res.next()){
                Teil teil = new Teil(res.getInt(1),res.getString(2));
                teile.add(teil);
            }


        } catch (SQLException ex) {
            Logger.getLogger(WizardControler.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

确切的错误是:

/wizard.xhtml @13,64 value="#{antwort.text}": The class 'de.workshop.sales_tool.Model.Antwort' does not have a readable property 'text'.

,这是wizardControler的范围变量值:

WizardControler(fragen = [Frage(text = Frage 1,nr = 1,antworten = [Antwort(text = Antwort 1,nr = 1,teile = [Teil(TID = 1,name = Teil 1)]), Antwort(text = Atwort 2,nr = 2,teile = [Teil(TID = 1,name = Teil 1)])]),Frage(text = Frage 2,nr = 2,antworten = [Antwort(text = Antwort 1) ,nr = 5,teile = [Teil(TID = 3,name = Teil 3)]),Antwort(text = Atwort 2,nr = 6,teile = [Teil(TID = 2,name = Teil 2)]), Antwort(text = Antwort 3,nr = 7,teile = [Teil(TID = 3,name = Teil 3)])]),Frage(text = Frage 3,nr = 3,antworten = [Antwort(text = Atwort 2) ,nr = 3,teile = [Teil(TID = 2,name = Teil 2)]),Antwort(text = Antwort 1,nr = 4,teile = [Teil(TID = 1,name = Teil 1)])] )])

EDIT1:

刚尝试并为文本fild添加了真正的getter并在那里做了一个brakpint,在浏览器中显示错误之后它获得了triggert ^^

1 个答案:

答案 0 :(得分:0)

MAAN我讨厌这样的问题-.- 5个小时,这只是一个小小的&#34;私人&#34;在答案类前面 - .-