Return-Path: Delivered-To: apmail-myfaces-users-archive@www.apache.org Received: (qmail 30635 invoked from network); 20 Apr 2007 15:33:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Apr 2007 15:33:58 -0000 Received: (qmail 91884 invoked by uid 500); 20 Apr 2007 15:34:00 -0000 Delivered-To: apmail-myfaces-users-archive@myfaces.apache.org Received: (qmail 91856 invoked by uid 500); 20 Apr 2007 15:34:00 -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 91845 invoked by uid 99); 20 Apr 2007 15:34:00 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Apr 2007 08:33:59 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (herse.apache.org: local policy) Received: from [198.240.128.81] (HELO ln-bas08.csfb.com) (198.240.128.81) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Apr 2007 08:33:52 -0700 Received: from slon11p30741.csfb.cs-group.com (slon11p30741.csfb.mail [166.12.48.145]) by ln-bas08.csfb.com (Postfix) with ESMTP id BD0D6335F for ; Fri, 20 Apr 2007 16:33:29 +0100 (BST) Received: from [166.12.100.15] by slon11p30741.csfb.cs-group.com with ESMTP (P30741L (Email Firewall v6.3.1)); Fri, 20 Apr 2007 16:33:23 +0100 X-Server-Uuid: 0B8A1BB7-B238-48F9-9D9D-7A0E644CA9BB Received: by slon11p31502.csfb.cs-group.com with Internet Mail Service ( 5.5.2653.19) id ; Fri, 20 Apr 2007 16:33:22 +0100 Message-ID: <92F4F49152E28B45B80BD95EB6F1F5390184D9A7@enyc11p32003.corpny.csfb.com> From: "Leyzerzon, Simeon" To: "'MyFaces Discussion'" Subject: RE: Dynamic Value binding - please help! Date: Fri, 20 Apr 2007 16:33:14 +0100 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) X-WSS-ID: 6A3602C938W53378-01-03 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Hah! That works, thanks, but now I'm facing a new complication: #{rptPeriod.reportingDateMonthly} and #{rptPeriod.reportingDateMonthly} doesn't seem to be mapping to the right field in the underlying bean. Let me explain... 'rtpPeriod' is a representation of ReportingPeriod bean, instances of which populate the collection behind component. These ReportingPeriod beans have 3 properties for display, each formatted differently, and set by Spring-based DAOlike this: public void setReportingDate(Date reportingDate) { //logger.debug("set reporting date to: " + reportingDate); this.reportingDate = reportingDate; this.setReportingDateDaily(new SimpleDateFormat("MMM dd yyyy").format(reportingDate)); this.setReportingDateMonthly(new SimpleDateFormat("MMM yyyy").format(reportingDate)); this.setRawDate(new SimpleDateFormat("MM/dd/yyyy").format(reportingDate)); } What I see on the page though, is a combo box with the content populated in the following manner: 03/01/2007 02/01/2007 01/01/2007, etc. That is instead of using #{rptPeriod.reportingDateMonthly} or #{rptPeriod.reportingDateDaily}, #{rtpPeriod.rawDate} seems to be used. Here is my current code: ===================================================================================================================================== public void setReportingPeriodSelectOneMenuControl( HtmlSelectOneMenu reportingPeriodSelectOneMenuControl) { if (reportingPeriods == null){ logger.debug("reportingPeriods == null: " + (reportingPeriods==null) + "building reportingPeriods list..."); reportingPeriods = this.getSearchService().getReportingPeriods(); } //building if (reportingPeriodsSelectItemsControl == null){ reportingPeriodsSelectItemsControl = (UISelectItems) FacesContext .getCurrentInstance().getApplication().createComponent( UISelectItems.COMPONENT_TYPE); } reportingPeriodsSelectItemsControl.setValue(reportingPeriods); reportingPeriodsSelectItemsControl.setVar("rptPeriod"); if (DAILY.equals(this.getPeriod())) { reportingPeriodsSelectItemsControl.setValueBinding("itemLabel", FacesContext.getCurrentInstance().getApplication() .createValueBinding( "#{rptPeriod.reportingDateDaily}")); }else if (MONTHLY.equals(this.getPeriod())) { reportingPeriodsSelectItemsControl.setValueBinding("itemLabel", FacesContext.getCurrentInstance().getApplication() .createValueBinding( "#{rptPeriod.reportingDateMonthly}")); } reportingPeriodsSelectItemsControl.setValueBinding("itemValue", FacesContext.getCurrentInstance().getApplication().createValueBinding("#{rptPeriod.rawDate}")); reportingPeriodSelectOneMenuControl.getChildren().add(reportingPeriodsSelectItemsControl); this.reportingPeriodSelectOneMenuControl = reportingPeriodSelectOneMenuControl; logger.debug("setReportingPeriodSelectOneMenuControl()" + reportingPeriodSelectOneMenuControl); } } ===================================================================================================================================== ReportingPeriod bean is also registered as a managed-property of the backing bean on the faces-config.xml if it makes any difference. Thanks again!!! Simeon -----Original Message----- From: Mike Kienenberger [mailto:mkienenb@gmail.com] Sent: Friday, April 20, 2007 10:26 AM To: MyFaces Discussion Subject: Re: Dynamic Value binding - please help! You need to assign ValueBinding objects, not strings. You'd typically do something like this [example borrowed and modified from another posting]: FacesContext context = FacesContext.getCurrentInstance(); Application app = context.getApplication(); reportingPeriodsSelectItemsControl.setValueBinding("itemLabel", app.createValueBinding("#{rptPeriod.reportingDateMonthly}")); On 4/20/07, Leyzerzon, Simeon wrote: > > > > Hi, > > I need to create the following construct dynamically in the backing bean: > > ====================================================================== > ======================== > value="#{searchHandler.reportingPeriod.rawDate}" > > binding="#{searchHandler.reportingPeriodSelectOneMenuControl}"> > > var="rptPeriod" > itemLabel="#{rptPeriod.reportingDateMonthly}" > itemValue="#{rptPeriod.rawDate}" > > binding="#{searchHandler.reportingPeriodsSelectItemsControl}" > /> > > > ====================================================================== > ======================== > > So I'm doing the following in my setter: > > ====================================================================== > ======================== public void > setReportingPeriodSelectOneMenuControl( > HtmlSelectOneMenu > reportingPeriodSelectOneMenuControl) { > > > if (reportingPeriods == null){ > logger.debug("reportingPeriods == null: " + > (reportingPeriods==null) + "building reportingPeriods > list..."); > reportingPeriods = > this.getSearchService().getReportingPeriods(); > } > > > //building > if (reportingPeriodsSelectItemsControl == null){ > reportingPeriodsSelectItemsControl = > (UISelectItems) FacesContext > > .getCurrentInstance().getApplication().createComponent( > UISelectItems.COMPONENT_TYPE); > > } > > > reportingPeriodsSelectItemsControl.setValue(reportingPeriods); > reportingPeriodsSelectItemsControl.setVar("rptPeriod"); > > String label = null; > > > > if (DAILY.equals(this.getPeriod())) { > label = "#{rptPeriod.reportingDateDaily}"; > }else if (MONTHLY.equals(this.getPeriod())) { > label = "#{rptPeriod.reportingDateMonthly}"; > } > > > reportingPeriodsSelectItemsControl.setItemLabel(label); > > reportingPeriodsSelectItemsControl.setItemValue("#{rptPeriod.rawDate}" > ); > > > > reportingPeriodSelectOneMenuControl.getChildren().add(reportingPeriods > SelectItemsControl); > > > > > > this.reportingPeriodSelectOneMenuControl = > reportingPeriodSelectOneMenuControl; > logger.debug("setReportingPeriodSelectOneMenuControl()" > + reportingPeriodSelectOneMenuControl); > } > > ====================================================================== > ========================== > > Unfortunately, what I am getting in the page is the combo populated > with a bunch of strings: #{rptPeriod.reportingDateMonthly} > > What am I missing here to link this variable 'rtpPeriod' to the value > binding expression. Or should there be a different syntax? > > Thanks for you help. > Simeon > > ====================================================================== > ======== Please access the attached hyperlink for an important > electronic communications disclaimer: > > http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html > ====================================================================== > ======== > > > > ============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html ==============================================================================