Package com.dodo.blog.ui.page

Examples of com.dodo.blog.ui.page.Page


        {
            // check authorization
            if ( !isAuthorized( pageClass ) )
            {
                Injector injector = RequestCycle.get().getInjector();
                Page page = injector.getInstance( WebApplication.get().getUnauthorizedPage() );
                response.getWriter().write( page.render() );

                return;
            }

            // handle ajax calls
            if ( AjaxListenerHelper.isAjax() )
            {
                String paramHandler = request.getParameter( IAjaxRequestHandler.PARAM_AJAX_HANDLER );
                if ( paramHandler != null )
                {
                    IAjaxRequestHandler handler = ( IAjaxRequestHandler ) Class.forName( paramHandler ).newInstance();
                    handler.handle();

                    return;
                }
            }

            // regular page calls
            Injector injector = RequestCycle.get().getInjector();
            Page page = ( Page ) injector.getInstance( pageClass );
            response.getWriter().write( page.render() );
        }
        catch ( Exception e )
        {
            processError( e, path, httpResponse );
        }
View Full Code Here


        HttpServletResponse httpResponse = RequestCycle.get().getResponse();

        String modelId = httpRequest.getParameter( AjaxListenerHelper.PARAM_MODEL_ID );
        if ( modelId != null )
        {
            Page page = RequestCycle.get().getInjector().getInstance( getPageClass() );

            // check model parameter
            String modelParameter = httpRequest.getParameter( AjaxListenerHelper.PARAM_METHOD_MODEL );
            if ( modelParameter == null )
            {
                log.severe( "Model parameter ['" + AjaxListenerHelper.PARAM_METHOD_MODEL + "'] must be set." );
                return;
            }

            // check json parameter
            String jsonParameter = httpRequest.getParameter( AjaxListenerHelper.PARAM_JSON );
            if ( jsonParameter == null )
            {
                log.severe( "Json parameter ['" + AjaxListenerHelper.PARAM_JSON + "'] must be set." );
                return;
            }

            // set model class form model parameter
            Class<?> modelClass = Class.forName( modelParameter );
            for ( Method method : page.getClass().getDeclaredMethods() )
            {
                SetModel setModelAnnotation = method.getAnnotation( SetModel.class );
                if ( setModelAnnotation != null && setModelAnnotation.name().equals( modelId ) )
                {
                    // parse json parameter into model object
                    Object model = getModelObject( page, modelId );
                    MAPPER.updatingReader( model ).readValue( jsonParameter );

                    try
                    {
                        Response response = ( Response ) method.invoke( page, model );
                        response.setMessages( RequestCycle.get().getMessages() );
                        response.setModel( model );
                        httpResponse.getWriter().write( MAPPER.writeValueAsString( response ) );
                    }
                    catch ( InvocationTargetException e )
                    {
                        throw ( Exception ) e.getCause();
                    }
                    return;
                }
            }

            log.severe( "No method with annotation " + SetModel.class.getName() + "(name = '" + modelId + "') found in class " + page.getClass().getName() );
        }
    }
View Full Code Here

        HttpServletResponse httpResponse = RequestCycle.get().getResponse();

        String paramMethod = httpRequest.getParameter( AjaxListenerHelper.PARAM_METHOD );
        if ( paramMethod != null )
        {
            Page page = RequestCycle.get().getInjector().getInstance( getPageClass() );
            for ( Method method : page.getClass().getDeclaredMethods() )
            {
                AjaxRequest ajaxRequestAnnotation = method.getAnnotation( AjaxRequest.class );
                if ( ajaxRequestAnnotation != null && ajaxRequestAnnotation.name().equals( paramMethod ) )
                {
                    try
                    {
                        Response response = ( Response ) method.invoke( page );
                        response.setMessages( RequestCycle.get().getMessages() );
                        httpResponse.getWriter().write( MAPPER.writeValueAsString( response ) );
                    }
                    catch ( InvocationTargetException e )
                    {
                        throw ( Exception ) e.getCause();
                    }
                    return;
                }
            }

            log.severe( "No method with annotation " + AjaxRequest.class.getName() + "(name = '" + paramMethod + "') found in class " + page.getClass().getName() );
        }
    }
View Full Code Here

        HttpServletResponse httpResponse = RequestCycle.get().getResponse();

        String modelId = httpRequest.getParameter( AjaxListenerHelper.PARAM_MODEL_ID );
        if ( modelId != null )
        {
            Page page = RequestCycle.get().getInjector().getInstance( getPageClass() );
            Object model = getModelObject( page, modelId );
            if ( model != null )
            {
                Response response = new Response();
                response.setMessages( RequestCycle.get().getMessages() );
                response.setModel( model );

                httpResponse.getWriter().write( MAPPER.writeValueAsString( response ) );

                return;
            }

            log.severe( "No method with annotation " + GetModel.class.getName() + "(name = '" + modelId + "') found in class " + page.getClass().getName() );
        }
    }
View Full Code Here

TOP

Related Classes of com.dodo.blog.ui.page.Page

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.