尝试将一些值从jsf页面发送到bean时出现此错误。
我想将值设置为bean中的字段,然后创建一个Airplane实例并将其添加到我的数据库中。但是我收到一个错误,告诉我我使用非法语法来设置bean的setter部分。
为什么我会收到错误?我在这个网站上找不到任何帮我解决问题的方法。
这是jsf部分:
<h4>Add A Plane</h4>
<c:if test="#{not empty listAirplaneBB.error}">
<div class="alert alert-danger">
<span class="glyphicon glyphicon-remove"></span> <h:outputText value="#{listAirplaneBB.error}" />
</div>
</c:if>
<h:form>
<table class="table">
<thead>
<tr>
<th>Plane Make</th>
<th colspan="1">Plane Model</th>
<th colspan="1">Plane Seats</th>
</tr>
</thead>
<tr>
<td>
<h:inputText value="#{addAirplaneCtrl.setMake(make)}">
<f:validateLength minimum="3" />
</h:inputText>
</td>
<td>
<h:inputText id="lastname" value="#{addAirplaneCtrl.setModel(model)}">
<f:validateLength minimum="3" />
</h:inputText>
</td>
<td>
<h:inputText value="#{addAirplaneCtrl.setSeats(seats)}">
<f:validateLength minimum="1" />
</h:inputText>
</td>
<td>
<h:commandButton value="Add Plane" class="btn btn-primary" action="#{addAirplaneCtrl.addPlane()}" />
</td>
</tr>
</table>
</h:form>
这是豆子:
@Named
@RequestScoped
public class AddAirplaneCtrl implements Serializable{
@Inject
private FlightModel flightModel;
private ListAirplaneBB listAirplaneBB;
private String make;
private String model;
private String seats;
private static final String PLANE_EXIST = "Plane already exists";
private static final String EMPTY_FIELDS = "Please fill in all fields";
protected AddAirplaneCtrl(){
;
}
/*
TO DO LIST
error handling
*/
public String addPlane(){
//make sure all fields are filled, otherwise set error and return redirect false
if(make == null || model == null || seats == null){
listAirplaneBB.setError(EMPTY_FIELDS);
return "/private/admin/admincenter?faces-redirect=false";
}
//create planeId
String pId = make.substring(0, 1);
pId += model;
//upload photo in new method [Meet requirements, rename photoID planeId, upload to folder]
//check if exist
List<Airplane> airplaneList = flightModel.getAirplaneList().getByAirplaneId(pId);
if(!airplaneList.isEmpty()){
listAirplaneBB.setError(PLANE_EXIST);
return "/private/admin/admincenter?faces-redirect=false";
}
//add plane
Airplane airplane = new Airplane(make, model, pId, seats);
flightModel.getAirplaneList().create(airplane);
return "/private/admin/admincenter?faces-redirect=true";
}
public String deleteAirplane(String planeId){
return "";
}
/**
* @param make the make to set
*/
public void setMake(String make) {
this.make = make;
}
/**
* @param model the model to set
*/
public void setModel(String model) {
this.model = model;
}
/**
* @param seats the seats to set
*/
public void setSeats(String seats) {
this.seats = seats;
}
}
这是错误:
javax.faces.component.UpdateModelException: javax.el.PropertyNotWritableException: /private/admin/admincenter.xhtml @118,87 value="#{addAirplaneCtrl.setMake(make)}": Illegal Syntax for Set Operation
at javax.faces.component.UIInput.updateModel(UIInput.java:866)
at javax.faces.component.UIInput.processUpdates(UIInput.java:749)
at javax.faces.component.UIForm.processUpdates(UIForm.java:281)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1286)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1286)
at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1254)
at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at edu.cth.dzenkyair.frontend.auth.AdminFilter.doFilter(AdminFilter.java:40)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at edu.cth.dzenkyair.frontend.auth.UserFilter.doFilter(UserFilter.java:39)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.PropertyNotWritableException: /private/admin/admincenter.xhtml @118,87 value="#{addAirplaneCtrl.setMake(make)}": Illegal Syntax for Set Operation
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:136)
at javax.faces.component.UIInput.updateModel(UIInput.java:832)
... 45 more
Caused by: javax.el.PropertyNotWritableException: Illegal Syntax for Set Operation
at com.sun.el.parser.AstValue.setValue(AstValue.java:228)
at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:294)
at org.jboss.weld.el.WeldValueExpression.setValue(WeldValueExpression.java:64)
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
... 46 more
答案 0 :(得分:2)
JSF使用ManagedBeans,托管bean使用bean标准,即实现可序列化,封装和空构造函数
facelets可以通过表达式语言与托管bean通信,并将使用任何 EditableValueHolder UIComponent的setter。
在您的情况下,您正在使用的 EditableValueHolder 是<h:inputText />
组件,当您使用value=""
属性时,调用setter的正确方法将是使用您尝试设置的属性的名称,这是一个示例:
<强>豆:强>
@Named or @ManageBean
@some_scope
public class YourBean implements Serializable{
private String make;
public void setMake(String make){
this.make = make;
}
public String getMake(){
return this.make;
}
}
<强>的facelet:强>
// will call the setMake(String make) method
<h:inputText value="#{yourBean.make}" />
// will call the getMake() method
<h:outputText value="#{yourBean.make}" />
答案 1 :(得分:1)
您不需要在表达式语言上编写“set”描述,只需编写
即可 <h:inputText value="#{addAirplaneCtrl.make}">
然后jsf将尝试在提交时在bean上找到方法setMake,因为你将它放在inputText组件上。