Asignar valor de base de datos a variable de layout

25 May '18, 01:29 AM
2,500 Views
No Forum Badges

Hola, buenas tardes.

Estoy trabajando en un layout donde se muestran los valores de una tabla de base de datos (con un foreach), la situación es: ¿De que manera puedo manipular (asignar) ese valor de la base de datos para poder trabajar con el?, por ejemplo, si el valor que estoy mostrando es un cero, mostar en el <td> "sin asignar", y si es 1 "asignado", el lugar del cero o el uno. 

<c:forEach var="current" varStatus="status" items="${<wr:Id context="unit"/>.data}">

  <c:set var="index" value="${status.index}"/>

  <tr>

  <td><wr:Value context="distrito"/></td>

  <td><wr:Value context="casilla"/></td>

  <td><wr:Value context="crNoLlego"/></td>

  <td><wr:Value context="crViolencia"/></td>

  <td><wr:Value context="crOtros"/></td>

  <td><wr:Value context="abCambSinJus"/></td>

  <td><wr:Value context="abRecibenVot"/></td>

  <td><wr:Value context="abOcho"/></td>

<td><wr:Value context="abCambioJust"/></td>

  <td><wr:Value context="abierta"/></td>

  <td><wr:Value context="sinRep"/></td>

  <td><wr:Value context="sinRepresent"/></td>

  <td class="numCeltd"><wr:Value context="numCel"/></td>

            <td><wr:Value context="atencion"/>

  <td>

  <select name="select" onchange="clicBoton(<wr:Value context="casilla"/>);">

  <option value="Si">Si</option>

  <option value="No">No</option>

  </select><wr:Value context="seContacto"/>

</td>

  </tr>

</c:forEach>

 
x 0
Follow
Answer Answer at this question and get points!
No Forum Badges

Hola Antonio

Primero debes tener en el template declarado el atributo que deseas comparar por ejemplo:

def productValue = unit.selectSingleNode("layout:Attribute[@name='productValue']")

 

Luego de definirlo, dentro del foreach puedes obtener su valor y compararlo con la siguiente sintaxis:

 

${not empty current.[%= getFieldName(productValue["attribute"])%]}

 

Para este ejemplo estoy preguntado si el valor no está en blanco, pero pudieras compararlo con "eq 0" para el caso que necesitas. 

 

Espero que te ayude

 


Hi Antonio

First of all, you have to declare the attribute on the template, for example:

def productValue = unit.selectSingleNode("layout:Attribute[@name='productValue']")

 

Then, inside of the "foreach" you can get the value and compare it like this:

${not empty current.[%= getFieldName(productValue["attribute"])%]}

 

In this example, I'm asking if the value is empty, but you can ask if is equals to 0 using "eq 0".

 

I hope it helps you.

 
x 0
Answer at this question and get points!