Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Server validator for formItem without datasource

    Well, we are working in the client side, we have a dynamicForm with no datasource linked, and we want to validate in the server side some formItems value. We have looking for examples to do this, but all we have found is through the xml datasource definition.
    We have tried to do so but don't get ok result:

    Code:
    ...
    	fields:
    	[
    	 	//
    	 	//	Campos de entrada
    	 	//
    		{
    			name:"USUARIO",
    			title: terminalesSacarTradicionalUIDS.getField("terminalesSacarTradicional.usuario").title
    			,validateOnExit:true 
    			,validators: [{
    				type: "serverCustom",
    				serverObject: {lookupStyle: "new",
    							   className: "com.redur.orm.terminal.TerminalSacarTradicionalValidator"
    				},
    				errorMessage: "Error zasca en user"
    			}]
    		},
    ...
    Then (in a button click event) we call validate method, but it doesn't seems to work, because we have put a breakpoint into the java code, but it never stops there.

    Could you help us about how to make this?

    Thanks in advance.


    We are working under:
    v9.1p_2014-06-11/PowerEdition Development SC and IExplrorer 10.0.9200 navigator, Eclipse Helios and Tomcat 7.0.28

    #2
    By the way, the java source code, we have been written is almost the same that is in your example.

    Code:
    package com.redur.orm.terminal;
    
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Map;
    
    import org.springframework.web.context.ContextLoader;
    import org.springframework.web.context.WebApplicationContext;
    
    import com.isomorphic.datasource.DSRequest;
    import com.isomorphic.datasource.DataSource;
    import com.isomorphic.datasource.Validator;
    import com.isomorphic.util.DataTools;
    import com.redur.beans.terminal.BeanAtteyParametrosWS;
    import com.redur.generalObject.TemplateGenericDaoIbatis;
    import com.redur.orm.LlamadaBasicaDMI;
    
    public class TerminalSacarTradicionalValidator  {
    
        // the first four arguments (value, validator, fieldName, record) are required.
        // After those four arguments, you can optionally declare further arguments for any of the
        // objects that are available at validation time, in any order.  
        //
        // Here, we declare the four required arguments, and then a fifth argument of type
        // "DataSource" - it receives the DataSource that this validator was declared in.
        public boolean condition(Object value, Validator validator, String fieldName, Map record, DataSource ds) throws Exception {
    
            int quantityOrdered = Integer.valueOf(value.toString()).intValue();
    
            // look up the StockItem by id to see current quanity
            DSRequest dsRequest = new DSRequest("StockItem", "fetch");
            Object itemId = record.get("itemId");
            // if no item was selected, no way to run this validation - rely on a required
            // validator on the itemId question to tell the user to populate the form.
            if (itemId == null) return true;
            
            dsRequest.setCriteria(DataTools.buildMap("id", record.get("itemId")));
    
            Map dataMap = dsRequest.execute().getDataMap();
            if (dataMap == null) {
                // No row found - throw an error
                throw new Exception("Unrecognized stock item ID");
            }
            
            long quantityAvailable = ((Integer)dataMap.get("quantity")).intValue();
    
            if (quantityOrdered > quantityAvailable) {
                validator.addErrorMessageVariable("available", "" + quantityAvailable);
                return false;
            }
            
            return true;
        }	
    } // De la clase

    Comment


      #3
      Server validation does indeed require a .ds.xml file.

      It makes no sense to try to put a server-side validator definition in JavaScript, because the server side does not process your JavaScript files.

      Comment


        #4
        Originally posted by Isomorphic View Post
        Server validation does indeed require a .ds.xml file.

        It makes no sense to try to put a server-side validator definition in JavaScript, because the server side does not process your JavaScript files.
        Well and then, how can I get this goal? I mean, how can I make a server validation synchronous for this field without the need of a datasource file? I am thinking about a DMI call in JavaScript, but I need to make it synchronous. How can I do this?

        Comment


          #5
          You should simply use a DataSource file. Any other way of doing it would be more complicated, so we don't know why you are even looking at any other options.

          An example of how to do this kind of thing with a DataSource file is here. As you can see, we've made it very simple.

          Comment

          Working...
          X