6 Replies Latest reply on Nov 28, 2011 6:32 AM by giant2

    Dynamic form and SEAM

    giant2 Newbie

      Hi all,
      I try to create a dynamic form composed by textfields, combo, check, etc.
      I saw some articles about dynamic form, but nothing like the one I need.
      My problem is how can refer to the dynamic fields when I need to save data written on them.
      Someone could help me?

        • 1. Re: Dynamic form and SEAM
          giant2 Newbie
          In particularly I refer to this situation:
          2 textfields inserted with <c:forEach>
          1 button to see what user wrote in these 2 textfields.
          Both textfields (values) are part (List) of a session object.
          See the code below (in action the button):
          for (int i=0;i<txtfields.size();i++){
                         El el=txtfields.get(i);
                         System.out.println(el.getId()+" "+el.getTxt()+" "+el.getVal());
          I see only the last textfield value is really present in getVal, the first one is ever blank.

          I see the html code produced for the page and see:
          <input type="text" value="" name="xxxForm:j_id17">
          <input type="text" value="" name="xxxForm:j_id21">
          so the two textfields have different name.
          I try to change the order and see only the last one is valuated.

          Why only the last???
          Is it a problem of Seam with dynamic form or a wrong way to develop?
          • 2. Re: Dynamic form and SEAM
            omid pourhadi Apprentice

            In this case i recommend Inject Seam Built in Parameters component and get your request values then set them in your entity

            Parameters params = Parameters.instance(); // or @In Parameters parameters
                  if (params!=null) 
                     Map<String, String[]> requestParameters = params.getRequestParameters();

            • 3. Re: Dynamic form and SEAM
              giant2 Newbie

              Thanks for the answer, but what do you mean for Parameters?
              I check the value inserted on the page (the 2 textfields) in an action which show me only the last value and not both.
              Why this appens?

              • 4. Re: Dynamic form and SEAM
                nathan dennis Expert

                he is saying if you are generating a dynamic form and you dont know how many inputs the screen will/could have... maybe you are even trying a recursive form or sorts,,, then use the Parameter Map to get the array of parameters and reference it accordingly.

                • 5. Re: Dynamic form and SEAM
                  giant2 Newbie

                  Ok. Infact I have an object @In @Out containig a java.util.List of objects which contain values and label of the textfields I create in the foreach tag.
                  I try to debug all the app and see the values are correctly set, but for all the textfield after the correct set, a set(blank) is called; only for the last textfield there is only the correct set.
                  Why this appens, I'm becaming crazy!!!

                  • 6. Re: Dynamic form and SEAM
                    giant2 Newbie

                    Solved myself!
                    The problem is that foreach reinit the page after the setting and so the values aren't all maintained.
                    Using ui:repeat all goes ok (without any change to the code).