LuckyLuke
LuckyLuke

Reputation: 49087

How to make form input fields for a many objects?

I am making an administrating interface for an mobile application that I made. I have a question entity and a answer entity. Multiple answer objects (between 3-5) belongs to a single question object.

I am making a interface where I can register a new question with answers, how do I do that? In the backing bean I have a Question object and then I bind the properties to the input fields, but I don't know what to do with the Answers? And is it possible to make let say 4 input fields and have a button saying "Add answer" which makes a new input html tag?

(I am using Java EE 6 with all reference implementations).

Upvotes: 0

Views: 98

Answers (1)

BalusC
BalusC

Reputation: 1108842

The answers are specific to a question, right? Make the answers a property of the question.

public class Question {

    private List<Answer> answers;

    // ...
}

In your admin interface you could use an iterating component such as a <h:dataTable> to present multiple answers and add/remove them. See also How to dynamically add JSF components

Upvotes: 1

Related Questions