Hi.

  Thank you very much Volker, your answer is very interesting.
My problem is very similar to the one you solved with your example. Going under, I also need to generate components within my own jsf component, and not only from a binding variable. So, as an example, think about a structure in memory that should be rendered in a page, and that the rendered component should, with a determined behavior, interact with the user: for example the component could render links or command buttons that have an action bounded to them.

So what's the problem? Create a ValueBinding/MethodBinding and assign this to the corresponding property of the component.
I do a lot of stuff like

    component.setValueBinding("rendered", new BooleanValueBinding() {
      public boolean get() {
        return getEditor().isVisible();
      }
    });

or

button.setAction(new StringMethodBinding() {
            protected String execute() {
              return executeSearch();
            }
          });

You may also construct value/method binding with Application.

Actually I'm doing exactly what you've done in your example, but during rendering phase of my component. All is working OK if I use myfaces, but if I switch to Sun RI that, for default, caches 15 views, I get a duplicate component id every time a page is reloaded for some reason.

You should explicitly assign ids to new components:

  public static void assignId(String prefix, UIComponent component) {
final UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
    if (viewRoot != null) {
      final String id = viewRoot.createUniqueId();
      component.setId(prefix + id);
    }
  }

  public static void assignId(UIComponent component) {
    assignId("h", component);
  }

> I
can workaround the problem disabling the caching of views, but my question is more philosophical than practical: is it right to create components during the rendering phase of my component or the component should not depends from other widgets and should only render its own portion of html (including, for example, all form related components)? My question so is more a check on what I'm doing with my component...Am I wrong with this approach? Is my (and of course your) solution "JSF oriented" (note...is quoted :) or is it only a tricky way to resolve this kind of problem?
Maybe it's a silly problem...

I don't quite get your difficulties. What I do a lot is instantiate and combine components in session-scoped beans and use binding="#{myBean.myComponent}" in JSF/Facelet pages. This works fine.

Bye.
/lexi

Reply via email to