Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
License Agreement. Rich Faces - Natural Ajax for Java Server Faces (JSF) Copyright (C) 2007 Exadel, Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 package org.ajax4jsf.component;
 
 import  javax.faces.FacesException;
 import  javax.faces.component.UIComponentBase;
 import  javax.faces.component.UIParameter;
 import  javax.faces.context.FacesContext;
 import  javax.faces.convert.Converter;
 import  javax.faces.event.AbortProcessingException;
 import  javax.faces.event.ActionEvent;
 import  javax.faces.event.ActionListener;
 
 import  org.ajax4jsf.Messages;

Author(s):
shura (latest modification by $Author: alexsmirnov $)
Version:
$Revision: 1.1.2.2 $ $Date: 2007/02/01 15:31:55 $
 
 public class UIActionParameter extends UIParameter implements ActionListener, JavaScriptParameter {
     public static final String COMPONENT_TYPE = "org.ajax4jsf.components.UIActionParameter";
     private static String noEscapeAttr = "noEscape";

    
 
    
Action listener to call after binding has been updated
 
     private MethodExpression actionListener = null;
    
Binding for update on ActionEvent
 
     private ValueExpression assignToBinding = null;

    
 
    
Converter for update value with this parameter
 
     private Converter converter = null;

    
 
    
Skip quota escaping of parameter value - for substitute JavaScript exspression on submit
 
     private Boolean noEscape = null;
 
     public void setAssignToBinding(ValueExpression propertyBinding) {
         this. = propertyBinding;
     }
 
     public ValueExpression getAssignToBinding() {
         return ;
     }
 
     public MethodExpression getActionListener() {
         return ;
     }
 
     public void setActionListener(MethodExpression actionListener) {
         this. = actionListener;
     }
 
     public void setConverter(Converter converter) {
         this. = converter;
     }
 
     public Converter getConverter() {
         return ;
     }
 
     /*
      * (non-Javadoc)
      *
      * @see org.ajax4jsf.framework.ajax.JavaScriptParameter#setNoEscape(boolean)
      */
     public void setNoEscape(boolean noEscape) {
         this. = Boolean.valueOf(noEscape);
     }
    /*
     * (non-Javadoc)
     *
     * @see org.ajax4jsf.framework.ajax.JavaScriptParameter#isNoEscape()
     */
    public boolean isNoEscape() {
        return isValueOrBinding();
    }
    /*
     * (non-Javadoc)
     *
     * @see javax.faces.component.UIParameter#getName()
     */
    public String getName() {
        String name = super.getName();
        // If name not set - use clientId. be Careful !
        if (null == name) {
            name = getClientId(FacesContext.getCurrentInstance());
        }
        return name;
    }
    public Object getValue() {
        Object value = super.getValue();
        // TODO - perform conversion if converter is present.
        if (null != value) {
            Class<?> type = value.getClass();
            FacesContext context = getFacesContext();
            Converter converter = createConverter(contexttype);
            if (null != converter) {
                value = converter.getAsString(contextthisvalue);
            }
        }
        return value;
    }

    
    /*
     * (non-Javadoc)
     *
     * @see javax.faces.event.ActionListener#processAction(javax.faces.event.ActionEvent)
     */
    public void processAction(ActionEvent actionEventthrows AbortProcessingException {
        FacesContext context = getFacesContext();
        ELContext elContext = context.getELContext();
        ValueExpression updateBinding = getAssignToBinding();
        if (updateBinding != null && (!updateBinding.isReadOnly(elContext))) {
            Object requestValue = context.getExternalContext().getRequestParameterMap().get(getName());
            if (requestValue != null && requestValue instanceof String) {
                Class<?> type = updateBinding.getType(elContext);
                Converter converter = createConverter(contexttype);
                if (null != converter) {
                    requestValue = converter.getAsObject(contextthis, (StringrequestValue);
                }
            }
            if (null != requestValue) {
                updateBinding.setValue(elContextrequestValue);
            }
            MethodExpression listener = getActionListener();
            if (listener != null) {
                listener.invoke(elContextnew Object[] { actionEvent });
            }
        }
    }

    

Parameters:
context
type
Returns:
Throws:
FacesException
    private Converter createConverter(FacesContext contextClass<?> typethrows FacesException {
        Converter converter = getConverter();
        if (converter == null && type != null && !type.equals(String.class) && !type.equals(Object.class)) {
            try {
                converter = context.getApplication().createConverter(type);
            } catch (Exception e) {
                throw new FacesException(Messages.getMessage(Messages.NO_CONVERTER_REGISTERED, type.getName()), e);
            }
        }
        return converter;
    }
    /*
     * (non-Javadoc)
     *
     * @see javax.faces.component.UIComponentBase#restoreState(javax.faces.context.FacesContext)
     */
    @Override
    public void restoreState(FacesContext contextObject state) {
        Object[] values = (Object[]) state;
        super.restoreState(context, values[0]);
        // restore fields values
         = (ValueExpression) UIComponentBase.restoreAttachedState(contextvalues[1]);
         = (Booleanvalues[2];
         = (Converter) UIComponentBase.restoreAttachedState(contextvalues[3]);
         = (MethodExpression) UIComponentBase.restoreAttachedState(contextvalues[4]);
    }
    /*
     * (non-Javadoc)
     *
     * @see javax.faces.component.UIComponentBase#saveState(javax.faces.context.FacesContext)
     */
    @Override
    public Object saveState(FacesContext context) {
        Object[] values = new Object[5];
        values[0] = super.saveState(context);
        // save fields values
        values[1] = UIComponentBase.saveAttachedState(context);
        values[2] = ;
        values[3] = UIComponentBase.saveAttachedState(context);
        values[4] = UIComponentBase.saveAttachedState(context);
        return values;
    }

    

Parameters:
field - value of field to get.
name - name of field, to get from ValueBinding
Returns:
boolean value, based on field or valuebinding.
    private boolean isValueOrBinding(Boolean fieldString name) {
        if (null != field) {
            return field.booleanValue();
        }
        ValueExpression vb = getValueExpression(name);
        if (null != vb) {
            FacesContext context = getFacesContext();
            ELContext elContext = context.getELContext();
            return ((Booleanvb.getValue(elContext)).booleanValue();
        } else {
            return false;
        }
    }
New to GrepCode? Check out our FAQ X