And what if I need to invoke the model-update?  Here is my problem, not sure if 
it's related or not to the lifecycle...

I have a javascript menu that is passing a parameter which is intercepted by a 
jsp page and being set in the session.  This parameter is a 'report category'.  
The control is then redirected to a jsf page, which has a bound HtmlPanelGrid 
component populated dynamically via backing bean(see below).  Each category has 
multiple number of reports, so per category, I dynamically create a combo-box 
(HtmlSelectOneMenu) and that should display different options every time the 
category is changed by the user.  Here's the code:

Selector.jsf

<f:view>
        <h:panelGrid footerClass="subtitle" headerClass="" styleClass=""
        columnClasses="" binding="#{selector.panelGrid}">


SelectorHandler.java

public void setPanelGrid(HtmlPanelGrid panelGrid) {
        this.panelGrid = panelGrid;
    }

    public HtmlPanelGrid getPanelGrid() {

        System.out.println(">>>>>>>Inside the getPanelGrid().....");
        panelGrid = new HtmlPanelGrid();
        panelGrid.setColumns(4);
        panelGrid.setBgcolor("red");

        HtmlSelectOneMenu chooser = new HtmlSelectOneMenu();
        chooser.setId("reportsOfCategory");
        chooser.setOnchange("submit()");
        /*
         * //chooser.setImmediate(true); //ValueBinding binding =
         * application.createValueBinding("${selector.reportName}");
         * //chooser.setValueBinding("value", binding);
         */
        chooser.setValue("${selector.reportName}");
        chooser.setValueChangeListener(application.createMethodBinding(
                "#{selector.buildControls}",
                new Class[] { ValueChangeEvent.class }));
        chooser.setTitle("Please select a report to run");
        ValueBinding chooserBinding = 
application.createValueBinding("#{selector.chooserBinding}");
        chooser.setValueBinding("value",chooserBinding);
        chooser.getChildren().add(
                ReportsPerCategoryMapper.getOptionItems(this.getCategory()
                        .getName()));

        panelGrid.getChildren().add(chooser);
        // this is only for testing
        panelGrid.getChildren().add(displayCategory());
        return panelGrid;
    }

    public void buildControls(ValueChangeEvent event) {
        System.out.println("I got the report's name: " + event.getNewValue());
        reportName = (String) event.getNewValue();
        System.out.println("reportName property: " + this.getReportName());
        if (reportName.equals("LIQ Revenue Summary by Revenue Type")) {

            HtmlOutputText outText = new HtmlOutputText();
            ValueBinding binding = application
                    .createValueBinding("test is #{selector.category.name}");
            outText.setValueBinding("value", binding);
            outText.setRendererType("javax.faces.Text");
            panelGrid.getChildren().add(outText);

            /*application.createComponent(arg0)
            UIOutput verbatim = (UIOutput) application
                    .createComponent("javax.faces.Output");
            // verbatim.setId("vrbtm");
            verbatim.getAttributes().put("escape", Boolean.FALSE);
            verbatim
              .setValue("<f:subview id=\" + 
FacesContext.getCurrentInstance().getViewRoot().createUniqueId()+ 
\"><jsp:include page=\"test.jsp\"></f:subview>");
            panelGrid.getChildren().add(verbatim);*/
            
            
        }


On value change in the combo box, the contents of the grid should be updated 
with dynamically created controls (in the buildControls() listener method).  

The problem is that when the user chooses a different category via the drop 
down javascript menu, the select items in the combo-box don't seem to get 
updated with the new values corresponding to a different report category.  It 
looks like the flow of the code bypasses the getPanelGrid() method on all the 
subsequent change of the category except for the first one.  I guess, I'm 
missing something in the JSF lifecycle.  Could someone please give me a hand 
and explain how to fix this behavior.

Thanks a lot!
Simeon


-----Original Message-----
From: Martin Marinschek [mailto:[EMAIL PROTECTED] 
Sent: Monday, September 11, 2006 12:35 PM
To: MyFaces Discussion
Subject: Re: HtmlSelectOneMenu valueChange behavior

Hi Simeon,

remember the JSF-Lifecycle, and that model-beans are only updated after the 
conversion and validation phase has completely run?

The value-change-listeners are called ahead of the model-update-phase, and this 
is why you don't see the changed value in the backing beans.

regards,

Martin

On 9/11/06, Leyzerzon, Simeon <[EMAIL PROTECTED]> wrote:
>
>
> Sorry, I meant to say that calling this.getReportName() in the 
> buidControl() listener returns null whereas event.getNewValue() works.
> Simeon
>
>  ________________________________
>  From: Leyzerzon, Simeon
> [mailto:[EMAIL PROTECTED]
> Sent: Monday, September 11, 2006 12:21 PM
> To: '[email protected]'
> Subject: HtmlSelectOneMenu valueChange behavior
>
>
>
>
> Hi,
> I have the following code in my application, and it works, but I'm 
> wondering if this is the right way to do it:
>
> public HtmlPanelGrid getPanelGrid() {
>
>         grid = new HtmlPanelGrid();
>         grid.setColumns(4);
>         grid.setBgcolor("red");
>
>         HtmlSelectOneMenu chooser = new HtmlSelectOneMenu();
>         chooser.setId("reportsOfCategory");
>         chooser.setOnchange("submit()");
>         chooser.setValue("${selector.reportName}");
>         chooser.setValueChangeListener(application.createMethodBinding(
>                 "#{selector.buildControls}",
>                 new Class[] { ValueChangeEvent.class}));
>         chooser.setTitle("Please select a report to run");
>
> chooser.getChildren().add(ReportsPerCategoryMapper.getOptionItems(this
> .getCategory().getName()));
>
>         grid.getChildren().add(chooser);
>         //this is only for testing
>         grid.getChildren().add(displayCategory());
>         return grid;
>     }
>
>     public void buildControls(ValueChangeEvent event) {
>         System.out.println("I got the report's name: " + 
> event.getNewValue());
>     }
>
>
> Calling chooser.getValue() in the listener method returns null, 
> whereas
> event.getNewValue() works.  Could someone please explan this behavior.  
> What is the purpose of chooser.setValue() if getting the value doesn't work?
> Would it be correct to do:
>
>                 reportName = event.getNewValue();
>
> or is there a better way?
>
> TIA.
>
> Simeon Leyzerzon
> Risk IT
> <<...OLE_Obj...>>
>
> Tel: 212-538-7518
> Profile <http://people.csfb.net/from_gtd.asp?gtdid=1160763>
>
>
> ======================================================================
> ======== 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
> ======================================================================
> ========
>
>
>
>
>
>


-- 

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

==============================================================================
Please access the attached hyperlink for an important electronic communications 
disclaimer: 

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================

Reply via email to