4 Replies Latest reply on Jun 8, 2009 7:15 PM by nbelaevski

    a4j:keepAlive and 'Target Unreachable' error

    bitec

      Hello.

      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.

        • 1. Re: a4j:keepAlive and 'Target Unreachable' error
          nbelaevski

          Hi,

          Yes, bean is being serialized and deserialized. You can use

           private void readObject(java.io.ObjectInputStream in)
           throws IOException, ClassNotFoundException;
          to wire deserialized object to beans.

          • 2. Re: a4j:keepAlive and 'Target Unreachable' error
            bitec

            Thank you.

            I tried the following:

            public class OrderDetailsBean extends AbstractDetailsBean<Order> implements Serializable {
            ...
             private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
             in.defaultReadObject();
            
             if (this.entity.getContract() == null) {
             entity.setContract(new Contract());
             }
             }
            }
            


            But on some reason this method is not even called (debugger doesn't stop anywhere) and the exception still occurs.

            • 3. Re: a4j:keepAlive and 'Target Unreachable' error
              bitec

              Also would like to add that this method is called (debugger shows this) when the context is reloaded and the session objects are serialized. Seems the bean isn't serialized when 'keepAlive' tag is used or serialized not using standard java serialization mechanizm...

              • 4. Re: a4j:keepAlive and 'Target Unreachable' error
                nbelaevski

                Serialization happens either with client type of state saving or when explicitly turned on in web.xml. If readObject() is not called, then serialization does not happen at all and there should be another reason of dependencies lost.