3 Replies Latest reply on Jul 15, 2008 2:54 PM by nejc kikelj

    Form nested within a subtable

    Martin Treiber Newbie

      I am working on a editable rich:datatable. My database entries are shown with a rich:subtable, and some of the entries are supposed to be changed. I already tried to insert f:form at several positions but the only thing that seems to work is when I put it above the whole table. But that means, that every field is changed in the database and not just the selected. Is there a way to work around this?



           <h:form>
           <rich:dataTable value="#{gradesList}" var="subj">
                <rich:column colspan="13"><h:outputText value="#{subj.name}" /></rich:column>
                
                <rich:subTable value="#{subj.grades}" var="grade">
      
                <!-- this is where the magic is supposed to happen -->
                <rich:columnGroup rendered="#{org.jboss.seam.framework.currentDate.year + 1900 == grade.subj.year}">
                     <rich:column><h:outputText value="#{grade.subj.year}" /></rich:column>
                     <rich:column><h:inputText size="4" value="#{grade.t1g1}" /></rich:column>
                     <rich:column><h:inputText size="4" value="#{grade.t1g2}" /></rich:column>
                     <rich:column><h:inputText size="4" value="#{grade.t1g3}" /></rich:column>
                     <rich:column><h:outputText value="Wird berechnet" /></rich:column>
                     <rich:column><h:inputText size="4" value="#{grade.t2g1}" /></rich:column>
                     <rich:column><h:inputText size="4" value="#{grade.t2g2}" /></rich:column>
                     <rich:column><h:inputText size="4" value="#{grade.t2g3}" /></rich:column>
                     <rich:column><h:outputText value="Wird berechnet" /></rich:column>
                     <rich:column><h:inputText size="4" value="#{grade.t3g1}" /></rich:column>
                     <rich:column><h:inputText size="4" value="#{grade.t3g2}" /></rich:column>
                     <rich:column><h:inputText size="4" value="#{grade.t3g3}" /></rich:column>
                     <rich:column><h:outputText value="Wird berechnet" /></rich:column>
                     <rich:column><h:commandButton action="#{matriculation.changeGrades}" value="insert" /></rich:column>
                </rich:columnGroup>
                
                <!-- uneditable -->
                <rich:columnGroup rendered="#{org.jboss.seam.framework.currentDate.year + 1900 != grade.subj.year}">
                     <rich:column><h:outputText value="#{grade.subj.year}" /></rich:column>
                     <rich:column><h:outputText value="#{grade.t1g1}" /></rich:column>
                     <rich:column><h:outputText value="#{grade.t1g2}" /></rich:column>
                     <rich:column><h:outputText value="#{grade.t1g3}" /></rich:column>
                     <rich:column><h:outputText value="Wird berechnet" /></rich:column>
                     <rich:column><h:outputText value="#{grade.t2g1}" /></rich:column>
                     <rich:column><h:outputText value="#{grade.t2g2}" /></rich:column>
                     <rich:column><h:outputText value="#{grade.t2g3}" /></rich:column>
                     <rich:column><h:outputText value="Wird berechnet" /></rich:column>
                     <rich:column><h:outputText value="#{grade.t3g1}" /></rich:column>
                     <rich:column><h:outputText value="#{grade.t3g2}" /></rich:column>
                     <rich:column><h:outputText value="#{grade.t3g3}" /></rich:column>
                     <rich:column><h:outputText value="Wird berechnet" /></rich:column>
                </rich:columnGroup>
                </rich:subTable>
           </rich:dataTable>
           </h:form>



      The method changeGrades from the backing bean does a simple merge to the database (grade is fetched by @In).

        • 1. Re: Form nested within a subtable
          Keith Naas Novice

          From an aesthetic standpoint, would it be better to have only the selected row be editable?  This would let you enforce the form submission behavior you desire. 


          I'm a little bit confused about what you are describing, the user goes to the row 1 and makes some changes.  They then go to row 2.  As soon as they switch to row 2 are you submitting the changes from row 1?  Do they have to click a save button?


          Now, as far as the correct place to put the form tag, a component such as a subTable or columnGroup probably allows only certain tags to be nested within them.  For instance, a columnGroup probably allows a column, but not a form, input, select, etc.   You may need to split up your rows into separate subtables so that you can have a form per row.

          • 2. Re: Form nested within a subtable
            Martin Treiber Newbie

            This is a piece of software for a school. The tabel shows the grades of a student according to the subject. Therefore I have a subtable for each subject where the grades are shown, but only the current year's grades are editable.


            The user is supposed to enter the grades for one subject (Trimester One-Grade One, Trimester One-Grade Two, ...., Trimester Tree-Grade Three). After clicking on Insert this gets written to the database.
            What it is doing now is, that no matter where on the form data has been entered (data changed for multiple subjects), it's getting written to the database.

            • 3. Re: Form nested within a subtable
              nejc kikelj Newbie

              Hello,


              I have a similar problem...


              I have a rich:subTable that shows checkboxes from a List of boolean objects and I need to save all the changes made inside with one button...


              any hints? :)