Ok, I still would like Steve&#39;s input on this one.<br><br>How should we do this?<br>~Lincoln<br><br><div class="gmail_quote">On Wed, Nov 9, 2011 at 8:48 AM, Richard Kennard <span dir="ltr">&lt;<a href="mailto:richard@kennardconsulting.com">richard@kennardconsulting.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Sorry, bad example. I meant more like:<br>
<br>
    #{customerBean.customer.address}<br>
<br>
So originally the Forge scaffolding did this:<br>
<br>
    public class CustomerBean<br>
<br>
        ...<br>
        private Customer customer = new Customer();<br>
        ...<br>
    }<br>
<br>
So at construction time, basically. This pattern would need extending:<br>
<br>
    public class CustomerBean extends PersistenceUtil implements MenuItem {<br>
<br>
        ...<br>
        private Customer customer;<br>
        ...<br>
        public CustomerBean() {<br>
            customer = new Customer();<br>
            customer.setAddress( new Address() );<br>
        }<br>
        ...<br>
<div class="im">    }<br>
<br>
<br>
<br>
<br>
<br>
On 9/11/2011 6:02 PM, Lincoln Baxter, III wrote:<br>
&gt; It looks like, from this thread, the view layer is accessing an entity directly via &quot;#{customer}&quot; - this is not a good practice in general, however, if<br>
&gt; it is to be done, then what needs to happen, I think, is that &quot;Customer&quot; be initialized in whatever method is producing it.<br>
&gt;<br>
&gt; I&#39;ve copied Steve Ebersole because he is probably the best person to answer this question (I hope this is OK Steve. We want to get this stuff right in<br>
&gt; Forge.)<br>
&gt;<br>
&gt; E.g:<br>
&gt;<br>
&gt; @Produces<br>
&gt; @Named(&quot;customer&quot;)<br>
&gt; public Customer getCustomer()<br>
&gt; {<br>
&gt;    if(customer == null)<br>
&gt;    {<br>
&gt;       customer = new Customer();<br>
&gt;       customer.setAddress(new Address());<br>
&gt;    }<br>
&gt; }<br>
&gt;<br>
&gt; Is this on the same page? I don&#39;t think doing this in the Entity itself is correct. Thoughts?<br>
&gt; ~Lincoln<br>
&gt;<br>
</div><div class="im">&gt; On Wed, Nov 9, 2011 at 7:23 AM, Jason Porter &lt;<a href="mailto:lightguard.jp@gmail.com">lightguard.jp@gmail.com</a> &lt;mailto:<a href="mailto:lightguard.jp@gmail.com">lightguard.jp@gmail.com</a>&gt;&gt; wrote:<br>

&gt;<br>
&gt;     If Seam Faces or PrettyFaces is being used then their view action ability would be used. If vanilla JSF is being used, then we need to figure out the<br>
&gt;     best way to make this happen, which it looks like isn&#39;t all that easy :(<br>
&gt;<br>
&gt;     The idea is in the method would set a new instance of Address on the class so it&#39;s instantiated when the user goes to fill it out. Of course if<br>
&gt;     things aren&#39;t filled out then you&#39;d have an empty address instance persisted, could be good or bad, that really depends on the app.<br>
&gt;<br>
&gt;     I know that&#39;s a fairly simplistic explanation, but it is the high level idea. Did it come across clearly?<br>
&gt;<br>
&gt;<br>
</div><div class="im">&gt;     On Tue, Nov 8, 2011 at 22:27, Richard Kennard &lt;<a href="mailto:richard@kennardconsulting.com">richard@kennardconsulting.com</a> &lt;mailto:<a href="mailto:richard@kennardconsulting.com">richard@kennardconsulting.com</a>&gt;&gt; wrote:<br>

&gt;<br>
&gt;         Jason,<br>
&gt;<br>
&gt;         Okay agreed. Could you explain how you would see the &#39;view action&#39; approach working?<br>
&gt;<br>
&gt;         Richard.<br>
&gt;<br>
&gt;         On 9/11/2011 4:24 PM, Jason Porter wrote:<br>
&gt;         &gt; It may boil down to which way we believe is the &quot;correct&quot; way. For all of the Forge plugins we&#39;ve been trying to have then generated code use<br>
&gt;         best practices.<br>
&gt;         &gt;<br>
&gt;         &gt; This helps lessen support as hopefully, the patterns will be repeated and they&#39;ll be done correctly with fewer bugs. This approach also helps<br>
&gt;         to educate people, though we could certainly do a better job at that by documenting why Forge is generating code a certain way.<br>
&gt;         &gt;<br>
&gt;         &gt; I suggested my proposal as I view this as an interaction problem with the persistence model, not a problem with that model. Therefore, my<br>
&gt;         solution kept the fix closer to the problem, or at least as I see it, it does :)<br>
&gt;         &gt;<br>
&gt;         &gt; However, I&#39;m not tied to a particular solution and could be persuaded to others. I think some more discussion will provide a good approach.<br>
&gt;         &gt;<br>
&gt;         &gt; Sent from my iPhone<br>
&gt;         &gt;<br>
</div><div class="im">&gt;         &gt; On Nov 8, 2011, at 22:15, Richard Kennard &lt;<a href="mailto:richard@kennardconsulting.com">richard@kennardconsulting.com</a> &lt;mailto:<a href="mailto:richard@kennardconsulting.com">richard@kennardconsulting.com</a>&gt;&gt; wrote:<br>

&gt;         &gt;<br>
&gt;         &gt;&gt; I don&#39;t believe it will upset JPA, no. It *would* if you did:<br>
&gt;         &gt;&gt;<br>
&gt;         &gt;&gt;    public Address getAddress() {<br>
&gt;         &gt;&gt;        if ( this.address == null ) { this.address = new Address(); }<br>
&gt;         &gt;&gt;        return address;<br>
&gt;         &gt;&gt;    }<br>
&gt;         &gt;&gt;<br>
&gt;         &gt;&gt; Because JPA will call setAddress(null) and then getAddress() and get back a different result. But if the field is just initialised to a<br>
&gt;         default value...<br>
&gt;         &gt;&gt;<br>
&gt;         &gt;&gt;    private Address address = new Address();<br>
&gt;         &gt;&gt;<br>
&gt;         &gt;&gt; ...then JPA will overwrite it with setAddress(null) and it&#39;ll be okay.<br>
&gt;         &gt;&gt;<br>
&gt;         &gt;&gt; But sure, if there is a nicer way to do it I don&#39;t mind doing it a different way?<br>
&gt;         &gt;&gt;<br>
&gt;         &gt;&gt; Richard.<br>
&gt;         &gt;&gt;<br>
&gt;         &gt;&gt; On 9/11/2011 4:11 PM, Jason Porter wrote:<br>
&gt;         &gt;&gt;&gt; Won&#39;t this cause issues with the JPA impl? From my conversations with the Hibernate devs if what is returned from the property (getter/field)<br>
&gt;         is not what was set by JPA then extra db actions are performed.<br>
&gt;         &gt;&gt;&gt;<br>
&gt;         &gt;&gt;&gt; IMO, this an integration point for the JSF or EL specs. I think, though, this is an instantiation issue and should be done with a view action<br>
&gt;         instead.<br>
&gt;         &gt;&gt;&gt;<br>
&gt;         &gt;&gt;&gt; Sent from my iPhone<br>
&gt;         &gt;&gt;&gt;<br>
</div><div class="im">&gt;         &gt;&gt;&gt; On Nov 8, 2011, at 21:37, Richard Kennard &lt;<a href="mailto:richard@kennardconsulting.com">richard@kennardconsulting.com</a> &lt;mailto:<a href="mailto:richard@kennardconsulting.com">richard@kennardconsulting.com</a>&gt;&gt; wrote:<br>

&gt;         &gt;&gt;&gt;<br>
&gt;         &gt;&gt;&gt;&gt; Hi guys,<br>
&gt;         &gt;&gt;&gt;&gt;<br>
&gt;         &gt;&gt;&gt;&gt; As you&#39;re probably aware, in JSF if I do...<br>
&gt;         &gt;&gt;&gt;&gt;<br>
&gt;         &gt;&gt;&gt;&gt;   #{customer}<br>
&gt;         &gt;&gt;&gt;&gt;<br>
&gt;         &gt;&gt;&gt;&gt; ...then a Customer object will get instantiated &#39;just in time&#39;. But if I do...<br>
&gt;         &gt;&gt;&gt;&gt;<br>
&gt;         &gt;&gt;&gt;&gt;   #{customer.address.street}<br>
&gt;         &gt;&gt;&gt;&gt;<br>
&gt;         &gt;&gt;&gt;&gt; ...then &#39;address&#39; will *not* get instantiated just in time. So if you use Forge to do...<br>
&gt;         &gt;&gt;&gt;&gt;<br>
&gt;         &gt;&gt;&gt;&gt;   entity --named Customer<br>
&gt;         &gt;&gt;&gt;&gt;   field custom --named address<br>
&gt;         &gt;&gt;&gt;&gt;   [what custom type m&#39;lord?] com.test.domain.Address<br>
&gt;         &gt;&gt;&gt;&gt;<br>
&gt;         &gt;&gt;&gt;&gt; Then although you&#39;ll get a UI that includes a Customer with an embedded Address, it&#39;ll fail as soon as you try to save. There isn&#39;t a very<br>
&gt;         good solution to<br>
&gt;         &gt;&gt;&gt;&gt; this, so can I suggest the simplest?<br>
&gt;         &gt;&gt;&gt;&gt;<br>
&gt;         &gt;&gt;&gt;&gt; When Forge generates field/getter/setter for a custom type (possibly limited to the project&#39;s domain package), could it do:<br>
&gt;         &gt;&gt;&gt;&gt;<br>
&gt;         &gt;&gt;&gt;&gt;   @Column<br>
&gt;         &gt;&gt;&gt;&gt;   private Address address *=new Address();*<br>
&gt;         &gt;&gt;&gt;&gt;<br>
&gt;         &gt;&gt;&gt;&gt;   public Address getAddress() {<br>
&gt;         &gt;&gt;&gt;&gt;       return this.address;<br>
&gt;         &gt;&gt;&gt;&gt;   }<br>
&gt;         &gt;&gt;&gt;&gt;<br>
&gt;         &gt;&gt;&gt;&gt;   public void setAddress(final Address address) {<br>
&gt;         &gt;&gt;&gt;&gt;       this.address = address;<br>
&gt;         &gt;&gt;&gt;&gt;   } }<br>
&gt;         &gt;&gt;&gt;&gt;<br>
&gt;         &gt;&gt;&gt;&gt; _______________________________________________<br>
&gt;         &gt;&gt;&gt;&gt; forge-dev mailing list<br>
</div>&gt;         &gt;&gt;&gt;&gt; <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a>&gt;<br>
<div class="im">&gt;         &gt;&gt;&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
&gt;         &gt;&gt;&gt; _______________________________________________<br>
&gt;         &gt;&gt;&gt; forge-dev mailing list<br>
</div>&gt;         &gt;&gt;&gt; <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a>&gt;<br>
<div class="im">&gt;         &gt;&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
&gt;         &gt;&gt;&gt;<br>
&gt;         &gt;&gt;&gt;<br>
&gt;         &gt;&gt; _______________________________________________<br>
&gt;         &gt;&gt; forge-dev mailing list<br>
</div>&gt;         &gt;&gt; <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a>&gt;<br>
<div class="im">&gt;         &gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
&gt;         &gt; _______________________________________________<br>
&gt;         &gt; forge-dev mailing list<br>
</div>&gt;         &gt; <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a>&gt;<br>
<div class="im">&gt;         &gt; <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
&gt;         &gt;<br>
&gt;         &gt;<br>
&gt;<br>
&gt;         _______________________________________________<br>
&gt;         forge-dev mailing list<br>
</div>&gt;         <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a>&gt;<br>
<div class="im">&gt;         <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;     --<br>
&gt;     Jason Porter<br>
&gt;     <a href="http://lightguard-jp.blogspot.com" target="_blank">http://lightguard-jp.blogspot.com</a><br>
&gt;     <a href="http://twitter.com/lightguardjp" target="_blank">http://twitter.com/lightguardjp</a><br>
&gt;<br>
&gt;     Software Engineer<br>
&gt;     Open Source Advocate<br>
&gt;     Author of Seam Catch - Next Generation Java Exception Handling<br>
&gt;<br>
&gt;     PGP key id: 926CCFF5<br>
</div>&gt;     PGP key available at: <a href="http://keyserver.net" target="_blank">keyserver.net</a> &lt;<a href="http://keyserver.net" target="_blank">http://keyserver.net</a>&gt;, <a href="http://pgp.mit.edu" target="_blank">pgp.mit.edu</a> &lt;<a href="http://pgp.mit.edu" target="_blank">http://pgp.mit.edu</a>&gt;<br>

&gt;<br>
&gt;     _______________________________________________<br>
&gt;     forge-dev mailing list<br>
&gt;     <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a>&gt;<br>
<div class="im">&gt;     <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Lincoln Baxter, III<br>
&gt; <a href="http://ocpsoft.com" target="_blank">http://ocpsoft.com</a><br>
&gt; <a href="http://scrumshark.com" target="_blank">http://scrumshark.com</a><br>
&gt; &quot;Keep it Simple&quot;<br>
&gt;<br>
&gt;<br>
</div><div><div></div><div class="h5">&gt; _______________________________________________<br>
&gt; forge-dev mailing list<br>
&gt; <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
<br>
_______________________________________________<br>
forge-dev mailing list<br>
<a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Lincoln Baxter, III<br><a href="http://ocpsoft.com">http://ocpsoft.com</a><br><a href="http://scrumshark.com">http://scrumshark.com</a><br>&quot;Keep it Simple&quot;<br>