0 Replies Latest reply on Dec 14, 2009 12:15 PM by Daniel Posch

    Dynamically generated table content (without <rich:dataTable>)

    Daniel Posch Newbie

      Hi everyone,

       

      I am a RichFaces newbie and still struggling with a problem that I failed to solve using <rich:paint2D> as seen in this thread and decided to open a new thread, because the problem now has nothing to do with <rich:paint2D> anymore.

       

      So, basically what I want to do is fetch a bunch of hardware of my database (Hardware is an EntityBean) and illustrate the physical location of these hardware elements using a table. The hardware is located in one of three cabinets, which consist of four subracks and 19 plugin units, so I created a table with 3 * 19 columns and four rows - I hope you get an idea of what I try to do.

       

      Since <rich:paint2D> is not an option anymore, I tried to dynamically generate the value for each table element. I defined a three-dimensional array in a session bean (that is, hardwareLocationArr[cabinet][subrack][plugin_unit]) with conventional getters and setters (does that actually work with arrays?) and tried to update an <h:outputText> inside each table element using <a4j:repat> and <a4j:jsFunction> outside the table.

       

      The resulting code looks like this:

       

      <table border="1" width="auto">
          <tr>
              <!-- cabinet 1, subrack 1 -->
              <td><h:outputText id="hwLoc111" value="#{netElementPainter.hardwareLocationArr[0][0][0]}" /></td>
              <td><h:outputText id="hwLoc112" value="#{netElementPainter.hardwareLocationArr[0][0][1]}" /></td>
              <td><h:outputText id="hwLoc113" value="#{netElementPainter.hardwareLocationArr[0][0][2]}" /></td>
              <td><h:outputText id="hwLoc114" value="#{netElementPainter.hardwareLocationArr[0][0][3]}" /></td>
              <td><h:outputText id="hwLoc115" value="#{netElementPainter.hardwareLocationArr[0][0][4]}" /></td>
              <td><h:outputText id="hwLoc116" value="#{netElementPainter.hardwareLocationArr[0][0][5]}" /></td>
              <td><h:outputText id="hwLoc117" value="#{netElementPainter.hardwareLocationArr[0][0][6]}" /></td>
              <td><h:outputText id="hwLoc118" value="#{netElementPainter.hardwareLocationArr[0][0][7]}" /></td>
              <td><h:outputText id="hwLoc119" value="#{netElementPainter.hardwareLocationArr[0][0][8]}" /></td>
              <td><h:outputText id="hwLoc1110" value="#{netElementPainter.hardwareLocationArr[0][0][9]}" /></td>
              <td><h:outputText id="hwLoc1111" value="#{netElementPainter.hardwareLocationArr[0][0][10]}" /></td>
              <td><h:outputText id="hwLoc1112" value="#{netElementPainter.hardwareLocationArr[0][0][11]}" /></td>
              <td><h:outputText id="hwLoc1113" value="#{netElementPainter.hardwareLocationArr[0][0][12]}" /></td>
              <td><h:outputText id="hwLoc1114" value="#{netElementPainter.hardwareLocationArr[0][0][13]}" /></td>
              <td><h:outputText id="hwLoc1115" value="#{netElementPainter.hardwareLocationArr[0][0][14]}" /></td>
              <td><h:outputText id="hwLoc1116" value="#{netElementPainter.hardwareLocationArr[0][0][15]}" /></td>
              <td><h:outputText id="hwLoc1117" value="#{netElementPainter.hardwareLocationArr[0][0][16]}" /></td>
              <td><h:outputText id="hwLoc1118" value="#{netElementPainter.hardwareLocationArr[0][0][17]}" /></td>
              <td><h:outputText id="hwLoc1119" value="#{netElementPainter.hardwareLocationArr[0][0][18]}" /></td>
              
              <!-- cabinet 2, subrack 1 -->
              <td><h:outputText id="hwLoc211" value="#{netElementPainter.hardwareLocationArr[1][0][0]}" /></td>
              <td><h:outputText id="hwLoc212" value="#{netElementPainter.hardwareLocationArr[1][0][1]}" /></td>
              <td><h:outputText id="hwLoc213" value="#{netElementPainter.hardwareLocationArr[1][0][2]}" /></td>
              <!-- ... -->
              <!-- and so on -->
      
              <!-- ... -->
      
              <td><h:outputText id="hwLoc3416" value="#{netElementPainter.hardwareLocationArr[2][3][15]}" /></td>
              <td><h:outputText id="hwLoc3417" value="#{netElementPainter.hardwareLocationArr[2][3][16]}" /></td>
              <td><h:outputText id="hwLoc3418" value="#{netElementPainter.hardwareLocationArr[2][3][17]}" /></td>
              <td><h:outputText id="hwLoc3419" value="#{netElementPainter.hardwareLocationArr[2][3][18]}" /></td>
          </tr>
      </table>
      <a4j:form>
          <a4j:repeat value="#{netElementsHome.hardwares}" var="hardware">
              <a4j:jsFunction name="fillTable" reRender="hwLoc#{hardware.cabinet}#{hardware.subrack}#{hardware.pluginunitpos}">
                  <a4j:actionparam name="#{hardware.attachedtofunit}" assignTo="#{netElementPainter.hardwareLocationArr['#{hardware.cabinet - 1}']['#{hardware.subrack - 1}']['#{hardware.pluginunitpos - 1}']}" />
              </a4j:jsFunction>
              <script type="text/javascript">fillTable();</script>
          </a4j:repeat>
      </a4j:form>
      

       

      I know this looks quite awkward, but I have not found a better solution yet. As if it weren't clear, this does not work. The table exists, but it is empty.

       

      Maybe someone of you can help out. Why does my code not work? Are there any better solutions to get the information in my table elements?

       

      Any suggestions?

       

      Best Regards,

       

      Daniel