javax.el.PropertyNotWritableException:集合操作的语法非法 [英] javax.el.PropertyNotWritableException: Illegal Syntax for Set Operation

查看:159
本文介绍了javax.el.PropertyNotWritableException:集合操作的语法非法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在JSF上学的一个项目,对此我几乎没有问题.

I'm making a project to school in JSF and I have few problems with that.

首先,当我想通过推送将自己重定向到项目的另一个页面时,h:commandButton无法正常工作.显示错误:

First of all, the h:commandButton doesn't work properly when I want to redirect myself to another page of the project by pushing it. There is an error displayed:

javax.el.PropertyNotWritableException:集合操作的语法非法

javax.el.PropertyNotWritableException: Illegal Syntax for Set Operation

index.jsp:

index.jsp:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>  
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>  

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
  <head>
<title>Firma Komputerowa - Baza Danych</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/table-style.css" />
  </head>
     <body>
       <f:view>
         <h:form>   
        <h:panelGrid columns="3">
     <h:commandButton action="#{producentBean.redirect }" value="Dodaj"/>
</h:panelGrid>
<h:panelGrid>
    <h:dataTable value="#{producentBean.List}" var="p" 
                styleClass="order-table"
                headerClass="order-table-header"
                rowClasses="order-table-odd-row,order-table-even-row" border="1" > 
        <h:column>
            <f:facet name="header">ID producenta</f:facet>
            <h:inputText value="#{p.getId}"/>
        </h:column>

        <h:column>
            <f:facet name="header">Nazwa producenta</f:facet>
            <h:inputText value="#{p.getNazwa}" />
        </h:column>

        <h:column>
            <f:facet name="header">NIP</f:facet>
            <h:inputText value="#{p.getNip}" />
        </h:column>

        <h:column>
            <f:facet name="header">REGON</f:facet>
            <h:inputText value="#{p.getRegon}" />
        </h:column>

        <h:column>
            <f:facet name="header">Miasto</f:facet>
            <h:inputText value="#{p.getMiasto}" />
        </h:column>

        <h:column>
            <f:facet name="header">Adres</f:facet>
            <h:inputText value="#{p.getAdres}" />
        </h:column>

        <h:column>
            <f:facet name="header">Telefon</f:facet>
            <h:inputText value="#{p.getTel}" />
        </h:column>

        <h:column>
            <f:facet name="header">E-mail</f:facet>
            <h:inputText value="#{p.getEmail}" />
        </h:column>
    </h:dataTable>
</h:panelGrid>
        </h:form>
       </f:view>
    ...
   </body>
</html>

ProducentBean.java:

ProducentBean.java:

    public class ProducentBean extends Polacz implements Serializable {

   public String redirect() {
    return "dodaj_pr";
}
}

我试图通过多种方式做到这一点,但我无法应对.

I was trying to do it in many ways, but I can't deal with it.

我还有另一个问题:JSF中是否有可能从数据库动态显示表,例如通过选择表名并在其中选择一个选项?我的数据库包含三个表,每个表具有不同的列数.

I also have an another question: is there in JSF a possibility to display a table dynamically from database, for example by choosing a table name selecting an option in ? My database contains three tables with different count of colums each.

如果有人给我一些建议,我会很高兴.

I'll be very happy if somebody gives me some advices.

好的,我尝试这样做:

private String dodajPrUrl = "dodaj_pr?faces-redirect=true";

public String getDodajPrUrl() {
    return this.dodajPrUrl;
}

public void setDodajPrUrl(String newUrl) {
    this.dodajPrUrl = newUrl;
}

以及在index.jsp中:

and in index.jsp:

<h:commandButton action="#{producentBean.redirect }" value="Dodaj" />

它仍然给我同样的错误.

It gives me still the same error.

堆栈跟踪:

SEVERE: javax.faces.FacesException: javax.el.PropertyNotWritableException: Illegal Syntax for Set Operation
javax.faces.FacesException: javax.el.PropertyNotWritableException: Illegal Syntax for  Set Operation
    at com.sun.faces.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:142)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
    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:860)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    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)
Caused by: javax.faces.component.UpdateModelException: javax.el.PropertyNotWritableException: Illegal Syntax for Set Operation
    at javax.faces.component.UIInput.updateModel(UIInput.java:853)
    at javax.faces.component.UIInput.processUpdates(UIInput.java:735)
    at javax.faces.component.UIData.iterate(UIData.java:2001)
    at javax.faces.component.UIData.processUpdates(UIData.java:1253)
    at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
    at javax.faces.component.UIForm.processUpdates(UIForm.java:281)
    at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
    at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1231)
    at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    ... 26 more
Caused by: javax.el.PropertyNotWritableException: Illegal Syntax for Set Operation
    at com.sun.el.parser.AstValue.setValue(AstValue.java:207)
    at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:291)
    at javax.faces.component.UIInput.updateModel(UIInput.java:818)
    ... 35 more

推荐答案

查看堆栈跟踪.这是最重要的部分:

Look at the stack trace. Here's the most important part:

Caused by: javax.faces.component.UpdateModelException: javax.el.PropertyNotWritableException: Illegal Syntax for Set Operation
    at javax.faces.component.UIInput.updateModel(UIInput.java:853)
    at javax.faces.component.UIInput.processUpdates(UIInput.java:735)
    at javax.faces.component.UIData.iterate(UIData.java:2001)
    at javax.faces.component.UIData.processUpdates(UIData.java:1253)
    at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
    at javax.faces.component.UIForm.processUpdates(UIForm.java:281)
    at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
    at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1231)
    at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    ... 26 more

从下至上阅读.在更新模型值阶段,JSF从UIViewRoot组件(<f:view>)开始遍历组件树.在UIForm组件(<h:form>)中,存在一个UIData组件(<h:dataTable>),该组件具有需要处理的UIInput组件(<h:inputText>). updateModel()基本上需要将提交的,转换的和经过验证的值放入模型(托管Bean)中.但是,该操作失败,因为该属性不可写(即无法根据EL表达式语法找到setter方法).

Read from bottom to top. During update model values phase, JSF is traversing the component tree starting from UIViewRoot component (<f:view>). In an UIForm component (<h:form>) there is an UIData component (<h:dataTable>) which has an UIInput component (<h:inputText>) which needs to be processed. The updateModel() basically needs to put the submitted, converted and validated value in the model (the managed bean). However, that operation has failed because the property is not writable (i.e. the setter method cannot be found based on the EL expression syntax).

好吧,让我们大致了解一下<h:inputText>组件的属性.

Well, let's look at the properties of your <h:inputText> components in general.

<h:inputText value="#{p.getId}"/>
...
<h:inputText value="#{p.getNazwa}" />
...
<h:inputText value="#{p.getNip}" />

等等,这很奇怪.他们都以"get"开始!这绝对是不正常的.然后,JSF正在寻找诸如setGetId()setGetNazwa()之类的方法,这些方法没有任何意义(鉴于这种例外情况,您可能也没有).期望它们代表具体的属性名称,例如"id","nazwa","nip"等,而不是完整的方法名称.

Wait, that's strange. They start all with "get"! This is definitely not normal. JSF is then looking for methods like setGetId(), setGetNazwa(), etc which just doesn't make sense (and you likely also don't have, given this exception). It's expected that they represent concrete property names like "id", "nazwa", "nip", etc and not full method names.

因此,在模型中:

private Long id;
private String nazwa;
private String nip;

// Add/generate getters and setters in the following syntax:

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

// ...

因此在视图中:

<h:inputText value="#{p.id}"/>
...
<h:inputText value="#{p.nazwa}" />
...
<h:inputText value="#{p.nip}" />

然而,这已经在一些理智的JSF书籍/教程/资源中进行了介绍.您绝对肯定自己在阅读正确的文章吗?您的问题还表明,您正在将JSF 2.0与已弃用的 JSP视图技术结合使用,而不是其后继的Facelets.从我们的JSF Wiki页面开始.

This is however already covered in a bit sane JSF book/tutorial/resource. Are you absolutely positive that you were reading the right one? Your question also shows that you're using JSF 2.0 in combination with the deprecated JSP view technology instead of its successor Facelets. Start at our JSF wiki page.

这篇关于javax.el.PropertyNotWritableException:集合操作的语法非法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆