I send you some sourcecode of mine which heavily uses component
binding - a complete grid is initialized in the source-code. Code
quality is not at its best though, so take it with care.

regards,

Martin

public getEncashmentGrid()
{
            HtmlPanelGrid grid = new HtmlPanelGrid();

            HtmlOutputLabel textLabel = new HtmlOutputLabel();
            textLabel.setId("claimTypeLabel");

            textLabel.setValue(GuiUtil.getResourceLabelIfAvailable(
                            getGuiContext().getLocale(),
"IN.claimTypeLabel",null,""));

            textLabel.setValueBinding("styleClass",
                   
getValueBinding("#{encashmentDetail.editMode?'label':'textLabel'}"));
            
textLabel.setRendered(!getGuiContext().getSessionData().isEncashmentMode());

            textLabel.setFor("claimType");

            grid.getChildren().add(textLabel);

            ValueBinding valueBinding;

            ValueBinding editAndNotEncashmentsModeValueBinding =
                    getValueBinding("#{encashmentDetail.editMode &&
!sessionData.encashmentMode}");
            ValueBinding notEditAndNotEncashmentsModeValueBinding =
getValueBinding(
                    "#{!encashmentDetail.editMode &&
!sessionData.encashmentMode}");

            HtmlPanelGroup group = new HtmlPanelGroup();
            group.setId("claimTypeGroup");
            
group.setRendered(!getGuiContext().getSessionData().isEncashmentMode());
            grid.getChildren().add(group);

            valueBinding =
getValueBinding("#{encashmentDetail.encashment.claimType}");

            HtmlSelectOneMenu claimTypeSelectOneMenu = new HtmlSelectOneMenu();
            claimTypeSelectOneMenu.setId("claimType");
            claimTypeSelectOneMenu.setValueBinding("value", valueBinding);
            claimTypeSelectOneMenu.setValueBinding("rendered",
editAndNotEncashmentsModeValueBinding);
            claimTypeSelectOneMenu.setStyleClass("selectOneMenu");
            claimTypeSelectOneMenu.setRequired(true);
            
claimTypeSelectOneMenu.setValueBinding("disabled",getValueBinding("#{encashmentDetail.encashmentExisting==true}"));

            UISelectItems items = new UISelectItems();
            items.setId("claimTypeSelectItems");
            
items.setValueBinding("value",getValueBinding("#{encashmentDetail.claimTypes}"));

            claimTypeSelectOneMenu.getChildren().add(items);

            group.getChildren().add(claimTypeSelectOneMenu);

            HtmlOutputText text = new HtmlOutputText();
            text.setId("claimType");
            text.setValueBinding("value",
getValueBinding("#{applicationData.claimTypeMap[encashmentDetail.encashment.claimType]}"));
            text.setValueBinding("rendered",
notEditAndNotEncashmentsModeValueBinding);
            text.setStyleClass("text");

            group.getChildren().add(text);

            Fields fields =
getClaimTypesToFields().getFields(getEncashment().getClaimType());

            if(fields == null)
            {
                log.error("No fields defined for claimType :
"+getEncashment().getClaimType());
                throw new IllegalStateException("No fields defined for
claimType : "+getEncashment().getClaimType());
            }

            Iterator it = fields.getFields();

            while (it.hasNext())
            {
                Field field = (Field) it.next();

                JsValueChangeListener listener = new JsValueChangeListener();
                listener.setId("valueChangeListenerFor"+field.getKey());
                listener.setFor(field.getKey()+"Label");
               
listener.setExpressionValue("$destElem.innerHTML=claimTypesToFields[$srcElem.options[$srcElem.selectedIndex].value]['"+field.getKey()
                       
+"']['label']+(claimTypesToFields[$srcElem.options[$srcElem.selectedIndex].value]['"+field.getKey()+"']['required']==true?'<span
class=\"requiredLabel\">*</span>':'')");

                claimTypeSelectOneMenu.getChildren().add(listener);

                JsValueChangeListener displayedLabelListener = new
JsValueChangeListener();
               
displayedLabelListener.setId("displayedValueChangeListenerFor"+field.getKey()+"Label");
                displayedLabelListener.setFor(field.getKey()+"Label");
               
displayedLabelListener.setExpressionValue("claimTypesToFields[$srcElem.options[$srcElem.selectedIndex].value]['"+field.getKey()
                       
+"']['displayed']==true?$destElem.style.display='inline':$destElem.style.display='none';");

               
claimTypeSelectOneMenu.getChildren().add(displayedLabelListener);

                JsValueChangeListener displayedListener = new
JsValueChangeListener();
               
displayedListener.setId("displayedValueChangeListenerFor"+field.getKey());
                displayedListener.setFor(field.getKey());
               
displayedListener.setExpressionValue("claimTypesToFields[$srcElem.options[$srcElem.selectedIndex].value]['"+field.getKey()
                       
+"']['displayed']==true?$destElem.style.display='inline':$destElem.style.display='none';");

                claimTypeSelectOneMenu.getChildren().add(displayedListener);

                textLabel = new HtmlOutputLabel();
                textLabel.setId(field.getKey()+"Label");
                textLabel.setFor(field.getKey());
                if(!field.isDisplayed())
                {
                    textLabel.setStyle("display:none;");
                }

                //valueBinding = new ValueBindingImpl(
                //       
FacesContext.getCurrentInstance().getApplication(),"#{label."+field.getKey()+"Label}");

                textLabel.setValue(field.getLabel());
                textLabel.setValueBinding("styleClass",
                       
(getValueBinding("#{encashmentDetail.editMode?'label':'textLabel'}")));

                grid.getChildren().add(textLabel);

                valueBinding = new ValueBindingImpl(
                       
FacesContext.getCurrentInstance().getApplication(),"#{encashmentDetail.encashment."+field.getKey()+"}");

                ValueBinding editModeValueBinding = new ValueBindingImpl(
                        FacesContext.getCurrentInstance().getApplication(),
                        "#{encashmentDetail.editMode}");
                ValueBinding notEditModeValueBinding = new ValueBindingImpl(
                        FacesContext.getCurrentInstance().getApplication(),
                        "#{!encashmentDetail.editMode}");
                ValueBinding editNewModeValueBinding = new ValueBindingImpl(
                        FacesContext.getCurrentInstance().getApplication(),
                        "#{encashmentDetail.editMode &&
encashmentDetail.vloClaimNr <= 0}");
                ValueBinding notEditNewModeValueBinding = new ValueBindingImpl(
                        FacesContext.getCurrentInstance().getApplication(),
                        "#{!encashmentDetail.editMode ||
(encashmentDetail.editMode && encashmentDetail.vloClaimNr >0)}");


                group = new HtmlPanelGroup();
                group.setId(field.getKey()+"group");

                grid.getChildren().add(group);

                HtmlInputText inputText = new HtmlInputText();

                if(field.getKey().equals("currency"))
                {
                    HtmlSelectOneMenu selectOneMenu = new HtmlSelectOneMenu();
                    selectOneMenu.setId("currency");
                    selectOneMenu.setValueBinding("value", valueBinding);
                    selectOneMenu.setValueBinding("rendered",
field.isOnlyInNewEditable()?editNewModeValueBinding:editModeValueBinding);
                    selectOneMenu.setStyleClass("selectOneMenu");
                    selectOneMenu.setRequired(true);
                   
selectOneMenu.setValueBinding("disabled",getValueBinding("#{encashmentDetail.encashmentExisting==true}"));

                    items = new UISelectItems();
                    items.setId("currencyItems");
                   
items.setValueBinding("value",getValueBinding("#{encashmentDetail.currencies}"));

                    selectOneMenu.getChildren().add(items);

                    group.getChildren().add(selectOneMenu);

                }
                else if(field.getKey().equals("claimContested"))
                {
                    HtmlSelectOneMenu selectOneMenu = new HtmlSelectOneMenu();
                    selectOneMenu.setId("claimContested");
                    selectOneMenu.setValueBinding("value", valueBinding);
                    selectOneMenu.setValueBinding("rendered",
field.isOnlyInNewEditable()?editNewModeValueBinding:editModeValueBinding);
                    selectOneMenu.setStyleClass("selectOneMenu");
                    selectOneMenu.setRequired(true);
                   
selectOneMenu.setValueBinding("disabled",getValueBinding("#{encashmentDetail.encashmentExisting==true}"));

                    selectOneMenu.setValueBinding("converter", getValueBinding(
                            "#{converterBean.booleanConvt}"));

                    items = new UISelectItems();
                    items.setId("claimContestedItems");
                   
items.setValueBinding("value",getValueBinding("#{encashmentDetail.yesNoList}"));

                    selectOneMenu.getChildren().add(items);

                    group.getChildren().add(selectOneMenu);
                }
                else
                {
                    inputText.setId(field.getKey());
                    inputText.setValueBinding("value", valueBinding);
                    if(!field.isEditable())
                    {
                        inputText.setRendered(false);
                    }
                    else
                    {
                        inputText.setValueBinding("rendered",
field.isOnlyInNewEditable()?editNewModeValueBinding:editModeValueBinding);
                    }
                    inputText.setStyleClass("text");
                    inputText.setRequired(field.isRequired());


                    if(!field.isDisplayed())
                    {
                        inputText.setStyle("display:none;");
                    }

                    if(field.isUsesAmountConverter())
                    {
                        inputText.setValueBinding("converter", new
ValueBindingImpl(FacesContext.getCurrentInstance().getApplication(),
                                "#{converterBean.amountConvt}"));
                    }

                    if(field.isRequiresLengthValidator())
                    {
                        LengthValidator validator = new
LengthValidator((int)field.getUpperBoundLength());
                        inputText.addValidator(validator);
                    }

                    if(field.isRequiresDoubleRangeValidator())
                    {
                        DoubleRangeValidator validator = new
DoubleRangeValidator(field.getUpperBoundDoubleRange(),
                                field.getLowerBoundDoubleRange());
                        inputText.addValidator(validator);
                    }

                    if(field.isRequiresLongRangeValidator())
                    {
                        DoubleRangeValidator validator = new
DoubleRangeValidator(field.getUpperBoundLongRange(),
                                field.getLowerBoundLongRange());
                        inputText.addValidator(validator);
                    }

                    group.getChildren().add(inputText);
                }

                text = new HtmlOutputText();
                text.setId(field.getKey());
                text.setValueBinding("value", valueBinding);
                if(field.isEditable())
                {
                    text.setValueBinding("rendered",
field.isOnlyInNewEditable()?notEditNewModeValueBinding:notEditModeValueBinding);
                }
                else
                {
                    text.setRendered(true);
                }
                text.setStyleClass("text");

                if(!field.isDisplayed())
                {
                    text.setStyle("display:none;");
                    inputText.setStyle("display:none;");
                }

                if(field.isUsesAmountConverter())
                {
                    text.setValueBinding("converter", getValueBinding(
                            "#{converterBean.amountConvt}"));
                    inputText.setValueBinding("converter", getValueBinding(
                            "#{converterBean.amountConvt}"));
                }

                if(field.isUsesBooleanConverter())
                {
                    text.setValueBinding("converter", getValueBinding(
                            "#{converterBean.booleanOutputConvt}"));
                }

                if(field.isUsesDateTimeConverter())
                {
                    text.setValueBinding("converter", getValueBinding(
                            "#{converterBean.dateTimeConvt}"));
                    inputText.setValueBinding("converter", getValueBinding(
                            "#{converterBean.dateTimeConvt}"));
                }

                if(field.isRendersWithBreaks())
                {
                    text.setValueBinding("binding", getValueBinding(
                            "#{componentBean.outputWithBreaks}"));
                }

                group.getChildren().add(text);
            }

            return grid;
    }

    private ValueBinding getValueBinding(String expression)
    {
        return new ValueBindingImpl(
                FacesContext.getCurrentInstance().getApplication(),
                expression);
    }

On 5/18/05, Pierrick Samary <[EMAIL PROTECTED]> wrote:
> Thanks Martin for your answer.
> 
> Where can i find good examples of manipulation of component in the back-end 
> please ?
> 
> Regards,
> 
> Pierrick.
> 
> -----Message d'origine-----
> De : Martin Marinschek [mailto:[EMAIL PROTECTED]
> Envoy� : mardi 17 mai 2005 18:30
> � : MyFaces Discussion
> Objet : Re: EL Limitations
> 
> Usually, if you start to need that much dynamisation, you are better off 
> using the component binding features of JSF and dynamise the component tree 
> in Java.
> 
> works like this: binding="#{backingBean.xyComponent}" - and you can do 
> whatever you want to initialize your component in the back-end.
> 
> regards,
> 
> Martin
> 
> On 5/17/05, Pierrick Samary <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> > Hello,
> >
> > I have several questions about dynamic programmation with JSF. I open
> > a thread for each one.
> >
> > Is it possible with JSF to use local variables from my page xxx.jsp in
> > an EL expression ? If the answer is "no", is it possible to have the
> > same functionnality by an other way ?
> >
> > Thanks,
> >
> > Pierrick
> 
>

Reply via email to