Return-Path: Delivered-To: apmail-myfaces-users-archive@www.apache.org Received: (qmail 36881 invoked from network); 30 May 2008 08:27:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 30 May 2008 08:27:23 -0000 Received: (qmail 20192 invoked by uid 500); 30 May 2008 08:27:22 -0000 Delivered-To: apmail-myfaces-users-archive@myfaces.apache.org Received: (qmail 19945 invoked by uid 500); 30 May 2008 08:27:21 -0000 Mailing-List: contact users-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Discussion" Delivered-To: mailing list users@myfaces.apache.org Received: (qmail 19934 invoked by uid 99); 30 May 2008 08:27:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 May 2008 01:27:21 -0700 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [194.152.182.1] (HELO mgate.ops.co.at) (194.152.182.1) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 May 2008 08:26:27 +0000 Received: from smtp.ops.co.at (smtp.int.ops.co.at [172.27.0.4]) by mgate.ops.co.at (OPS Mail Gateway - authorized use only - NO UCE/UBE C=AT L=VIE) with ESMTP id 379E5AFE4F for ; Fri, 30 May 2008 10:26:48 +0200 (CEST) Received: by smtp.ops.co.at (Postfix, from userid 65534) id AE51F6E023F; Fri, 30 May 2008 10:26:46 +0200 (CEST) Received: from [172.27.1.104] (lints2.int.ops.co.at [172.27.1.104]) by smtp.ops.co.at (Postfix) with ESMTP id 22CF26E0234 for ; Fri, 30 May 2008 10:26:46 +0200 (CEST) Message-ID: <483FBA47.1060001@chello.at> Date: Fri, 30 May 2008 10:26:47 +0200 From: "simon.kitching@chello.at" User-Agent: Thunderbird 2.0.0.0 (X11/20070418) MIME-Version: 1.0 To: MyFaces Discussion Subject: Re: duplication POJO and JSF beans References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam-Checker-Version: SpamAssassin 2.64 (2004-01-11) on smtp.ops.co.at X-Spam-Level: X-Virus-Checked: Checked by ClamAV on apache.org X-Old-Spam-Status: No, hits=-3.6 required=7.0 tests=AWL,BAYES_00,LOCAL_SPAMWORDS, RATWR10_MESSID,SARE_TOCC_USER autolearn=no version=2.64 Anton Gavazuk schrieb: > Hi all, > > I'm using JPA as persistence layer, and one of my modules contains > more then 50 entities. > Almost all of those entities (POJO) I must somehow show in UI. > But in UI some POJOs should have extra fields - value for this fields > is generated according to business logic, so the value is not a part > of actual entity. > Yep, common problem. > Simple Example > > CorePojo > int a; > int b; > int generatedValue = businessFunction.(a,b); > .... > > I dont like approach when this "generated" value is being added to > core POJO with @Transient mark - on other hand I dont' want to create > in my JSF application copy of every original POJO with extra fields. > Yep, that solution is pretty ugly. > So the only one way which I see now - create new POJO for UI which > extends CorePojo and adds needed fields. > The problem with creating a subclass of the real persistent pojo is that these "ui-specific" pojos must be different instances from the ones dealt with by the ui, so data must be copied back and forth between the persistent pojos and the ui versions. > So my question is: > does someone come accross with same situation? How it can be resolved? > The solution I've most commonly used is to write wrapper classes that add the UI-specific methods, ie something like: public class UICorePojo { public CorePojo getCorePojo() {...} // the persistent object public int getGeneratedValue() {...} // the "added" functionality } then use EL expressions like #{foo.corePojo.a} #{foo.generatedValue} Unfortunately this does mean the EL is "aware" of the difference between the "real" methods and the added ones. On one project I used, CGLIB was used to transparently generate a proxy class that effectively did what the above code does, but also made the CorePojo methods available on the generated proxy. Then the EL can consistently access the proxy, with the method being delegated to the appropriate handler. I suspect that using Spring's AOP support could make this quite easy to do. Regards, Simon