当尝试在EL中引用托管bean时#{bean.entity.property}
,有时会javax.el.PropertyNotFoundException: Target Unreachable
抛出异常,通常是在设置bean属性时,或者要调用bean操作时.
似乎有五种不同的消息:
这些都意味着什么?它们是如何引起的,它们应该如何解决?
我有一个看起来像这样的类:
public class ScoreDefinition {
protected Boolean primary;
public Boolean isPrimary() {
return primary;
}
public void setPrimary(Boolean value) {
this.primary = value;
}
}
Run Code Online (Sandbox Code Playgroud)
我试图primary
在EL中访问它的属性,如下所示:
<c:forEach var="score" items="${scores}">
<input type="checkbox"
value="${score.primary}"
name="someName"
class="textField"/>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)
但我得到了例外:
javax.el.PropertyNotFoundException: Property 'primary' not readable on type java.lang.Boolean
at javax.el.BeanELResolver$BeanProperty.read(BeanELResolver.java:280)
at javax.el.BeanELResolver$BeanProperty.access$000(BeanELResolver.java:230)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:81)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.el.parser.AstValue.getValue(AstValue.java:123)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:938)
at org.apache.jsp.WEB_002dINF.views.administer.projectBlocks_jsp._jspx_meth_c_005fforEach_005f2(projectBlocks_jsp.java:806)
at org.apache.jsp.WEB_002dINF.views.administer.projectBlocks_jsp._jspx_meth_c_005fif_005f2(projectBlocks_jsp.java:709)
at org.apache.jsp.WEB_002dINF.views.administer.projectBlocks_jsp._jspx_meth_form_005fform_005f0(projectBlocks_jsp.java:245)
at org.apache.jsp.WEB_002dINF.views.administer.projectBlocks_jsp._jspService(projectBlocks_jsp.java:150)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) …
Run Code Online (Sandbox Code Playgroud) 我有结果
Query query = session.createQuery("From Pool as p left join fetch p.poolQuestion as s");
Run Code Online (Sandbox Code Playgroud)
查询,我想在JSP上显示它.
我有循环:
<c:forEach items="${pools}" var="pool">
<p>${pool.name}</p>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)
我想显示poolQuestion表(连接表)的结果.我想要显示的值是"回答".
我该怎么做?
<c:forEach items="${pools}" var="pool">
<p>${pool.answer}</p>
<p>${pool.name}</p>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)
上面的代码不起作用.
错误是:
org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/home.jsp at line 21
18: <c:forEach items="${pools}" var="pool">
19:
20: <p>${pool.name}</p>
21: <c:out value="${pool.poolQuestion.answer}"/>
22:
23: </c:forEach>
24:
SEVERE: Servlet.service() for servlet appServlet threw exception
javax.el.PropertyNotFoundException: Property 'answer' not found on type com.pool.app.domain.Pool
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:214)
at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:191)
at javax.el.BeanELResolver.property(BeanELResolver.java:300)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:81)
at …
Run Code Online (Sandbox Code Playgroud) 我有以下树节点类:
public abstract class DocumentTreeNode extends TreeNodeImpl implements javax.swing.tree.TreeNode
{
private Boolean isToC;
...
public Boolean isToC()
{
return isToC;
}
public void setToC(Boolean isToC)
{
this.isToC = isToC;
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个简单的复选框,指示文档是否包含在任何内容中.但是,当试图从JSF 2 EL中引用它时
...
<h:selectBooleanCheckbox value="#{node.isToC}" />
...
Run Code Online (Sandbox Code Playgroud)
我得到一个例外:
引起:javax.el.PropertyNotFoundException:/main.xhtml @ 541,64 value ="#{node.isToC}":类'ChapterTreeNode'没有属性'isToC'.
(我想我几乎尝试了所有组合,至少我觉得这样...... ;-))
如何解决该布尔属性?需要改变什么?
我在运行JSF页面时遇到了这个错误.
javax.el.PropertyNotFoundException:目标无法访问,'null'返回null ..
警告:/createStaff.xhtml @ 33,125 value ="#{staffBean.staff.firstName}":目标无法访问,'null'返回null javax.el.PropertyNotFoundException:/createStaff.xhtml @ 33,125 value ="#{staffBean.staff. firstName}":目标无法访问,'null'返回null
我不明白为什么我在使用value =时会遇到错误"#{staffBean.staff.firstName}"
.当我使用value = "#{staffBean.userName}"
和value = "#{staffBean.passWord}"
above 时没有问题.
这是我的createStaff.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Create Staff</title>
</h:head>
<h:body>
<f:view>
<h:form>
<p:panel id ="panel" header="Staff Creation">
<p:messages id="msgs" />
<h:panelGrid columns="3" columnClasses="label, value">
<h:outputText value="Username: *" />
<p:inputText id="username" value="#{staffBean.userName}" required="true" label="Username">
</p:inputText>
<p:message for="username" />
<h:outputLabel for="pwd1" value="Password 1: *" …
Run Code Online (Sandbox Code Playgroud) 我有一个JSP,我正在尝试使用JSTL标记来显示类的内存实例中的数据.数据由一系列字符串组成,其中每个字符串是RSS提要的地址.
在JSP中,我有以下代码:
<table border = "1">
<tr>
<c:forEach var = "rssFeedURL" items = "${rssfom.rssFeedURLs}">
<td align = "left">${rssFeedURL}</td>
</c:forEach>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
基本上,rssfom是以下类的实例:
public class RSSFeedOccurrenceMiner extends RSSFeedMiner {
private HashMap<String, Counter> keywordFrequencies;
public RSS_Feed_OccurrenceMiner() {
super();
this.keywordFrequencies = new HashMap();
}
...
}
Run Code Online (Sandbox Code Playgroud)
这继承自RSSFeedMiner类,它包含以下变量和方法:
private ArrayList<String> rssFeedURLs;
public ArrayList<String> getRSSFeedURLs() {
return rssFeedURLs;
}
public void setRSSFeedURLs(ArrayList<String> rssFeedURLs) {
this.rssFeedURLs = rssFeedURLs;
}
Run Code Online (Sandbox Code Playgroud)
所以在JSP中,我以为我可以使用上面的代码但是当页面运行时,我只是收到一个空表.在服务器日志中,我倾向于找到消息:
javax.el.PropertyNotFoundException:在类型RSSFeedOccurrenceMiner上找不到属性'rssFeedURLs'
鉴于我对继承的使用,这是正确的.那么有人能告诉我JSTL是否允许继承或者我的代码中是否缺少某些内容?
我真的不想在JSP中使用scriptlet.
我的Facelet中有以下代码片段:
<h:commandLink id="cmdbtn">
<f:ajax event="click" execute="@form"
listener="#{screenShotBean.takeScreenshot}" />
</h:commandLink>
Run Code Online (Sandbox Code Playgroud)
它工作正常,但当我像这样取消它,
<!-- <h:commandLink id="cmdbtn"> -->
<!-- <f:ajax event="click" execute="@form" -->
<!-- listener="#{screenShotBean.takeScreenshot}" /> -->
<!-- </h:commandLink> -->
Run Code Online (Sandbox Code Playgroud)
然后它抛出以下异常:
javax.el.PropertyNotFoundException: Property 'takeScreenshot' not found on type monstage.test.com.ScreenShotBean
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)
at javax.el.BeanELResolver.property(BeanELResolver.java:325)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at com.sun.faces.facelets.el.ELText$ELTextVariable.toString(ELText.java:217)
at com.sun.faces.facelets.el.ELText$ELTextComposite.toString(ELText.java:157)
at com.sun.faces.facelets.compiler.CommentInstruction.write(CommentInstruction.java:77)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:424)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
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 …
Run Code Online (Sandbox Code Playgroud) 具有以下代码段:
豆:
import javax.faces.view.ViewScoped;
import javax.inject.Named;
@Named(value = "directoryBean")
@ViewScoped
public class DirectoryBean implements Serializable {
private static final long serialVersionUID = 1L;
....
}
Run Code Online (Sandbox Code Playgroud)
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
version="2.3">
....
</faces-config>
Run Code Online (Sandbox Code Playgroud)
group.xhtml
<ui:composition ...>
<f:metadata>
<f:viewParam name="id" value="#{directoryBean.id}" />
</f:metadata>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
结果得到异常:
javax.el.PropertyNotFoundException: /group.xhtml @6,64 value="#{directoryBean.id}": Target Unreachable, identifier 'directoryBean' resolved to null
Run Code Online (Sandbox Code Playgroud)
在将faces-config.xml从2.2版语法更改为2.3版语法后得到了它。
意思是,使用带有以下内容的faces-config.xml,一切正常:
<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
....
</faces-config>
Run Code Online (Sandbox Code Playgroud)
JSF 2.3.2部署在Payara 4.1.2.172(完整)服务器上,并且还添加到pom.xml中,“提供”范围。
....
<dependencies>
...
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.3.2</version>
<scope>provided</scope> …
Run Code Online (Sandbox Code Playgroud) 我有一个具有以下默认方法的接口:
default Integer getCurrentYear() {return DateUtil.getYear();}
Run Code Online (Sandbox Code Playgroud)
我还有一个实现此接口的控制器,但它不会覆盖该方法.
public class NotifyController implements INotifyController
Run Code Online (Sandbox Code Playgroud)
我试图从我的xhtml访问此方法,如下所示:
#{notifyController.currentYear}
Run Code Online (Sandbox Code Playgroud)
但是,当我打开屏幕时,会出现以下错误:
The class 'br.com.viasoft.controller.notify.notifyController' does not have the property 'anoAtual'
Run Code Online (Sandbox Code Playgroud)
如果我从我的控制器的实例访问此方法,它返回正确的值,但是当我尝试从我的xhtml访问它作为"属性"时,它会发生此错误.
有没有办法从我的控制器的引用访问此接口属性,而无需实现该方法?
我的项目是使用hibernate 3.4.0 GA访问数据库,Spring MVC 2.5.6用于处理Web请求,jsp(jstl)用于呈现视图(网页).
我通过hibernate从数据库中获取实体列表,并将其作为模型添加到jsp的modelmap中.当jsp渲染我的网页时,它会抛出"javax.el.PropertyNotFoundException".
javax.el.PropertyNotFoundException:在类型java.lang.String上找不到属性'timestamp'
而例外来自:
<c:forEach var="statusHistory" items="statusHistoryList">
${statusHistory.timestamp}
</c:forEach>
Run Code Online (Sandbox Code Playgroud)
似乎"statusHistory"被视为String,但不是对象.
"StatusHistory"类具有"timestamp"属性和getter方法:
public Class StatusHistory{
...
private Date timestamp;
public Date getTimestamp(){...}
...
}
Run Code Online (Sandbox Code Playgroud)
我在谷歌上搜索了一整天.有些帖子说getter方法不符合约定.但似乎不是我的情况.
有人可以帮帮我吗?
在此先感谢安德鲁