我认为我的问题与我的Managed Bean构造函数没有出现被调用有关。也就是说,如果我在构造函数中放置断点,应用程序不会在断点处停止。
我获取标题但不是构造函数中添加的行。
这是我的代码:首先是xhtml:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:head>
<f:facet name="first">
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
<title>LOTTO CHECKER</title>
</f:facet>
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="100" resizable="true" closable="true" collapsible="true">
LOTTO CHECKER
</p:layoutUnit>
<p:layoutUnit position="south" size="100" closable="true" collapsible="true">
Footer
</p:layoutUnit>
<p:layoutUnit position="west" size="175" header="Left" collapsible="true" >
</p:layoutUnit>
<p:layoutUnit position="center">
<h:form id="powerBallDrawingForm">
<p:dataTable value="#(lottoCheckerBean.powerBallDrawings}" var="powerBallDrawing" >
<p:column headerText="DATE">
<h:outputText value ="#{powerBallDrawing.drawingDate}"/>
</p:column >
<p:column headerText="BALL 1">
<h:outputText value="#{powerBallDrawing.ball_1}" />
</p:column>
<p:column headerText ="BALL 2">
<h:outputText value="#{powerBallDrawing.ball_2}" />
</p:column>
<p:column headerText ="BALL 3">
<h:outputText value="#{powerBallDrawing.ball_3}" />
</p:column>
<p:column headerText ="BALL 4">
<h:outputText value="#{powerBallDrawing.ball_4}" />
</p:column>
<p:column headerText="BALL 5">
<h:outputText value="#{powerBallDrawing.ball_5}" />
</p:column>
<p:column headerText="POWER BALL">
<h:outputText value="#{powerBallDrawing.powerBall}" />
</p:column>
</p:dataTable>
</h:form>
</p:layoutUnit>
</p:layout>
</h:body>
</f:view>
</html>
现在是托管Bean
package PowerBall_BigBame_Checker;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class LottoCheckerBean implements Serializable {
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method")
private List<PowerBallDrawing> powerBallDrawings;
public LottoCheckerBean() {
powerBallDrawings = new ArrayList<PowerBallDrawing>();
powerBallDrawings.add( new PowerBallDrawing("03/16/2013",1,2,3,4,5,6));
}
public List<PowerBallDrawing> getPowerBallDrawings() {
return this.powerBallDrawings;
}
public void setPowerBallDrawings(List<PowerBallDrawing> powerBallDrawings) {
this.powerBallDrawings = powerBallDrawings;
}
}
最后是包含表格行的类:
package PowerBall_BigBame_Checker;
import java.io.Serializable;
public class PowerBallDrawing implements Serializable {
private String drawingDate;
private int ball_1;
private int ball_2;
private int ball_3;
private int ball_4;
private int ball_5;
private int powerBall;
public PowerBallDrawing(String drawingDate, int ball_1, int ball_2, int ball_3,
int ball_4, int ball_5, int powerBall) {
this.ball_1 = ball_1;
this.ball_2 = ball_2;
this.ball_3 = ball_3;
this.ball_4 = ball_4;
this.ball_5 = ball_5;
this.powerBall = powerBall;
this.drawingDate = drawingDate;
}
public String getDrawingDate() {
return drawingDate;
}
public void setDrawingDate(String drawingDate) {
this.drawingDate = drawingDate;
}
public int getBall_1() {
return ball_1;
}
public void setBall_1(int ball_1) {
this.ball_1 = ball_1;
}
public int getBall_2() {
return ball_2;
}
public void setBall_2(int ball_2) {
this.ball_2 = ball_2;
}
public int getBall_3() {
return ball_3;
}
public void setBall_3(int ball_3) {
this.ball_3 = ball_3;
}
public int getBall_4() {
return ball_4;
}
public void setBall_4(int ball_4) {
this.ball_4 = ball_4;
}
public int getBall_5() {
return ball_5;
}
public void setBall_5(int ball_5) {
this.ball_5 = ball_5;
}
public int getPowerBall() {
return powerBall;
}
public void setPowerBall(int powerBall) {
this.powerBall = powerBall;
}
}
我怀疑我在某个地方违反了一项惯例,但我没有看到它。
答案 0 :(得分:0)
您在构造函数中编写的代码应位于以下方法中:
public void setPowerBallDrawings(List powerBallDrawings){
}
这是因为无论何时尝试访问变量,都会调用相应的setter方法。
尝试一次。它应该工作。
答案 1 :(得分:0)
我已将您的类和jsf页面添加到现有项目中以查看错误。
你唯一的错误是在这一行
<p:dataTable value="#(lottoCheckerBean.powerBallDrawings}" var="powerBallDrawing">
如评论中所述,您的EL表达中有(。正确的定义是
<p:dataTable value="#{lottoCheckerBean.powerBallDrawings}" var="powerBallDrawing">
除此之外没有任何错误。