You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Don Tam <dt...@consumercontact.com> on 2005/11/16 16:06:30 UTC

Strange problem setting values to bound field with dynamically generated components

Hi,

I am generating a custom panelTabbedPane and panel tabs from the setter 
of my bean.  I am including the code below.  Everything looks fine when 
the page first shows up, and the values are all correctly checked (in 
the case of SelectOneBooleanCheckbox) or set (in the case of 
SelectMany). The html options for the selects are rendered correctly 
with the value/label pairs.

The problem happens when I submit.  It is as if all the inputs are 
cleared of values and then set to the bound bean field.  For example, 
all checkbox value holders are set to false, and the ids in the case of 
selectMany are set to null.  Here are the code snippets:

Bean:
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        HtmlPanelTab hpt = (HtmlPanelTab) 
app.createComponent(HtmlPanelTab.COMPONENT_TYPE);
        hpt.setLabel(label);       
       
        List<UIComponent> tabChildren = hpt.getChildren();
       
        HtmlDataTable hdt = (HtmlDataTable) 
app.createComponent(HtmlDataTable.COMPONENT_TYPE);
        hdt.setId("table_" + label);
        tabChildren.add(hdt);
       
        hdt.setStyleClass("table-background");
        hdt.setHeaderClass("table-header");
        hdt.setRowClasses("row-odd,row-even");
        hdt.setVar("item");
        hdt.setValue(values);
        HtmlSimpleColumn hsc = null;
       
           
        hsc = ComponentUtils.createDataTableColumn(hdt, "participates");
        ComponentUtils.createUIComponent(context, 
HtmlSelectBooleanCheckbox.COMPONENT_TYPE, "#{item.participates}", hsc);
              
        hsc = ComponentUtils.createDataTableColumn(hdt, "comment");
        HtmlSelectOneMenu hsom = (HtmlSelectOneMenu) ComponentUtils
                .createUIComponent(context, 
HtmlSelectOneMenu.COMPONENT_TYPE, "#{item.comment.id}", hsc);
        ComponentUtils.createUIComponent(context, 
UISelectItems.COMPONENT_TYPE, "#{Bean.comments.selectList}", hsom);

jsf:
<h:form styleClass="crudForm">
          <h:commandButton styleClass="crudButton"
             value="#{bundle.save_changes}"
             action="#{Bean.saveChanges}"/>

<t:panelTabbedPane activeTabStyleClass="active_tab" 
inactiveTabStyleClass="inactive_tab"
    binding="#{Bean.tabs}">
</t:panelTabbedPane>
</h:form>

Here is a piece of my log before and after the submit for the same record:
{Id: 1 Num: 222222 Name: Test Guy,true} {1:None}
                 this is participates-------------^        ^---- this is 
comment.id
after submit (even though participates is still checked):
{Id: 1 Num: 222222 Name: Test Guy,false} {null:None}

Does anyone have any clue?

Thanks,

-- 
Don Tam
Manager, Software Development
(416)493-6111x143
dtam@consumercontact.com


Re: Strange problem setting values to bound field with dynamically generated components

Posted by Mike Kienenberger <mk...@gmail.com>.
Don,  I don't know, but it seems more likely that it has something to
do with state management than anything else.   Maybe try setting some
breakpoints in the constructor, the StateHolder methods, and in the
setter?

On 11/18/05, Don Tam <dt...@consumercontact.com> wrote:
> Hi,
>
> I was wondering if anyone had any ideas on this.  I read briefly that
> someone mentioned something about a double submit problem?  Could this
> be it?  What is the double submit problem?
>
> Thanks,
>
> Don Tam wrote:
>
> > Hi,
> >
> > I am generating a custom panelTabbedPane and panel tabs from the
> > setter of my bean.  I am including the code below.  Everything looks
> > fine when the page first shows up, and the values are all correctly
> > checked (in the case of SelectOneBooleanCheckbox) or set (in the case
> > of SelectMany). The html options for the selects are rendered
> > correctly with the value/label pairs.
> >
> > The problem happens when I submit.  It is as if all the inputs are
> > cleared of values and then set to the bound bean field.  For example,
> > all checkbox value holders are set to false, and the ids in the case
> > of selectMany are set to null.  Here are the code snippets:
> >
> > Bean:
> >        FacesContext context = FacesContext.getCurrentInstance();
> >        Application app = context.getApplication();
> >        HtmlPanelTab hpt = (HtmlPanelTab)
> > app.createComponent(HtmlPanelTab.COMPONENT_TYPE);
> >        hpt.setLabel(label);                    List<UIComponent>
> > tabChildren = hpt.getChildren();
> >              HtmlDataTable hdt = (HtmlDataTable)
> > app.createComponent(HtmlDataTable.COMPONENT_TYPE);
> >        hdt.setId("table_" + label);
> >        tabChildren.add(hdt);
> >              hdt.setStyleClass("table-background");
> >        hdt.setHeaderClass("table-header");
> >        hdt.setRowClasses("row-odd,row-even");
> >        hdt.setVar("item");
> >        hdt.setValue(values);
> >        HtmlSimpleColumn hsc = null;
> >                        hsc = ComponentUtils.createDataTableColumn(hdt,
> > "participates");
> >        ComponentUtils.createUIComponent(context,
> > HtmlSelectBooleanCheckbox.COMPONENT_TYPE, "#{item.participates}", hsc);
> >                     hsc = ComponentUtils.createDataTableColumn(hdt,
> > "comment");
> >        HtmlSelectOneMenu hsom = (HtmlSelectOneMenu) ComponentUtils
> >                .createUIComponent(context,
> > HtmlSelectOneMenu.COMPONENT_TYPE, "#{item.comment.id}", hsc);
> >        ComponentUtils.createUIComponent(context,
> > UISelectItems.COMPONENT_TYPE, "#{Bean.comments.selectList}", hsom);
> >
> > jsf:
> > <h:form styleClass="crudForm">
> >          <h:commandButton styleClass="crudButton"
> >             value="#{bundle.save_changes}"
> >             action="#{Bean.saveChanges}"/>
> >
> > <t:panelTabbedPane activeTabStyleClass="active_tab"
> > inactiveTabStyleClass="inactive_tab"
> >    binding="#{Bean.tabs}">
> > </t:panelTabbedPane>
> > </h:form>
> >
> > Here is a piece of my log before and after the submit for the same
> > record:
> > {Id: 1 Num: 222222 Name: Test Guy,true} {1:None}
> >                 this is participates-------------^        ^---- this
> > is comment.id
> > after submit (even though participates is still checked):
> > {Id: 1 Num: 222222 Name: Test Guy,false} {null:None}
> >
> > Does anyone have any clue?
> >
> > Thanks,
> >
>
> --
> Don Tam
> Manager, Software Development
> (416)493-6111x143
> dtam@consumercontact.com
>
>

Re: Strange problem setting values to bound field with dynamically generated components

Posted by Don Tam <dt...@consumercontact.com>.
Hi,

I was wondering if anyone had any ideas on this.  I read briefly that 
someone mentioned something about a double submit problem?  Could this 
be it?  What is the double submit problem?

Thanks,

Don Tam wrote:

> Hi,
>
> I am generating a custom panelTabbedPane and panel tabs from the 
> setter of my bean.  I am including the code below.  Everything looks 
> fine when the page first shows up, and the values are all correctly 
> checked (in the case of SelectOneBooleanCheckbox) or set (in the case 
> of SelectMany). The html options for the selects are rendered 
> correctly with the value/label pairs.
>
> The problem happens when I submit.  It is as if all the inputs are 
> cleared of values and then set to the bound bean field.  For example, 
> all checkbox value holders are set to false, and the ids in the case 
> of selectMany are set to null.  Here are the code snippets:
>
> Bean:
>        FacesContext context = FacesContext.getCurrentInstance();
>        Application app = context.getApplication();
>        HtmlPanelTab hpt = (HtmlPanelTab) 
> app.createComponent(HtmlPanelTab.COMPONENT_TYPE);
>        hpt.setLabel(label);                    List<UIComponent> 
> tabChildren = hpt.getChildren();
>              HtmlDataTable hdt = (HtmlDataTable) 
> app.createComponent(HtmlDataTable.COMPONENT_TYPE);
>        hdt.setId("table_" + label);
>        tabChildren.add(hdt);
>              hdt.setStyleClass("table-background");
>        hdt.setHeaderClass("table-header");
>        hdt.setRowClasses("row-odd,row-even");
>        hdt.setVar("item");
>        hdt.setValue(values);
>        HtmlSimpleColumn hsc = null;
>                        hsc = ComponentUtils.createDataTableColumn(hdt, 
> "participates");
>        ComponentUtils.createUIComponent(context, 
> HtmlSelectBooleanCheckbox.COMPONENT_TYPE, "#{item.participates}", hsc);
>                     hsc = ComponentUtils.createDataTableColumn(hdt, 
> "comment");
>        HtmlSelectOneMenu hsom = (HtmlSelectOneMenu) ComponentUtils
>                .createUIComponent(context, 
> HtmlSelectOneMenu.COMPONENT_TYPE, "#{item.comment.id}", hsc);
>        ComponentUtils.createUIComponent(context, 
> UISelectItems.COMPONENT_TYPE, "#{Bean.comments.selectList}", hsom);
>
> jsf:
> <h:form styleClass="crudForm">
>          <h:commandButton styleClass="crudButton"
>             value="#{bundle.save_changes}"
>             action="#{Bean.saveChanges}"/>
>
> <t:panelTabbedPane activeTabStyleClass="active_tab" 
> inactiveTabStyleClass="inactive_tab"
>    binding="#{Bean.tabs}">
> </t:panelTabbedPane>
> </h:form>
>
> Here is a piece of my log before and after the submit for the same 
> record:
> {Id: 1 Num: 222222 Name: Test Guy,true} {1:None}
>                 this is participates-------------^        ^---- this 
> is comment.id
> after submit (even though participates is still checked):
> {Id: 1 Num: 222222 Name: Test Guy,false} {null:None}
>
> Does anyone have any clue?
>
> Thanks,
>

-- 
Don Tam
Manager, Software Development
(416)493-6111x143
dtam@consumercontact.com