myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leyzerzon, Simeon" <simeon.leyzer...@credit-suisse.com>
Subject RE: Dynamic Value binding - please help!
Date Fri, 20 Apr 2007 15:33:14 GMT
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 <t:selectItems> 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 <t:selectItems>
    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 <simeon.leyzerzon@credit-suisse.com> wrote:
>
>
>
> Hi,
>
> I need to create the following construct dynamically in the backing bean:
>
> ======================================================================
> ======================== <h:outputText value="Reporting Period"  />
>      <h:selectOneMenu
> value="#{searchHandler.reportingPeriod.rawDate}"
>
> binding="#{searchHandler.reportingPeriodSelectOneMenuControl}">
>
>          <t:selectItems value="#{searchHandler.reportingPeriods}"
> var="rptPeriod"
>                 itemLabel="#{rptPeriod.reportingDateMonthly}"
> itemValue="#{rptPeriod.rawDate}"
>
> binding="#{searchHandler.reportingPeriodsSelectItemsControl}"
>          />
>      </h:selectOneMenu>
>
> ======================================================================
> ========================
>
> 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 <t:selectItems>
>     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
==============================================================================


Mime
View raw message