Dynamic forms in jsf

Hi all,
This question has probably been asked a thousand times, but I can't find the answer.
I am an experienced Struts developer, but now I want to create an application using jsf.
It will be some kind of quiz with multiple choice questions. The problem is that the number of questions is not fixed, so for 1 quiz there can be 10 questions and for another one 20.
In struts I know that there is something called map-backed action forms that can be used for this kind of thing.
Does jsf have something like this? I can't seem to figure it out.
Thank you.

There is one thing that I don't like in the example. The generation of components in the backing bean. I am trying to generate them inside my jsp, but it won't work.
This is the code I use.
The jsp page
<body><h:form binding="#{backing_quiz.form1}" id="form1">
        <p>
          <h:dataTable value="#{backing_quiz.questions}" var="question">         
            <h:column>                   
              <h:outputText value="#{question.questionText}"/>
              <h:selectOneRadio layout="pageDirection">             
                    <f:selectItems value="#{question.answers}" />                       
              </h:selectOneRadio>             
            </h:column>
          </h:dataTable>
        </p>
        <p>
          <h:messages/>
        </p>
        <p>
          <h:commandButton value="commandButton1"
                           binding="#{backing_quiz.commandButton1}"
                           id="commandButton1"
                           action="#{backing_quiz.commandButton1_action}"/>
        </p>     
      </h:form></body>The backing bean with session scope.
public class Quiz {
    private HtmlForm form1;
    private HtmlDataTable dataTable1;
    private HtmlCommandButton commandButton1;
    private ArrayList questions = null;
    private HtmlSelectOneRadio selectOneRadio1;
    private UISelectItem selectItem1;
    private UISelectItem selectItem2;
    private UISelectItem selectItem3;
    public void setForm1(HtmlForm form1) {
        this.form1 = form1;
    public HtmlForm getForm1() {
        return form1;
    public ArrayList getQuestions() {
        if(questions == null) {             
            System.out.println("Create new list");
            questions = new ArrayList();
            Question question = new Question();
            ArrayList answers = new ArrayList();
            answers.add(new SelectItem(1,"vraag 1 antwoord 1"));
            answers.add(new SelectItem(2,"vraag 1 antwoord 2"));
            answers.add(new SelectItem(3,"vraag 1 antwoord 3"));       
            question.setQuestionText("vraag 1");
            question.setAnswers(answers);
            questions.add(question);
            question = new Question();
            answers = new ArrayList();       
            answers.add(new SelectItem(1,"vraag 2 antwoord 1"));
            answers.add(new SelectItem(2,"vraag 2 antwoord 2"));
            answers.add(new SelectItem(3,"vraag 2 antwoord 3"));
            answers.add(new SelectItem(4,"vraag 2 antwoord 4"));
            question.setQuestionText("vraag 2");
            question.setAnswers(answers);
            questions.add(question);
        return questions;
    public void setDataTable1(HtmlDataTable dataTable1) {
        this.dataTable1 = dataTable1;
    public HtmlDataTable getDataTable1() {
        return dataTable1;
    public void setCommandButton1(HtmlCommandButton commandButton1) {
        this.commandButton1 = commandButton1;
    public HtmlCommandButton getCommandButton1() {
        return commandButton1;
    public String commandButton1_action() {
        // Add event code here...
        System.out.println("add item with number " + (((Question)questions.get(0)).getAnswers().size()+1));
        ((Question)questions.get(0)).getAnswers().add(new SelectItem((((Question)questions.get(0)).getAnswers().size()+1) , "Nieuwe vraag " + ((Question)questions.get(0)).getAnswers().size()+1 ));
        return null;
}The commandButton1_action() needs to add an answer to the first question. This is in fact the backsite where quizes can be created.
When the action is called an it's redirected to the same page, the answer is added, but due to the fact that the page is rerenderd, the previously selected are gone.
Is this clear or do I need to give more explanation?

Similar Messages

  • Dynamic forms with JSF

    Hello guys !
    I hope you can help me. I am trying to do something with JSF, but I am not sure if JSF is the right approach.
    I am trying to build a dynamic web service, based on the information of a web service. That is I dont know the controls ( radio buttons, checkboxed, input boxes) , my form will have in advance, so I dont build any managed bean that maps all the controls.
    What I thought , it is to have a collection, which has the description of all the questions and posible answers, and dynamically go through the collection and build the form. (that is something I can do with datatables), and then when the user submits the form , in the action method ...I would recover the "answers" based on the ID or name of the controls, but for my surprise I cannot set the name of the controls with JSF , so I am clueless to send the answers of the form.
    I post the fill-up of the form to another web service which very briefl requires someting like this
    <answers>
            <answerid></answerid>
            <answervalue></answervalue>
    </answers>I might have the value , but not the answerid
    Thanks,
    Deibys

    or is there a way I cam force the id of a control ?
    <h:selectOneRadio id="#{question.questionid}"  layout="pageDirection" >
                             <f:selectItems value="#{question.answersOptions}" />
                        </h:selectOneRadio>this does not work for me
    org.apache.jasper.JasperException: /encuestaRiesgo.jsp(22,4) PWC6314: According to the TLD, the attribute id is not a deferred-value or deferred-method, but the specified value co

  • Dynamic form in jsf?

    Hi all, i am very new to JSF. I was wondering if it were possible to create a dynamically changing form using only JSF (without java script). Say, i need a tabbed pane that will have tabs added on clicking some button on the screen. If it is possible, does anyone know of a good code sample online? Thank you very much!!

    OK, this was a bad example. Here is another example:
    JSF:<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@taglib uri="http://www.ibm.com/jsf/BrowserFramework" prefix="odc"%>
    <odc:tabbedPanel binding="#{MyBean.tabbedPanel}" />
    <h:form>
         <h:inputText value="#{MyBean.bfPanelId}" />
         <h:inputText value="#{MyBean.bfPanelName}" />
         <h:commandButton value="add" action="#{MyBean.addBfPanel}" />
    </h:form>MyBean.javapackage mypackage;
    import com.ibm.faces.bf.component.html.HtmlBfPanel;
    import com.ibm.faces.bf.component.html.HtmlTabbedPanel;
    public class MyBean {
        // Inits
        HtmlTabbedPanel tabbedPanel = new HtmlTabbedPanel();
        String bfPanelId;
        String bfPanelName;
        // Actions
        public void addBfPanel() {
            HtmlBfPanel bfPanel = new HtmlBfPanel();
            bfPanel.setId(getBfPanelId());
            bfPanel.setName(getBfPanelName());
            getTabbedPanel().getChildren().add(bfPanel);
        // Getters
        public HtmlTabbedPanel getTabbedPanel() {
            return tabbedPanel;       
        public String getBfPanelId() {
            return bfPanelId;
        public String getBfPanelName() {
            return bfPanelName;
        // Setters
        public void setTabbedPanel(HtmlTabbedPanel tabbedPanel) {
            this.tabbedPanel = tabbedPanel;
        public void setBfPanelId(String bfPanelId) {
            this.bfPanelId = bfPanelId;
        public void setBfPanelName(String bfPanelName) {
            this.bfPanelName = bfPanelName;
    }Note that I'm using IBM's odc components. I don't have experience with Tomahawk, but this might give you some insights.

  • Dynamic Form componants in my jsf page?

    how could i make dynamic form componant in my jsf page ,depend on user inputs or result from database or whatever , where i use sun studio creator ???

    you need to use the "rendered" attribute of the components...
    for example in your jsp put this...
    <h:outputText value="Hello" rendered="#{myBean.renderHello}"/>
    the render hello method looks like this in your backing bean "myBean"
    public boolean getRenderHello() {
    return true; // or false
    if getRenderHello() returns true, "Hello" will be displayed, if getRenderHello() returns false, it will not...
    you can also use expressions in the jsf... for example...
    <h:outputText value="Hello" rendered="#{myBean.someNumber == 5}"/>
    if the "getSomeNumber()" method in your backing bean returns 5 it will be true and "Hello" will show up... otherwise it won't... :)
    Hope this helps...
    -Garrett

  • Dynamic Form Creation in JSF

    Hi ,
    I wanted to know how to create dynamic form meaning in Database i have some rows and the user is provided the option to chose which all he wants to include... Only using the ticked ones i need to generate the form...
    Can anyone tel me hw to do dis

    Use the rendered attribute to conditionally show fields or not. It will be far less work than generating a dynamic form with a matching dynamic backing bean...

  • Can someone point me to a dynamic form example?

    I'm very new to JSF.
    Simply put, I want to be able to create a page that can have a dynamic form on it. A form with potentially several fields on it defined at run time. Making it even more exciting, it will ideally support the File Upload as well.
    Do I need to create an entire JSF component for that, or can I assemble standard JSF components at run time and present the page?
    Is there an example somewhere that someone could guide me to?

    take a look at: http://jroller.com/page/RickHigh/20051130

  • A very comlicated dynamic form

    Hi guys,
    I am pretty new to JSF and I have to get a dynamic form working. Here you can see a mockup of the form, which has to be created. Blocks of drop down filed should be added and removed dynamically by clicking on the "+" and "-" buttons.
    My first idea was to make templates for the different blocks as follows:
    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:s="http://jboss.com/products/seam/taglib"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:a4j="http://richfaces.org/a4j"
          xmlns:rich="http://richfaces.org/rich">
                                       <h:panelGroup>
                                            or<br />Can
                                            <h:selectOneMenu styleClass="components">
                                                 <s:selectItems value=""     noSelectionLabel="Select Subject" />
                                            </h:selectOneMenu> execute
                                            <h:selectOneMenu styleClass="components">
                                                 <s:selectItems value="" noSelectionLabel="Select Operation" />
                                            </h:selectOneMenu> on
                                            <h:selectOneMenu styleClass="components">
                                                 <s:selectItems value="" noSelectionLabel="Select Object" />
                                            </h:selectOneMenu>
                                       </h:panelGroup>
                                       <h:panelGroup>
                                       <h:commandButton value="+" styleClass="components"/> <h:commandButton value="-" styleClass="components"/>
                                       </h:panelGroup>
                                       <h:div name="mydiv"/>
    </ui:composition>and then update these divs with the templated blocks. Unfortunately I dont know if that would be the right way to go. I would appreciate it if you could steer me in the right direction with some code examples and ideas.
    MANY THANKS!

    Thank you for the reply. So on the back I will have something like an arraylist of row objects and the + and - would remove objects from the list? Am I getting it right? Do you by any chance know any tutorial or an example to which i refer?
    Thanks!

  • Create a dynamic form where selected text boxes appears, based on options chosen in a drop-down box

    HELP!!! Can anyone please provide some guidance on how to create a dynamic form where selected text boxes appears, based on options chosen in a drop-down box.
    I have a form which – based on the department that's selected from a drop-down box – will have different form fields/text boxes, etc, made available.
    Is this possible in LiveCycle, if so, can you please provide the script/info - as needed.
    Thanks,

    In the preOpen event of the second dropdown list you put something like (in formCalc):
    if (dropdown1 == 1) then
    $.clearItems()
    $.setItems("Year, 2 Year,  3 Year")
    elseif (dropdown1 == 2) then
    $.clearItems()
    $.setItems("3 Year,  4 Year")
    endif

  • Get values from dynamic form items

    Hi All,
    I create a dynamic form with text input component
    private function buildForm():void{
                    var numberOfColumns:Number = 5
                    var formItem:FormItem = new FormItem();
                    var hBox:HBox = new HBox();
                    for(var i:Number=0; i< numberOfColumns; i++) {
                        var formInput:TextInput = new TextInput();
                        formInput.text = "test";
                        formInput.id = "txt_" +i;
                        hBox.addChild(formInput);
                    formItem.addChild(hBox);
                    loansForm.addChild(formItem);
    I can see the text input components, update the values.
    How can I get the updated values from the input components?
    I try  this["txt_" + i].text  but not working. It's not finding the component with the dynamic value.
    Any ideas?
    Thanks
    Johnny

    Hi,
    Here is the related thread, u will get some help
      http://forums.adobe.com/message/3075226
    Thanks and Regards,
    Kanchan Ladwani | [email protected] | www.infocepts.com

  • How to create a dynamic form with bind variables :schema & :table_name

    My application has two LOV's, one to select a schema, and the next to select a table within that schema. I then have a button which passes me to a report which displays the data in that table.schema.
    I now want to create a link to a form where I can edit the record based on the rowid of that table.schema, but it doesn't appear that I can create a dynamic form where I pass the schema.table_name and rowid. Is this possible? Can anyone advise how I can do this? The form builder only wants a fixed schema/table name.
    Thanks in advance.
    Stuart.

    Hi Stuart,
    In this sort of situation, you will need to be a bit creative.
    I would suggest a pipeline function called as if it was a report.
    Then you can pipe out the required fields.
    Since you will have a variable number of fields, you could use two of the multi row field names for your field names and values.
    Then after submit, you can create your own procedure to loop through the fields (stored for you in the Apex package) and update the table as required.
    Not very specific I'm afraid, but it should work.
    Regards
    Michael

  • Dynamic Forms and WF

    Hello,
    I have designed a dynamic form, where user can add rows dynamically by clicking a button on the form, the form is working fine in preview in designer.
    this form is initiating a LC WF process, but, if I deploy this form to form manager as an XDP and choose to render it to PDF, adding rows function does not work, however if I save this as dynamic PDF from LC designer and deploy it again to form manager, it works !!
    However, I can not use PDF generated from LC Designer since I found that commenting and annotations are not working ( I am using acrobat ) which is an important feature, also, web services calls are not working even, again from Acrobat!
    How can I set the form server installed with workflow server to render XDP templates into dynamic PDF forms ?
    Or alternatively how to enable commenting and fix web service calls in PDF rendered form ?
    Thank you for help,
    Greetings,

    By default Forms and Form Manager are configured to render a PDF as either static or dynamic based on some values in the XDP. By default those values will tell it to render a static PDF. What you can do, in Designer save as a dynamic PDF, then open the dynamic PDF in Designer and save as an XDP. Upload that XDP to Form Manager, the tags will be present to tell it to be rendered as a dynamic PDF. There's a better way if you are using Designer 7.1 and Forms 7.1, but since I don't know your environment this is a way that will work regardless of versions.
    Annotations will not work in dynamic PDF's though. Currently annotations make no sense in dyanmic PDF's since the template of the PDF can dynamically change while annotations are bound to a specific location. IE: You have a dynamic PDF that is initial 4 pages and add an annotation to page 4. Later the template of the PDF changes based on data and user interaction and it is now a 2 page PDF, but the annotation is still on page 4 which no longer exists...
    Chris
    Adobe Enterprise Developer Support

  • Remove scroll bars in dynamic form

    Hi all,
    I'm starting to kick myself every time I put a post here.  Apologies and thank you for everyone's help - slowly but shortly I'll be one of the people answering the questions.
    Really easy one (I think).  A have a dynamic form, which updates a dynamic list.  Is there a way to alter a text area in the dynamic form, so that it is a fixed area  i.e. when you get to the end of the line/characater usage, the cursor goes down to the next line rather than creating a horizontal scroll bar and running forever into the distance.  I have played around with Wrap options without luck, the css doesn;t seem to play much of a part as this is an actual text area in Dreamweaver as opposed to a CSS clipping in the list.
    Thanks again,
    Nathan

    NJFuller wrote:
    Perfect! Thank you Albert.  Is it possible to add virtual wrap to a box in a dynamic list?  As that is not presented in a normal html form'ish style way.....?
    Hi Nathan,
    as a Dynamic List displays pure text only, you´ll need to help yourself by formatting the displayed column using PHP. There are several ways to add "virtual" line breaks, and the most straightforward (though certainly not the most elegant) solution would be to apply the PHP function wordwrap which wraps a string to a given number of characters.
    The following example will wrap the text after 40 chars, and the "wordwrap" function will - as always - have to replace ADDT´s default "KT_FormatForList" function:
    <?php echo wordwrap($row_rsqueryname1['columnname'], 40, "<br />\n"); ?>
    Cheers,
    Günter

  • How to make my dynamic form pages flow correctly?

    I have created a dynamic form which has multiple questions with expandable text fields that will take multiple pages once completed.  I do not know how to make the form flow correctly past the first page.  I can attach the form if I knew how to do that.

    Thank you Paul.  Your editing assistance was greatly appreciated. I think I now understand that there should be only one page subform that is flowed, regardless of how many text box objects I have in my questionnaire. This did the trick.

  • Is it possible to update multiple tables with a dynamic form?

    I have columns from two tables populating a dynamic form. I am trying to have the form update both tables on submit. I have tried both a linked transaction and a custom transaction but I am not making progress. Only the master table is being updated. Is it possible with ADDT to update two tables with a dynamic form?

    I meant
    SXMSMSTAT
    SXMSSYERR
    Thanks.

  • My dynamic form - issue with saving data (urgent-i would greatly appreciate any help)

    Hello,
    I have some problems with this dynamic form (created in livecycle)  http://www.pathology.ubc.ca/Academic_Activity_Data_Form_Jan_4_2013.pdf .  It doesn't save data unless I add a' new row' to any of these tables.   There are a few text fileds and if I type anything in there data won't be saved unless I trigger it by adding randomly a table row.  This is big problem as this form will be used for updates and if I want to change any of my entered records I will always have to remember to 'add a new row' otherwise just adding/changing text won't be saved. This might sound confusing but you will understanding what is going on if you type in your name and save the form and then type in your name, add a table row and save the form (first case won't be saved second will).
    I would greatly appreciate any help.
    Debbie

    Hi Marco Russo ,
    = CALCULATE (
        SUM ( [measure] ),
        PARALLELPERIOD (
            SAMEPERIODLASTYEAR ( DateTime[DateKey] ),
            0,
            QUARTER
    I have used the above DAX function it is working fine and i have applied same for Year , Quarter and Month 
    But when i remove month filters (Slicer) and Year filters in Power view report
     it is showing total Year values for Year and Quarter values
    for Quarter etc..
    Like below i am getting 
    Last Yr Month Amt   Current Yr Month Amt   Last Yr Qtr Amt   Current Yr Qtr  Amt    Last Yr     Current Yr
     10000                     30000                              10000                30000
                        30000       30000
    but i need Blanks in report if i am not selecting any filters
    thanks,
    Sreeni

Maybe you are looking for

  • How do I create a NetBeans project with multiple JavaFX (FXML) dialogs?

    I'm very new to Java and JavaFX, so forgive what is probably a question asked a thousand times, but I can't seem to find the answer. I come from a Visual Studio (C# with WPF) background. I'm used to creating a Solution then adding a Project for each

  • No wifi connections with Windows 8.1 on Lenovo Flex 2-14

    I got me a new Lenovo Flex 2-14 with Windows 8.1 on it yesterday, but I can't connect to my wifi network. In the tray there's always the red cross (not the yellow symbol) and no network is found at all. I read that a lot of users experience this, so

  • My iCloud on the PC is not working. How can I restore it?

    My icloud does not seem to be working. My iphone and ipad are syncing but not with my PC. When I try to log onto icloud on the PC it says currently unavailable and photostream has stopped working. How do I solve this problem?

  • Alpha Channel errors

    Hello, I'm working with some uncompressed Quicktimes in Final Cut 6 that have built in alpha channels, but they are not working properly when placed over other footage in my timeline. I just get a black background where the video from the track below

  • Live stream buffer shrinking

    We're encountering a problem with live audio streams going through FMS. We play back the streams with a generous buffer on the client to smooth out any hiccups in the end-user's connection. But over long periods of time (10-30 minutes) the amount of