我正在 JSF 中为学校制作一个项目,对此我几乎没有问题。
首先,当我想通过推送将自己重定向到项目的另一个页面时,h:commandButton 无法正常工作。显示错误:
javax.el.PropertyNotWritableException:集合操作的非法语法
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:
public class ProducentBean extends Polacz implements Serializable {
public String redirect() {
return "dodaj_pr";
}
}
我试图以多种方式做到这一点,但我无法应对。
我还有另一个问题:在 JSF 中是否有可能从数据库中动态显示一个表,例如通过选择一个表名来选择一个选项?我的数据库包含三个表,每个表的列数不同。
如果有人给我一些建议,我会很高兴。
编辑:
好的,我试着这样做:
private String dodajPrUrl = "dodaj_pr?faces-redirect=true";
public String getDodajPrUrl() {
return this.dodajPrUrl;
}
public void setDodajPrUrl(String newUrl) {
this.dodajPrUrl = newUrl;
}
在 index.jsp 中:
<h:commandButton action="#{producentBean.redirect }" value="Dodaj" />
它仍然给我同样的错误。
编辑2:
堆栈跟踪:
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