bgould / jmesa

Automatically exported from code.google.com/p/jmesa
0 stars 0 forks source link

worksheet validator problem #289

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi Jeff.

Im trying to set validation with tags this is the code i wrote on the jsp for a 
column.

<jmesa:htmlColumn property="value" 
                                          title="Valor"
                                          worksheetEditor="es.indra.transporte.central.configuration.scada.client.jmesa.cellEditor.ValueCellEditor"
                                          worksheetValidation="required:true" errorMessage="required:The value must be a number"/>

But when the jso is loaded from the controller with the parameters Bean a 
window alert me saying that the object doesn´t accept this property or method 
and the error method is this

jQuery.jmesa.setValidator('parametersTable', 
$(jQuery.jmesa.getFormByTableId('parametersTable')).validate({
        rules: {
            'value' : { required: true }
        },
        messages: {
            'value' : { required: 'The value must be a number' }
        },
        showErrors: function(errorMap, errorList) {
            jQuery.jmesa.setError('parametersTable', errorMap);
        },
        onsubmit: false,
        onfocusout: false,
        onkeyup: false,
        onclick: false
    }));

thanks!

Original issue reported on code.google.com by VictorRo...@gmail.com on 4 Oct 2010 at 2:48

GoogleCodeExporter commented 9 years ago
Hi jeff. could the problem be that i haven included the js of the 
bassistance.de page¿? if it is needed, which js do i need to include¿? thanks!

Original comment by VictorRo...@gmail.com on 5 Oct 2010 at 7:04

GoogleCodeExporter commented 9 years ago
Hi jeff, the previous problem dissapears, but know i have another problem. Y 
create cell editor like this.

package es.indra.transporte.central.configuration.scada.client.jmesa.cellEditor;

import org.jmesa.view.html.HtmlBuilder;
import org.jmesa.worksheet.WorksheetColumn;
import org.jmesa.worksheet.editor.AbstractWorksheetEditor;

public class ValueCellEditor extends AbstractWorksheetEditor
{

    public static final String CHECKED = "checked";
    public static final String UNCHECKED = "unchecked";

    @Override
    public Object getValue( Object item, String property, int rowcount )
    {
        Object changedValue = null;
        Object originalValue = null;
        WorksheetColumn worksheetColumn = getWorksheetColumn( item, property );
        if( worksheetColumn != null )
        {
            changedValue = worksheetColumn.getChangedValue();
            originalValue = worksheetColumn.getOriginalValue();

        }
        else
        {
            originalValue = getCellEditor().getValue( item, property, rowcount );
        }
        return getWsColumn( changedValue, originalValue, item, rowcount );

    }

    private String getWsColumn( Object changedValue, Object originalValue,
            Object item, int rowcount )
    {

        String ccsClass = "wsTextColumn";
        String disabled = "disabled";
        String value = String.valueOf( originalValue );
        String checkboxValue = getCheckboxVal( item, rowcount );

        if( changedValue != null )
        {
            if( originalValue.equals( changedValue ) )
            {
                if( checkboxValue.equals( CHECKED ) )
                {
                    disabled = "";
                    ccsClass = "wsTextColumnEnabled";
                }
                else
                {
                    disabled = "disabled";
                    ccsClass = "wsTextColumn";
                }
            }
            else
            {
                if( checkboxValue.equals( CHECKED ) )
                {
                    disabled = "";
                    ccsClass = "wsTextColumnChanged";
                    value = String.valueOf( changedValue );
                }
                else
                {
                    disabled = "disabled";
                    ccsClass = "wsTextColumn";
                    value = String.valueOf( changedValue );
                }
            }
        }
        else
        {
            if( checkboxValue.equals( CHECKED ) )
            {
                disabled = "";
                ccsClass = "wsTextColumnEnabled";
            }
            else
            {
                disabled = "disabled";
                ccsClass = "wsTextColumn";
            }
        }

        // String
        // component="<input type='text'  onmouseover=\"$.jmesa.setTitle(this.parentNode, event)\" onclick=\""+getUniquePropertyJavaScript(
        // item
        // )+"$.jmesa.createWsTextColumn(this, 'parametersTable',up,'value')\" id=\"value_"+rowcount+"\" value="+value+" style=\"width:96px\" class=\"wsTextColumn\" disabled/>";

        HtmlBuilder html = new HtmlBuilder();
        html.input().type( "text" );
        html.styleClass( ccsClass );
        if( disabled.equals( "disabled" ) )
        {
            html.disabled();
        }
        html.value( value );
        html.id( "value_" + rowcount );
        html.onmouseover( "$.jmesa.setTitle(this.parentNode, event)" );
        html.onclick( getUniquePropertyJavaScript( item )
                + "$.jmesa.createWsTextColumn(this, 'parametersTable',up,'value')" );

        return html.toString();
    }

    private String getCheckboxVal( Object item, int rowcount )
    {
        WorksheetColumn select = getWorksheetColumn( item, "chkbox" );
        if( select != null )
        {
            return select.getChangedValue();

        }
        else
        {
            return getCheckboxValue( getCellEditor().getValue( item,
                    "selected", rowcount ) );
        }
    }

    private String getCheckboxValue( Object value )
    {

        if( value == null )
        {
            return UNCHECKED;
        }

        String valueToConvert = String.valueOf( value );

        if( valueToConvert.equalsIgnoreCase( "y" )
                || valueToConvert.equalsIgnoreCase( "yes" )
                || valueToConvert.equalsIgnoreCase( "true" )
                || valueToConvert.equals( "1" ) )
        {
            return CHECKED;
        }

        if( valueToConvert.equalsIgnoreCase( "n" )
                || valueToConvert.equalsIgnoreCase( "no" )
                || valueToConvert.equalsIgnoreCase( "false" )
                || valueToConvert.equals( "0" ) )
        {
            return UNCHECKED;
        }

        throw new IllegalStateException(
                "Not able to convert the value for the checkbox." );
    }

And i use my own created javascript methods:

createWsTextColumn: function(column,id,uniqueProperties,property)
        {
            if(wsColumn)
            {
                return;
            }

            wsColumn = new classes.WsColumn(column, id, uniqueProperties, property);

            var cell = $(column);
            var width=cell.width();
            var originalValue=cell.val();

            cell.width(width);
            cell.parent().width(width);
            cell.css('overflow','visible');

            var input=$('#'+column.id);
            input.val(originalValue);
            if (jQuery.browser.msie) { /* IE need a second focus */
                input.focus();
            }

            //this.wsColumnKeyEvent(cell, input, originalValue);
            $('#'+column.id).blur(function(){
                $.jmesa.validateAndSubmitWsTextColumn(cell,input,originalValue,column.id);
            });
        }

validateAndSubmitWsTextColumn:function(cell,input,originalValue,id)
        {
            var changedValue=input.val();
            var validator = validatorObject[wsColumn.id];
            var hasRules;
            if (validator) {
                $.each(input.rules(), function() { hasRules = true; });
            }
            if (changedValue != originalValue) {
                if (hasRules) {
                    /* trigger validation */
                    validator.element($('#'+id));
                }
            }
            cell.val(changedValue);
            if (changedValue != originalValue) {
                if (!cell.attr('data-ov')) {
                   /* use custom attribute to store original value */
                   cell.attr('data-ov', originalValue);
                }
                $.jmesa.submitWsTextColumn(originalValue, changedValue, hasRules);
            }
            wsColumn = null;

        }

submitWsTextColumn: function(originalValue,changedValue,hasRules)
        {
            /* hasRules is optional parameter and will be true only if the column has validations */
            var data = '{ "id" : "' + wsColumn.id + '"';

            data += ', "cp_" : "' + wsColumn.property + '"';

            var props = wsColumn.uniqueProperties;
            $.each(props, function(key, value) {
                data += ', "up_' + key + '" : "' + value + '"';
            });

            data += ', "ov_" : "' + encodeURIComponent(originalValue) + '"';
            data += ', "cv_" : "' + encodeURIComponent(changedValue) + '"';

            var cell = $(wsColumn.column);
            var errorMessage;

            if (hasRules) {
               if (errorMap[wsColumn.id]) {
                  errorMessage = errorMap[wsColumn.id][wsColumn.property];
               }
            } else {
               errorMessage = cell.attr('data-em');
            }

            if (errorMessage) {
               data += ', "em_" : "' + encodeURIComponent(errorMessage) + '"';
            }

            data += '}'

            var contextPath = coreapi.getContextPath(wsColumn.id);
            if (contextPath) {
               contextPath += "/";
            }

            $.post(contextPath + 'jmesa.wrk?', eval('(' + data + ')'), function(columnStatus) {
                jQuery.jmesa.updateCssTextClass(columnStatus, cell, errorMessage);
             });
        }

updateCssTextClass:function(columnStatus,cell,errorMessage)
        {
            var classNames=
            {
                    "_rm_":'wsTextColumn',
                    "_uu_":'wsTextColumnChanged',
                    "_ue_":'wsTextColumnError'
            };
            if(cell.attr('class').indexOf('wsTextColumn')==0){

                cell.attr('class',classNames[columnStatus]);

                if('wsTextcolumn'==classNames[columnStatus]){
                    cell.removeAttr('data-ov');
                }

                if(errorMessage)
                {
                    cell.attr('data-em',errorMessage)
                }
                else
                {
                    cell.removeAttr('date-em');
                }
            }

        }

Mi jmesa column when i use the new celleditor is like this

<jmesa:htmlColumn property="value" 
                                          title="Valor"
                                          worksheetEditor="es.indra.transporte.central.configuration.scada.client.jmesa.cellEditor.ValueCellEditor"
                                          worksheetValidation="minlength:2" errorMessage="minlength:The value must be a number"/>

The problem is that when i use the worksheetvalidation with my own celleditor 
no validation rules are loaded in the validator on the javascript. Could you 
plesa help me or tell me when exactly is the validator loaded with the rules on 
the javascript

Thanks a lot for your help!

Original comment by VictorRo...@gmail.com on 5 Oct 2010 at 9:50

GoogleCodeExporter commented 9 years ago
What does it look like when you view the source of the table?

Technically the code is generated in the HtmlSnippets.getWorksheetValidation() 
method from HtmlSnippets.initJavascriptLimit(). You might want to attach the 
JMesa source and step through (with your debugger) to see what is going on.

Remember too that you can do sever side validation as well on save. I replied 
to your other post in which you can find more information about that.

Overall (except for this case) I would be interested to hear how the client 
side validation is working out. Do you think it works well, or is it difficult 
to use? 

Original comment by jeff.johnston.mn@gmail.com on 5 Oct 2010 at 5:19

GoogleCodeExporter commented 9 years ago
Hi jeff, i finally solved my problem, the client side works as good as the 
client side, eeach one is a good option, but i´m getting mad, how i told you 
i´m trying to do my own editors, but from the begining my issue is that i have 
a table wich have a column that is going to be editable but the disabled or 
enabled option of this column depends on the checkbox of the same row, if click 
the checkbox of the row the colum gets enable and if i deselect the checkbox 
the column turns into disabled. On the standard of the jmesa i´ve seen that 
and editable column is formed by a div with the information inside and then 
turns into a div with and input type text, but i can´t use this cause i can´t 
turn a div disabled.

Do you know any solution for the issue which i´m telling you, i can´t find a 
real good solution. I would like to use the standard jmesa javascript functions 
but adding this checkbox funcionality to the table

Thanks again for all your answers

Original comment by VictorRo...@gmail.com on 6 Oct 2010 at 2:40

GoogleCodeExporter commented 9 years ago
Not sure if this is still an issue...closing for now.

Original comment by jeff.johnston.mn@gmail.com on 10 Mar 2011 at 8:15