1 Reply Latest reply on Apr 13, 2009 9:05 AM by Oguzhan YALCIN

    descriptions instead values

    Moissane Hernández Newbie

      In my database table configIp I have a field named mask(subnet mask).


      A mask value can be:


      128.0.0.0 (equivalent to 1)


      192.0.0.0 (equivalent to 2)


      224.0.0.0 (equivalent to 3)


      ...and so on.


      Then, in my xhtml form I have a selectOneMenu to pick the mask



      <h:selectOneMenu id="mask" value="#{configIp.mask}">
              <f:selectItem itemValue="-" itemLabel=""/>
              <f:selectItem itemValue="128.0.0.0" itemLabel="1"/>
              <f:selectItem itemValue="192.0.0.0" itemLabel="2"/>
              <f:selectItem itemValue="224.0.0.0" itemLabel="3"/>
              <f:selectItem itemValue="240.0.0.0" itemLabel="4"/>
              <f:selectItem itemValue="248.0.0.0" itemLabel="5"/>
              <f:selectItem itemValue="252.0.0.0" itemLabel="6"/>
              <f:selectItem itemValue="254.0.0.0" itemLabel="7"/>
              <f:selectItem itemValue="255.0.0.0" itemLabel="8"/>
      </h:selectOneMenu>
      


      When I pick up, for example, 3 from de combobox the 224.0.0.0 value is writen in the field mask in the db table, and its fine.
      I have another xhtml form to list the table values in a rich:dataTable component like this:



      <rich:dataTable id="accessList" value="#{configIpList}" var="access" 
              rows="10" columnsWidth="200,20,300">
              <a4j:support event="onRowClick" reRender="edit,remove"
                      action="#{accessView.dataTableObtenerSele(access)}"
                      onsubmit="select(this,'#e6e6e6','#{a4jSkin.tableBackgroundColor}')"/>
              <rich:column>
                      <f:facet name="header">Ip</f:facet>
                              <h:outputText value="#{access.ip}" styleClass="mytext"/>
              </rich:column>
              <rich:column>
                      <f:facet name="header">Mask</f:facet>
                              <h:outputText value="#{access.mask}" styleClass="mytext"/>
              </rich:column>
      </rich:dataTable>
      


      Well just I need to show the equivalent value(3) instead mask value (224.0.0.0) in the Mask rich:column of the rich:dataTable. How can I do that?

        • 1. Re: descriptions instead values
          Oguzhan YALCIN Newbie

          Hi,
          It will be a better practice to store those ip ranges in a lookup table in db. By giving a foreign key relation your problem can be solved easily. But in your case, you can simply use <c:choose>
          and <c:when> for converting your ip values to int values like:



          <rich:dataTable id="accessList" value="#{configIpList}" var="access" 
                  rows="10" columnsWidth="200,20,300">
                  <a4j:support event="onRowClick" reRender="edit,remove"
                          action="#{accessView.dataTableObtenerSele(access)}"
                          onsubmit="select(this,'#e6e6e6','#{a4jSkin.tableBackgroundColor}')"/>
                  <rich:column>
                          <f:facet name="header">Ip</f:facet>
                                  <h:outputText value="#{access.ip}" styleClass="mytext"/>
                  </rich:column>
                  <rich:column>
                          <f:facet name="header">Mask</f:facet>
                  <c:choose>
                      <c:when test="#{access.mask == '128.0.0.0'}">
                                  <h:outputText value="1" styleClass="mytext"/>
                      </c:when>
                      <c:when test="#{access.mask == '192.0.0.0'}">
                                  <h:outputText value="2" styleClass="mytext"/>
                      </c:when>
                      ...
                  </c:choose>
                  </rich:column>
          </rich:dataTable>