0

I'm writing a JSF2.0-component as a Java class and Renderer class and so on. I can't write parts of the output in the xhtml like

<h:outputText ... />

because the elements are generated dynamically.

  1. So I get the message "The button/link/text component needs to have a Form in its ancestry. Please add .". Below you can see how I currently render a form. Is this correct too? Or should change something to make the warning dissappear?

    private void encodeForm(Element elem) throws IOException {
        //ResponsWriter writer
        writer.startElement("form", form);
        encodeChildren(elem);
        writer.endElement("form");
    }
    
  2. Is it possible to connect an input-field to a variable that is created during runtime (i.e. an Object in a List)? If yes how? If no: I have to implement the decode()-method right?
  3. How should I render a button that submits such a form? It should for example call a method in my component that then somehow (how? like the decode-method?) can process the user-input.

Thanks for any help!

sotix
  • 822
  • 1
  • 8
  • 23

1 Answers1

2

Is this correct too? Or should change something to make the warning dissappear?

Your best bet would be to just remove the code you've shown and ask the users of said component to place it inside a form.

At any length, what you're doing is writing markup for a form. This is something else than actually putting a form component in the tree.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
  • Thanks for your answer but I have to create it like this. So is there a way? – sotix May 26 '12 at 20:15
  • If you absolutely feel you need to do this, you can resort to `dynamic component tree manipulation`. For how to do this from a component, see http://blog.kennardconsulting.com/2010/10/safely-manipulating-component-tree-with.html and for actually inserting a form component see: http://jdevelopment.nl/single-class-pure-java-jsf-application – Arjan Tijms May 26 '12 at 20:34