sotix
sotix

Reputation: 822

JSF2.0: How to write h:form in MyComponent in Java?

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!

Upvotes: 0

Views: 199

Answers (1)

Arjan Tijms
Arjan Tijms

Reputation: 38163

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.

Upvotes: 2

Related Questions