14 Replies Latest reply on Dec 5, 2006 3:40 AM by sherkan777

    Using textInput inside a dataTable inside a form?

    smokingapipe

      Let's say that I want a user to be able to update an invoice with many line items on it. They should be able to make all their quantity updates and hit submit. The abreviated and somewhat simplified HTML might look like this:

      <form>
       <table>
       <tr>
       <th>Item:</th>
       <th>Quantitiy ordered</th>
       </tr>
      
       <tr>
       <td>Diet Coke</td>
       <td><input name="invoice[0]quantity" type="text" value="5"/></th>
       </tr>
      
       <tr>
       <td>Sprite</td>
       <td><input name="invoice[1]quantity" type="text" value="2"/></th>
       </tr>
       </table>
      
       <input type="submit" value="Update quantities"/>
      </form>
      


      I like to use these contructions quite a lot. I have tried, without success, to make something like this work. The problem is that I'll have a table like this:

       <h:form>
       <t:dataTable id="invoiceTable"
       var="item"
       value="#{invoice.items}"
       >
      
       <t:column>
       <f:facet name="header">
       <h:outputText value="Item name"/>
       </f:facet>
       <h:outputText value="#{item.name}"/>
       </t:column>
      
       <t:column>
       <f:facet name="header">
       <h:outputText value="Quantity"/>
       </f:facet>
      
       <h:inputText value="#{item.quantity}" size="5"/>
      
       </t:column>
       </t:dataTable>
      
       <h:commandButton value="Update invoice" action="#{invoiceManager.update}"/>
      
       </h:form>
      


      which of course, does not work, because the inputText value="#{item.quantity}" is not actually a value binding because the "item" variable only exists within the table iteration (is this correct?) Is there a way to get this type of thing to work? I'm totally stumped.

      Thanks


        • 1. Re: Using textInput inside a dataTable inside a form?
          pmuir

          What you have should work. Show the backing bean

          • 2. Re: Using textInput inside a dataTable inside a form?
            smokingapipe

            I set up a simplified test case, which did work. Now I need to figure out what is going on with my more complicated real use to see why that isn't working.

            • 3. Re: Using textInput inside a dataTable inside a form?
              smokingapipe

              Now I don't think it's in my code. I have checked it over. I have it working in a test case but not in a case where the entities are actually persistent. Hmm. Seam holds great promise, but for now is fragile and has almost no possibility of debugging these things. There's no way to tell which objects are being handled in the page or what is happening in the assign values phase of JSF.

              • 4. Re: Using textInput inside a dataTable inside a form?
                smokingapipe

                I'm now thinking that this is a bug in JBoss' JSF implementation. The restore view phase isn't even happening on the form. I'm trying to make a test case for this.

                • 5. Re: Using textInput inside a dataTable inside a form?
                  pmuir

                  I'm 99% that it is no bug (which is the default JBoss JSF impl). It's also highly unlikely that it is the persisting of objects that is causing this.

                  I notice that you don't show a h:messages component. Are you sure that there are no validation/conversion errors on your form?

                  • 6. Re: Using textInput inside a dataTable inside a form?
                    pmuir

                    sorry, I meant

                    that it is no bug in Myfaces

                    • 7. Re: Using textInput inside a dataTable inside a form?
                      smokingapipe

                      I put in: <h:messages globalOnly="false"/> after the table, and get no messages. I also turned off all the validation in the various classes. This is 99% a bug in the JSF implementation. There's no reason why it shouldn't hit the "update model values" phase, because if it were dying in the process validations phase, there would be some type of message, right? Surely with all the advanced features of Seam and JSF there's some way for it tell me which phase it's in, what it's doing, etc? In any normal programming system you can trace the values of variables.

                      • 8. Re: Using textInput inside a dataTable inside a form?
                        pmuir

                         

                        "SmokingAPipe" wrote:
                        I put in: <h:messages globalOnly="false"/> after the table, and get no messages. I also turned off all the validation in the various classes. This is 99% a bug in the JSF implementation.


                        I think you need to produce a simple runnable test case then.

                        There's no reason why it shouldn't hit the "update model values" phase, because if it were dying in the process validations phase, there would be some type of message, right?


                        There would be a message in h:messages, yes.

                        Surely with all the advanced features of Seam and JSF there's some way for it tell me which phase it's in, what it's doing, etc? In any normal programming system you can trace the values of variables.


                        Sorry, I'm not in front of the right computer atm so can't give you details but you can do this by attaching a debugger into myfaces.

                        Also, I've just noticed that you are using tomahawk. You would be much better stripping all that out and reproducing this with just h: components

                        • 9. Re: Using textInput inside a dataTable inside a form?
                          pmuir

                          If the restore view phase isn't happening you do have something weird going on...

                          • 10. Re: Using textInput inside a dataTable inside a form?
                            smokingapipe

                            Ok, following your suggestion, I removed all the Tomahawk components. Somehow they were working when they shouldn't have been. I removed all of them, and made it only one column, to just display (no input) the field I want to display, and I get an exception with this cause:

                            "value of context variable is not an instance of the component bound to the context variable"

                            So I am doing something wrong, I just need to figure out what it is. If I can figure that out, I can probably go back to the Tomahawk components, or whatever, but at least it will be working.

                            This whole system has so many pitfalls. Right now, if there's any error in a Servlet / JSP type of system, I can look at it and know where the error is within five minutes, because I'm so familiar with it. I feel like with the Seam world right now there are so many new things I'm unsure of where to begin to track bugs down.

                            • 11. Re: Using textInput inside a dataTable inside a form?
                              smokingapipe

                              I'm getting closer to it, and it is in fact a JSF bug.

                              • 12. Re: Using textInput inside a dataTable inside a form?
                                sherkan777

                                I have same problem but I think when U use dataTable component is submited x times (x is size of your collection).
                                I made some example

                                private String tagName;
                                private List tagList;

                                <h:dataTable var="answers" value="#{answerList}" >
                                <h:column>
                                <h:outputText id="a1" value="#{answers.answer}" escape="false"/>

                                <h:inputText value="#{showDetailedQuestionAction.tagName}"/>
                                <h:commandButton value="myButton" action="#{bbBean.action}"/>
                                </h:column>
                                </h:dataTable>

                                and method implemented in setter & getter for tagName;
                                public String getTagName() {
                                System.out.println("Get: " + this.tagName);
                                return tagName;
                                }
                                public void setTagName(String tagName) {
                                System.out.println("SET: " + this.tagName);
                                this.tagName = tagName;
                                }

                                and Result:
                                09:19:15,187 INFO [STDOUT] SET: null
                                09:19:15,203 INFO [STDOUT] SET:
                                09:19:15,203 INFO [STDOUT] SET:
                                09:19:15,203 INFO [STDOUT] SET: myInsertedString
                                09:19:15,203 INFO [STDOUT] Get:
                                09:19:15,203 INFO [STDOUT] Action method clicked
                                09:19:15,250 INFO [STDOUT] Get:
                                09:19:15,328 INFO [STDOUT] Get:
                                09:19:15,328 INFO [STDOUT] Get:
                                09:19:15,343 INFO [STDOUT] Get:
                                09:19:15,343 INFO [STDOUT] Get:


                                So, and on my final result I cant get my tagName, ony if I insert some string to last inputText.
                                Can anyone tell me how to get my tagName value?

                                • 13. Re: Using textInput inside a dataTable inside a form?
                                  sherkan777

                                  Result of my problem is to create form for each row...

                                  • 14. Re: Using textInput inside a dataTable inside a form?
                                    sherkan777

                                    My Propsion for smokingPipe problem, try to make somethink like this:

                                    
                                    <t:dataTable id="invoiceTable"
                                     var="item"
                                     value="#{invoice.items}">
                                    
                                    <t:column>
                                     <f:facet name="header">
                                     <h:outputText value="Item name"/>
                                     </f:facet>
                                     <h:outputText value="#{item.name}"/>
                                    </t:column>
                                    
                                    <t:column>
                                     <f:facet name="header">
                                     <h:outputText value="Quantity"/>
                                     </f:facet>
                                     <h:form>
                                     <h:inputText value="#{item.quantity}" size="5"/>
                                     <h:commandButton value="Update invoice" action="#{invoiceManager.update}"/>
                                     </h:form>
                                    </t:column>
                                    </t:dataTable>