我遇到了一个奇怪的问题,我不知道为什么会发生这种情况,我得到了这样的类:
@ManagedBean(name = "clientBean")
@SessionScoped
public class ClientBean implements Serializable {
private static final long serialVersionUID = 1L;
private ClientDao clientDao = new ClientDao();
private SearchService searchService = new SearchService();
private String tags;
private Client client = new Client();
private Order order = new Order();
和我有一部分。xhtml:
<div class="form-group">
<label style="padding-top: 0px" class="col-sm-3 control-label">Tytuł zamówienia</label>
<div class="col-sm-9">
<h:inputText type="text"
value="#{clientBean.order.title}"
class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Status</label>
<div class="col-sm-9">
<h:inputText type="text" value="PRZETWARZANIE"
class="form-control" disabled="true" />
</div>
</div>
问题是……为什么我不能设置order.title
的值?客户端类中的client.name
和其他字段没有问题,但是当我尝试用订单的属性设置表单字段并进入此视图时,会出现这种异常(我得到了所有getter和setter):
SEVERE: Error Rendering View[/clients.xhtml]
javax.el.PropertyNotFoundException: /clientRegistration.xhtml @112,67 value="#{clientBean.order.title}": Property 'order' not found on type com.firanycrm.controller.ClientBean
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:174)
at javax.faces.component.UIInput.getValue(UIInput.java:291)
对于JSF获取/设置您的属性,您需要有getter和setter的一切,无论是在ClientBean
类和类它引用Order
, Client
等。确保你有所有这些getter和setter,我建议如果你使用像Eclipse这样的IDE(右键单击> source> generate getter和setter),直接生成它们。