1. #1
    Sencha User
    Join Date
    Apr 2013
    Posts
    30
    Vote Rating
    0
    kozla13 is on a distinguished road

      0  

    Default Answered: Server validation

    Answered: Server validation


    I need to check if username is alredy taken. This unique check can only be done on the server side.
    Is ti posible to do such a validation ?

  2. I thought you might say that, there really has to be a better way to do this but what you could do as a work around is have the call back of that rpc call another method that does something like this:

    Code:
        public TextField buildTextFieldWidget(boolean nameUnique) {
            if(nameUnique){
                 nameField.forceInvalid("Name must be unique");
           }
        }

  3. #2
    Sencha User
    Join Date
    May 2011
    Posts
    47
    Answers
    2
    Vote Rating
    0
    nmb1106 is on a distinguished road

      0  

    Default


    What we do to validate the username is make and RPC call down to the server that performs a count on the associated table for that username, if the value comes back >=1 we return a false validation, and if it returns as 0 then we return true and let the user continue.

  4. #3
    Sencha User
    Join Date
    Apr 2013
    Posts
    30
    Vote Rating
    0
    kozla13 is on a distinguished road

      0  

    Default


    Quote Originally Posted by nmb1106 View Post
    What we do to validate the username is make and RPC call down to the server that performs a count on the associated table for that username, if the value comes back >=1 we return a false validation, and if it returns as 0 then we return true and let the user continue.
    can you post some code example

  5. #4
    Sencha User
    Join Date
    May 2011
    Posts
    47
    Answers
    2
    Vote Rating
    0
    nmb1106 is on a distinguished road

      0  

    Default


    Using a standard RPC call similar to: (We build our rpc's using a factory that is not important)
    Code:
            CustomRPCFactory.getJobService(true).checkJobNameUnique(null, jobName.getValue(), new CustomAsyncCallback<Boolean>() {
                @Override
                public void onSuccess(final Boolean result)
                {
                    if (result)
                    {
                        saveJobDetails();
                    }
                    else
                    {
                        MessageBox.alert("Add Job", "Job name must be unique.", null);
                    }
                }
            });
    Here is the underlying service that ithe above method is calling:

    Code:
        /**
         * Checks to see if there are any existing job masters (not including itself) with a name matching the name parameter.
         *
         * @param code
         * @param name
         * @return
         */
        public boolean checkJobNameUnique(Long code, String name)
        {
            final Long count = (Long) jobDaoExt.countWithMatchingName(code, name);
            if (count > 0)
            {
                return false;
            }
    
            return true;
        }
    Then here is the countWithMatchingName method inside the hibernate DAO:

    Code:
        public Object countWithMatchingName(final Long code, final String name)
        {
            String queryString = "select count(model) from job model where model.jobName = :name";
    
            if (code != null)
            {
                queryString += " and model.jobCode <> :code";
            }
    
            queryString += " and model.jobDeleted <> 'Y'";
    
            final Query query = entityManager.createQuery(queryString);
    
            query.setParameter("name", name);
    
            if(code!=null){
                query.setParameter("code", code);
            }
    
            return query.getSingleResult();
        }

  6. #5
    Sencha User
    Join Date
    Apr 2013
    Posts
    30
    Vote Rating
    0
    kozla13 is on a distinguished road

      0  

    Default


    i understend you approtch, but thats not what.
    i want the option if the user cliks out of the field(onBluer), that the server validat !
    And i want a regular validation like this.
    Attachment 46479

    i don't want some messages popping up, like in you example : MessageBox.alert("Add Job", "Job name must be unique.", null);

  7. #6
    Sencha User
    Join Date
    May 2011
    Posts
    47
    Answers
    2
    Vote Rating
    0
    nmb1106 is on a distinguished road

      0  

    Default


    Stick the rpc call inside of a custom validator: (I'm not sure if this is the best way to do this, there has to be a better way but this would work)

    Code:
        private class UniqueNameValidator extends AbstractValidator<String> {
    
            @Override
            public List<EditorError> validate(final Editor<String> editor, final String value) {
                final List<EditorError> errors = new ArrayList<EditorError>();
                if (value != null) {
    
            CustomRPCFactory.getJobService(true).checkJobNameUnique(null, value, new CustomAsyncCallback<Boolean>() {
                @Override
                public void onSuccess(final Boolean result)
                {
                    if (!result)
                    {
                        errors = createError(editor, "Name must be unique", value);
                    }
                }
            });            
    
        return errors;
    
            }
    
        }
    Then you would just add an instance of this validator to your field.

  8. #7
    Sencha User
    Join Date
    Apr 2013
    Posts
    30
    Vote Rating
    0
    kozla13 is on a distinguished road

      0  

    Default


    is not workign that way:
    return errors; is always executed before the RPC call finished

  9. #8
    Sencha User
    Join Date
    May 2011
    Posts
    47
    Answers
    2
    Vote Rating
    0
    nmb1106 is on a distinguished road

      0  

    Default


    I thought you might say that, there really has to be a better way to do this but what you could do as a work around is have the call back of that rpc call another method that does something like this:

    Code:
        public TextField buildTextFieldWidget(boolean nameUnique) {
            if(nameUnique){
                 nameField.forceInvalid("Name must be unique");
           }
        }

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi