myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Delbecq <de...@oma.be>
Subject Re: Needs help for creating a new JSF component
Date Tue, 22 May 2007 11:54:00 GMT
There are tutorial on how to create components and renderes.
Now while your goal is easy, it's realization isn't, creating composite
components is not straightfoward in JSF.
I see 4 ways to do so

1) don't use child components, just render several form fields in the
renderer and decode them yourself
2) During your component initialisation create child components
(getChildren().add(....)). The tricky part is to not redo it when it's a
restore view (because JSF recreated child components for you). The
easiest way is to do it lazily and store in your main component state a
'childCreated' property
3) Use facelets, which can easily be used to create composite components
4) Create the whole composite component tree in a bean and use binding.

Storing your component clientId inside a bean should not be necessary.
You always have your component as parameter when you need it in JSF
(render, restore, apply values, ...).

En l'instant précis du 22/05/07 13:34,
Stephane.CLINCKART@ext.ec.europa.eu s'exprimait en ces termes:
>
> Hi,
>
> I have to develop a new JSF component (component, tag and renderer).
>
> The goal of this new component is easy... Put together severals input
> zone in one single component.
>
> I have done somethink that works... But i'm not sure I did everything
> correctly. (in the State of Art)
> --> Should be great if I can get a link to a complete tutorial or full
> sample.
>
> I create some code I don't like:
> --> I have to "hardcoded" in the backingbean the "id" of my component
> and then cast it to my component.
> In my backingbean, the code looks like this:
> UIComponent temp =
> FacesContext.getCurrentInstance().getViewRoot().findComponent("dialog:dialog-body:mltext");
> UIMltext myComponent = (UIMltext) temp;
>
> During reading documentation I have found it is possible to "add"
> component in the JSF tree dynamicly with code like this:
> public void addControls(ActionEvent actionEvent)
> {
> Application application =
> FacesContext.getCurrentInstance().getApplication();
> //Question: how to get controlPanel ???
> List children = controlPanel.getChildren();
> children.clear();
> for (int count = 0; count < numControls; count++)
> {
> HtmlOutputText output =
> (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
> output.setValue(" " + count + " ");
> output.setStyle("color: blue");
> children.add(output);
> }
> }
> Is it necessary in my component. What is the goal of adding component
> in the tree?
>
> I can now do: "MyValue myValues = myComponent.getValue()"
>
> Then I have to do somethink like:
>
> backingBean.setValue1(myValues.getValue1());
> backingBean.setValue2(myValues.getValue2());
> ...
> backingBean.setValuex(myValues.getValuex());
>
> Is it correct? I should prefer the setter are called by JSF layer. Is
> it possible?
> Thanks a lot.
> Stéphane
>


Mime
View raw message