Llamar métod java desde botón de una plantilla

cancel
Showing results for 
Search instead for 
Did you mean: 
mrey
Member II

Llamar métod java desde botón de una plantilla

Hola a todos

Siguiendo este post http://forums.alfresco.com/es/viewtopic.php?f=11&t=1263&p=4712&hilit=llamar+metodo+desde+plantilla#p... he hecho un método que compruebe los metadatos de un documento y lo mueva de espacio cuando pulso el botón aprobar. Pero os pido ayuda para que me guieis sobre como puedo hacer para que al pulsar el botón llame a ese método. La plantilla es
<table>

<tr>
   <td><#list space.children as child>         
         <#if child.isDocument && (child.mimetype = "application/pdf")>
            <a href="/alfresco${child.url}" target="new"><embed src="/alfresco${child.url}"width="500" height="700"></embed>
         </#if>
         </#list>
   </td>
   <td>
   <#list space.childrenByXPath[".//*[subtypeOf('cm:content')]"] as child>
   
         <table>      
         
            <tr>
                  
                  <td>Fecha de emision:</td><td> <input type="text" name="fecha" value=${child.properties["custom:fecha"]?datetime}></td> 
            </tr>
            <tr>
                  <td>CIF de la empresa emisora:</td><td><input type="text" name="CIF" value=${child.properties["custom:CIF"]}> </td>
            </tr>
            <tr>
                  <td>Numero de factura: </td><td><input type="text" name="num_factura" value= ${child.properties["custom:numfactura"]}></td>
            </tr>
            <tr>
                  <td>Precio Base: </td><td><input type="text" name="Base" value=${child.properties["custom:base"]}></td>
            </tr>
            <tr>
                  <td>Iva: </td><td><input type="text" name="Iva" value= ${child.properties["custom:iva"]}></td>
            </tr>
            <tr>
                  <td>Precio Total:</td><td><input type="text" name="Total" value=${child.properties["custom:total"]}></td>
            </tr>
               
            <tr>
                  <td><input type=submit value="Rechazar"> </td><td><input type="submit" value="Aprobar" onclick=${aceptarFactura('child')}></td>
            </tr>
            </#if>    </#list>   
         </table>   
   </td>
</tr>
</table>

probé llamándolo con
onclick=${aceptarFactura('child')}
pero no llega a ejecutarse. Veis algo que pueda estar mal?

Muchas gracias a todos
1 Reply
mrey
Member II

Re: Llamar métod java desde botón de una plantilla

Hola

Vuelvo a recurrir a todos vosotros porque probando y siguiendo los ejemplos del sdk llegue a un punto muerto

Teniendo esta plantilla

<html>
  <body>
  <table>
       <tr>
          <td>
             <#list space.children as child>
                <#if child.isDocument && (child.mimetype = "application/pdf")>
                   <a href="/alfresco${child.url}" target="new"><embed src="/alfresco${child.url}"width="500" height="700"></embed>
                </#if>
             </#list>
          </td>
          <td>
                <table>
                  <#list space.childrenByXPath[".//*[subtypeOf('cm:content')]"] as child>
                  <form method="post" action=${aceptarFactura(child)}>
                   <tr>
                         <td>Fecha de emision:</td><td> <input type="text" name="fecha" value=${child.properties["custom:fecha"]?datetime}></td>
                   </tr>
                   <tr>
                         <td>CIF de la empresa emisora:</td><td><input type="text" name="CIF" value=${child.properties["custom:CIF"]}> </td>
                   </tr>
                   <tr>
                         <td>Numero de factura: </td><td><input type="text" name="num_factura" value= ${child.properties["custom:numfactura"]}></td>
                   </tr>
                   <tr>
                         <td>Precio Base: </td><td><input type="text" name="Base" value= ${child.properties["custom:base"]}></td>
                   </tr>
                   <tr>
                         <td>Iva: </td><td><input type="text" name="nombre" value= ${child.properties["custom:iva"]}></td>
                   </tr>
                   <tr>
                         <td>Precio Total:</td><td><input type="text" name="nombre" value=${child.properties["custom:total"]}></td>
                   </tr>
                   <tr>
                         <td><input type=submit name="revisar" value="guardar" ></td>
               </tr>
                  </form>   </#list>    </table>
          </td>
       </tr>
    </table>
  </body>
</html>


llamo al siguiente método java

public Object exec(List args) throws TemplateModelException
    {
       System.out.println("Entra en guardar metadatos");
        int result = 0;
        Boolean mover = true;
       
        if (args.size() == 1)
        {
           System.out.println("Entra en el primer if");
           
            Object arg0 = args.get(0);
             if (arg0 instanceof TemplateNodeModel)
             {
                System.out.println("Entra en la instancia");
                  Node documento = (Node)arg0;
               
                  Map<QName, Serializable> properties = this.nodeService.getProperties(documento.getNodeRef());
                  //Guarda las propiedades del documento antes de moverlo
                  this.services.getNodeService().setProperties(documento.getNodeRef(), properties);
               
                  QName fecha_factura = QName.createQName("custom.model", "fecha");
                  QName numfactura = QName.createQName("custom.model", "numfactura");
                  QName cif = QName.createQName("custom.model", "CIF");
                  QName base = QName.createQName("custom.model", "base");
                  QName iva = QName.createQName("custom.model", "iva");
                  QName total = QName.createQName("custom.model", "total");
                  Map<String, Object> map = new HashMap<String, Object>();
                  map.put("fecha", documento.getProperties().get(fecha_factura));
                  map.put("numfactura", documento.getProperties().get(numfactura));
                  map.put("cif", documento.getProperties().get(cif));
                  map.put("base", documento.getProperties().get(base));
                  map.put("iva", documento.getProperties().get(iva));
                  map.put("total", documento.getProperties().get(total));
                  Iterator it = map.entrySet().iterator();
                  do{
                     System.out.println("Entra en la funcion node");
                     if((it.next() == null)||(it.next() == "")){
                        mover = false;
                        break;
                     }
                  } while(it.hasNext());

Por ahora mi idea es qeu compruebe los metadatos y los guarde, pero al entrar en el método se queda en esta línea
if (arg0 instanceof TemplateNodeModel)

Si hago un 
System.out.println(arg0.getClass());
en la consola me dice lo siguiente: class freemarker.template.StringModel

Alguna idea de por que no pasa de esa línea? A qué debo instanciar arg0? va todo mal?

Muchas gracias a todos