747 | | |
| 747 | ==== Accessing a parent property that has not been initialized (usually set to null) ==== |
| 748 | |
| 749 | * Suppose one has the following code: |
| 750 | {{{ |
| 751 | |
| 752 | class Child extends BaseProObject { |
| 753 | |
| 754 | public Prop<Parent> parent() { |
| 755 | return getBean().makeParentProp(Parent.class); |
| 756 | } |
| 757 | |
| 758 | } |
| 759 | |
| 760 | class Parent extends BaseProObject { |
| 761 | |
| 762 | @Own |
| 763 | public RwProp<Child> child() { |
| 764 | return getBean().makeValueProp("child", Child.class); |
| 765 | } |
| 766 | |
| 767 | } |
| 768 | |
| 769 | }}} |
| 770 | |
| 771 | * If one tries to do the thing below a NotAvailableException will be thrown. |
| 772 | {{{ |
| 773 | Parent parent = new Parent(); |
| 774 | Child child = new Child(); |
| 775 | child.parent().get(); //null at this point. |
| 776 | parent.child().get(); //throws NotAvailableException |
| 777 | }}} |
| 778 | In order to use the above relation see... |
| 779 | {{{ |
| 780 | |
| 781 | Parent parent = new Parent(); |
| 782 | Child child = new Child(); |
| 783 | parent.child().set(child); |
| 784 | child.parent().get(); // child.parent().get() == parent |
| 785 | }}} |