我有这个托管bean,它从数据库表中获取两个值
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
// or import javax.faces.bean.SessionScoped;
import javax.inject.Named;
/* include SQL Packages */
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
import javax.annotation.Resource;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
// or import javax.faces.bean.ManagedBean;
import org.glassfish.osgicdi.OSGiService;
@Named("DashboardController")
@SessionScoped
public class Dashboard implements Serializable {
private String SessionTTL = null;
private String MaxActiveUsers = null;
private String stringone = null;
private String stringtwo = null;
private String SQL_Statement = null;
private String Password;
private String User;
public Dashboard(){
}
/* Call the Oracle JDBC Connection driver */
@Resource(name = "jdbc/Oracle")
private DataSource ds;
public String getSessionTTL() {
return SessionTTL;
}
public void setSessionTTL(String SessionTTL) {
this.SessionTTL = SessionTTL;
}
public String getMaxActiveUsers() {
return MaxActiveUsers;
}
public void setMaxActiveUsers(String MaxActiveUsers) {
this.MaxActiveUsers = MaxActiveUsers;
}
//connect to DB and get settings values
public List<Dashboard> getDashboardList()throws SQLException{
List<Dashboard> list = new ArrayList<Dashboard>();
if(ds == null) {
throw new SQLException("Can't get data source");
}
Connection conn = ds.getConnection();
if(conn == null) {
throw new SQLException("Can't get database connection");
}
PreparedStatement ps = conn.prepareStatement("SELECT * from GLOBALSETTINGS");
try{
//get data from database
ResultSet result = ps.executeQuery();
while (result.next()){
Dashboard cust = new Dashboard();
cust.setSessionTTL(result.getString("SessionTTL"));
cust.setMaxActiveUsers(result.getString("MaxActiveUsers"));
list.add(cust);
}
}
catch(Exception e1){
// Log the exception.
}
finally{
try{
ps.close();
conn.close();
}
catch(Exception e2){
// Log the exception.
}
}
return list;
}
}
这是JSF表的代码,它必须显示值:
<h:dataTable id="books"
columnClasses="list-column-center,
list-column-right, list-column-center,
list-column-right" headerClass="list-header"
rowClasses="list-row" styleClass="list-
background" value="#{DashboardController.getDashboardList()}" var="store">
<h:column>
<f:facet name="header">
<h:outputText value="#{store.SessionTTL}"/>
</f:facet>
<h:outputText value="#{store.SessionTTL}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{store.MaxActiveUsers}"/>
</f:facet>
<h:outputText value="#{store.MaxActiveUsers}"/>
</h:column>
</h:dataTable>
问题是当我尝试运行JSF页面时出现此错误:
javax.el.PropertyNotFoundException: /Settings.xhtml @82,69 value="#{store.SessionTTL}": The class 'com.DX_57.SM_57.Dashboard' does not have the property 'SessionTTL'.
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:111)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIOutput.getValue(UIOutput.java:169)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
at com.sun.faces.renderkit.html_basic.TableRenderer.renderRow(TableRenderer.java:384)
at com.sun.faces.renderkit.html_basic.TableRenderer.encodeChildren(TableRenderer.java:161)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
我在某个地方有错,但我找不到它。
答案 0 :(得分:1)
尝试将store.SessionTTL
替换为store.sessionTTL
。属性应以小写字符开头。
答案 1 :(得分:1)
尝试使用java命名约定,使用“sessionTTL”作为属性的名称,包括Dashboard bean和标记(JSF视图)。
private String sessionTTL = null;
<h:outputText value="#{store.sessionTTL}"/>
我的意思是我会使用较低的camelcase(小写的第一个字母)而不是上部的camelcase。点击here了解有关camelcase的更多信息。
我会为“maxActiveUsers”做同样的事情。