a4j:keepAlive and 'Target Unreachable' error
bitec Jun 7, 2009 1:47 PMHello.
Actually I use richfaces a long time, but only recently discovered very useful keepAlive tag, which allows to address bean properties in any "rendered" attributes with no fear. But with this tag I got the "Target Unreachable, '..' returned null" in some situations:
order_details.xhtml:
<a4j:keepAlive beanName="orderDetailsBean"/>
...
<h:panelGroup id="field_contract_group">
<h:selectOneMenu style="width:240px"
value="#{orderDetailsBean.entity.contract.id}"
styleClass="selectOneMenu" id="contr">
<f:selectItem itemValue="0" itemLabel="" />
<f:selectItems value="#{orderDetailsBean.filterContracts}" />
</h:selectOneMenu>
...
</h:panelGroup>
OrderDetailsBean.java:
private Order entity;
public Order getEntity(){..};
Order.java:
@ManyToOne(fetch = FetchType.LAZY)
@LazyToOne(LazyToOneOption.PROXY)
private Contract contract;
public Order() {
customer = new Customer();
contract = new Contract();
employee = new Employee();
}
public Contract getContract() {
/*if (contract == null) {
contract = new Contract();
}*/
return contract;
}
public void setContract(Contract contract) {
this.contract = contract;
}
The problem is that after submiting the form, if the selectOneMenu has an empty value, the following exception is raised:
Caused by: javax.el.PropertyNotFoundException: /order_details.xhtml @164,43 value="#{orderDetailsBean.entity.contract.id}": Target Unreachable, 'contract' returned null
at com.sun.facelets.el.TagValueExpression.getType(TagValueExpression.java:62)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:92)
at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:188)
at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:301)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:942)
at javax.faces.component.UIInput.validate(UIInput.java:868)I guess that richfaces serializes-deserializes bean, that's why the Contract object is null (I used to deal with this problem by constructing all dependencies - Contract, Employee and others in the constructor, but now all values are updated by deserialized values). I understand this is not exactly Richfaces problem, but it would be great, if anyone could help me.