Dynamic backing bean

Hello

Someone can help me with the following issue?

Im working on an application that creates jsf pages based on user input. Its a tool where one user should build a questionnaire and another user has to ansewer it.

The component creation based on user(quetionnaire builder) input is working has well, but i dont have any idea how to store the inputs from the user that has to ansewer the questionnaire.

I need a way to dynamic generate a backing bean and create a valueBind with all UIInput Components, forcing the bean to store the ansewers in a collection.

Someone know how may i do this?

Maybe a hashMap in a backingBean solve my problem, but i dont know how to bind all components with the map... how to make my jsfComponents add their own key and value in a map?

Thanks, and sorry for my poor english.

Ferryman

[873 byte] By [Ferrymana] at [2007-11-26 13:01:41]
# 1

Ferryman,

Perhaps you could make a simple bean that contains properties "name" and "value". Then create one of these to represent each question on the form. Since you are generating everything dynamically you could assign the beans a unqiue binding name for JSF and programmatically bind them. There may be a few details to overcome but I think this approach could work.

Ray

RaymondDeCampoa at 2007-7-7 17:03:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks Raymond, I think this will work.I'll try to do this, and when i finish, i'll give you a feedback.bye n thanks,Ferryman
Ferrymana at 2007-7-7 17:03:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Using a map to hold generated inputs is something I've used before and it works. I had a set of different classes that all knew how to create the JSF to add themselves to the form. When they added themselves, they bound the value to the map attribute using the name as specified on the constructor. The objects also know how to get the value out of the map. So during construction of the input form you loop through all these objects and tell them to add themselves to the input form, and then to get the values back you loop through the objects and ask them what the value is.

Here's another suggestion: how about using an h:dataTable to display a List of "QuestionBean"s.

Here's a sketch of what the code would look like:

public class QuestionBean {

private String prompt;

private String input = "";

public void setPrompt( String p ) {

}

// getPrompt, setInput, getInput...

}

public class QuestionsBean {

String current_question_input;

List questionList;

public void getQuestionList() {

return question_list;

}

public void setCurrentQuestionInput( String qi ) {

current_question_input = qi;

}

public void addQuestion( ActionEvent e ) {

QuestionBean qb = new Questionbean():

qb.setPrompt( current_question_prompt );

questionList.add( qb );

}

}

<h:dataTable value="#{questions.questionList}" var="var_question">

<h:column>

<h:outputText value="#{var_question.prompt}" />

</h:column>

<h:column>

<h:inputText value="#{var_question.input}" />

</h:column>

</h:dataTable>

BrantKnudsona at 2007-7-7 17:03:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...