[jboss-cvs] jboss-seam/ui/src/main/java/org/jboss/seam/ui/component ...
Peter Muir
peter at bleepbleep.org.uk
Fri Jun 15 13:06:57 EDT 2007
User: pmuir
Date: 07/06/15 13:06:57
Added: ui/src/main/java/org/jboss/seam/ui/component
README UIMessage.java UIEnumItem.java
UIFormattedText.java UISelectItems.java
UIValidateAll.java UISelection.java UILink.java
UIConversationPropagation.java UICache.java
UILoadStyle.java UISpan.java UIButton.java
UIAction.java UIConversationId.java UIFragment.java
UITaskId.java UIFileUpload.java UISelectDate.java
UIDecorate.java UISeamCommandBase.java UILabel.java
UIDiv.java
Log:
Refactor cdk port
Revision Changes Path
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/README
<<Binary file>>
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UIMessage.java
Index: UIMessage.java
===================================================================
/**
* License Agreement.
*
* Ajax4jsf 1.1 - 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.jboss.seam.ui.component;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlMessage;
/**
* JSF component class
*
*/
public abstract class UIMessage extends HtmlMessage {
/**
* A depth-first search for an EditableValueHolder
*/
protected static UIComponent getEditableValueHolder(UIComponent component)
{
if (component instanceof EditableValueHolder)
{
return component.isRendered() ? component : null;
}
for (Object child: component.getChildren())
{
if (child instanceof UIComponent)
{
UIComponent evh = getEditableValueHolder( (UIComponent) child );
if (evh!=null) return evh;
}
}
return null;
}
private static String getInputId(UIComponent cmp)
{
String forId = cmp instanceof UIDecorate ?
( (UIDecorate) cmp ).getFor() : null;
if (forId==null)
{
UIComponent evh = getEditableValueHolder(cmp);
return evh==null ? null : evh.getId();
}
else
{
return forId;
}
}
private static String getFor(UIComponent component)
{
if ( component.getParent()==null )
{
return null;
}
else if (component instanceof UIDecorate)
{
return getInputId(component);
}
else
{
return getFor( component.getParent() );
}
}
@Override
public String getFor()
{
return getFor(this);
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UIEnumItem.java
Index: UIEnumItem.java
===================================================================
package org.jboss.seam.ui.component;
import javax.faces.component.UISelectItem;
import javax.faces.model.SelectItem;
/**
* JSF component class
*
*/
public abstract class UIEnumItem extends UISelectItem
{
private static final String COMPONENT_TYPE = "org.jboss.seam.ui.EnumItem";
private static final String COMPONENT_FAMILY = "org.jboss.seam.ui.EnumItem";
public abstract String getEnumValue();
public abstract void setEnumValue(String enumValue);
public abstract void setLabel(String label);
public abstract String getLabel();
@Override
public Object getValue()
{
Class c = getParent().getValueExpression("value").getType(getFacesContext().getELContext());
String enumValue = getEnumValue();
String label = getLabel();
Object value = Enum.valueOf(c, enumValue);
return new SelectItem(value, label == null ? enumValue : label);
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UIFormattedText.java
Index: UIFormattedText.java
===================================================================
/**
* License Agreement.
*
* Ajax4jsf 1.1 - 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.jboss.seam.ui.component;
import java.io.Reader;
import java.io.StringReader;
import javax.faces.component.UIOutput;
import org.jboss.seam.text.SeamTextLexer;
import org.jboss.seam.text.SeamTextParser;
import antlr.ANTLRException;
/**
* JSF component class
*
*/
public abstract class UIFormattedText extends UIOutput {
@SuppressWarnings("unused")
private static final String COMPONENT_TYPE = "org.jboss.seam.ui.FormattedText";
@SuppressWarnings("unused")
private static final String COMPONENT_FAMILY = "org.jboss.seam.ui.FormattedText";
public String getFormattedText()
{
if ( getValue() == null) return null;
Reader r = new StringReader( (String) getValue() );
SeamTextLexer lexer = new SeamTextLexer(r);
SeamTextParser parser = new SeamTextParser(lexer);
try
{
parser.startRule();
}
catch (ANTLRException re)
{
throw new RuntimeException(re);
}
return parser.toString();
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UISelectItems.java
Index: UISelectItems.java
===================================================================
/**
* License Agreement.
*
* Ajax4jsf 1.1 - 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.jboss.seam.ui.component;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.component.ValueHolder;
import javax.faces.convert.Converter;
import javax.faces.model.DataModel;
import org.jboss.seam.framework.EntityQuery;
import org.jboss.seam.ui.converter.ConverterChain;
import org.jboss.seam.ui.converter.NoSelectionConverter;
/**
* JSF component class
*
*/
public abstract class UISelectItems extends javax.faces.component.UISelectItems {
private static final String COMPONENT_TYPE = "org.jboss.seam.ui.SelectItems";
private static final String COMPONENT_FAMILY = "org.jboss.seam.ui.SelectItems";
private Object value;
private class NullableSelectItem extends javax.faces.model.SelectItem
{
private Object value;
private NullableSelectItem(Object value, String label)
{
super.setLabel(label);
this.value = value;
}
@Override
public Object getValue()
{
return value;
}
}
private static final String NO_SELECTION_VALUE = null;
public abstract void setHideNoSelectionLabel(Boolean hideNoSelectionLabel);
public abstract Boolean getHideNoSelectionLabel();
public abstract String getNoSelectionLabel();
public abstract void setNoSelectionLabel(String noSelectionLabel);
public abstract String getVar();
public abstract void setVar(String var);
public abstract String getLabel();
public abstract void setLabel(String label);
public abstract Boolean getDisabled();
public abstract void setDisabled(Boolean disabled);
@Override
public Object getValue()
{
if (value == null)
{
Object originalValue = super.getValue();
if (originalValue instanceof Iterable)
{
value = asSelectItems((Iterable) originalValue);
}
else if (originalValue instanceof DataModel && ((DataModel) originalValue).getWrappedData() instanceof Iterable)
{
value = asSelectItems((Iterable) ((DataModel) originalValue).getWrappedData());
}
else if (originalValue instanceof EntityQuery)
{
value = asSelectItems(((EntityQuery) originalValue).getResultList());
}
else if (originalValue != null && originalValue.getClass().isArray())
{
if (originalValue.getClass().getComponentType().isPrimitive())
{
List list = new ArrayList();
for (int i = 0; i < Array.getLength(originalValue); i++)
{
list.add(Array.get(originalValue, i));
}
value = asSelectItems(list);
}
else
{
value = asSelectItems(Arrays.asList((Object[]) originalValue));
}
}
else
{
javax.faces.model.SelectItem noSelectionLabel = noSelectionLabel();
if (noSelectionLabel != null)
{
List<javax.faces.model.SelectItem> selectItems = new ArrayList<javax.faces.model.SelectItem>();
selectItems.add(noSelectionLabel);
value = selectItems;
}
else
{
value = originalValue;
}
}
}
return value;
}
private List<javax.faces.model.SelectItem> asSelectItems(Iterable iterable)
{
List<javax.faces.model.SelectItem> selectItems = new ArrayList<javax.faces.model.SelectItem>();
javax.faces.model.SelectItem noSelectionLabel = noSelectionLabel();
if (noSelectionLabel != null)
{
selectItems.add(noSelectionLabel);
}
for (Object o : iterable)
{
initVar(o);
selectItems.add(new javax.faces.model.SelectItem(o, getLabel(), "", getDisabled() == null ? false : getDisabled()));
destroyVar();
}
return selectItems;
}
private javax.faces.model.SelectItem noSelectionLabel()
{
boolean show = false;
/*
* This is a slight hack. If you do an EL expresison like this (to hide the label)
*
* noSelectionLabel="#{x eq y ? 'Please Select' : null}"
*
* then, if x != y, EL will return an empty String, not null, so we work around that, with the side effect
* that if the result of the EL expression is an empty String, then the label will be hidden.
*/
ValueExpression vb = getValueExpression("noSelectionLabel");
if (vb == null && !(getHideNoSelectionLabel() && getParentValue() != null))
{
/*
* Here, the user has specfied a noSelectionLabel (may be an empty string), and, if hideNoSelectionLabel
* is set, then, if a value is selected, then the label is hidden
*/
show = true;
}
else if (getNoSelectionLabel() != null && !"".equals(getNoSelectionLabel()) && !(getHideNoSelectionLabel() && getParentValue() != null))
{
/*
* Here, the user has used an EL expression as the noSelectionLabel. In this case, an empty string is
* indicates that the label should be hidden.
*/
show = true;
}
if (show)
{
NullableSelectItem s = new NullableSelectItem(NO_SELECTION_VALUE, getNoSelectionLabel());
ConverterChain converterChain = new ConverterChain(this.getParent());
Converter noSelectionConverter = new NoSelectionConverter();
// Make sure that the converter is only added once
if (!converterChain.containsConverterType(noSelectionConverter)) {
converterChain.addConverterToChain(noSelectionConverter, ConverterChain.CHAIN_START);
}
return s;
}
else
{
return null;
}
}
@SuppressWarnings("unchecked")
private void initVar(Object varValue)
{
if (getVar() == null)
{
throw new FacesException("var attribute must be set");
}
getFacesContext().getExternalContext().getRequestMap().put(getVar(), varValue);
}
private void destroyVar()
{
getFacesContext().getExternalContext().getRequestMap().remove(getVar());
}
private Object getParentValue()
{
if (getParent() instanceof ValueHolder)
{
ValueHolder parent = (ValueHolder) getParent();
return parent.getValue();
}
else
{
return null;
}
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UIValidateAll.java
Index: UIValidateAll.java
===================================================================
package org.jboss.seam.ui.component;
import javax.faces.component.UIComponentBase;
/**
* JSF component class
*
*/
public abstract class UIValidateAll extends UIComponentBase
{
private static final String COMPONENT_TYPE = "org.jboss.seam.ui.ValidateAll";
private static final String COMPONENT_FAMILY = "org.jboss.seam.ui.ValidateAll";
private boolean validatorsAdded = false;
@Override
public boolean getRendersChildren()
{
return true;
}
public boolean isValidatorsAdded()
{
return validatorsAdded;
}
public void setValidatorsAdded(boolean validatorsAdded)
{
this.validatorsAdded = validatorsAdded;
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UISelection.java
Index: UISelection.java
===================================================================
/**
* License Agreement.
*
* Ajax4jsf 1.1 - 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.jboss.seam.ui.component;
import javax.faces.component.UIParameter;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import org.jboss.seam.contexts.Contexts;
/**
* JSF component class
*
*/
public abstract class UISelection extends UIParameter {
private static final String COMPONENT_TYPE = "org.jboss.seam.ui.Selection";
private static final String COMPONENT_FAMILY = "org.jboss.seam.ui.Selection";
@Override
public String getName()
{
return "dataModelSelection";
}
@Override
public Object getValue()
{
Object value = Contexts.lookupInStatefulContexts(getDataModel());
if (value==null)
{
return null;
}
else
{
int rowIndex = ( (DataModel) value ).getRowIndex();
return rowIndex<0 ? null : getVar() + ':' + getDataModel() + '[' + rowIndex + ']';
}
}
public abstract String getDataModel();
public abstract void setDataModel(String dataModel);
public abstract String getVar();
public abstract void setVar(String var);
public static UISelection newInstance() {
return (UISelection) FacesContext.getCurrentInstance().getApplication().createComponent(COMPONENT_TYPE);
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UILink.java
Index: UILink.java
===================================================================
/**
* License Agreement.
*
* Ajax4jsf 1.1 - 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.jboss.seam.ui.component;
/**
* JSF component class
*
*/
public abstract class UILink extends UISeamCommandBase {
private static final String COMPONENT_TYPE = "org.jboss.seam.ui.Link";
private static final String COMPONENT_FAMILY = "org.jboss.seam.ui.Link";
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UIConversationPropagation.java
Index: UIConversationPropagation.java
===================================================================
/**
* License Agreement.
*
* Ajax4jsf 1.1 - 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.jboss.seam.ui.component;
import javax.faces.component.UIParameter;
import javax.faces.context.FacesContext;
/**
* JSF component class
*
*/
public abstract class UIConversationPropagation extends UIParameter {
private static final String COMPONENT_TYPE = "org.jboss.seam.ui.ConversationPropagation";
private static final String COMPONENT_FAMILY = "org.jboss.seam.ui.ConversationPropagation";
@Override
public String getName()
{
return "conversationPropagation";
}
@Override
public Object getValue()
{
return getPageflow()==null ? getType() : getType() + "." + getPageflow();
}
public abstract String getPageflow();
public abstract void setPageflow(String pageflow);
public abstract String getType();
public abstract void setType(String type);
public static UIConversationPropagation newInstance() {
return (UIConversationPropagation) FacesContext.getCurrentInstance().getApplication().createComponent(COMPONENT_TYPE);
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UICache.java
Index: UICache.java
===================================================================
/**
* License Agreement.
*
* Ajax4jsf 1.1 - 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.jboss.seam.ui.component;
import javax.faces.component.UIComponentBase;
/**
* JSF component class
*
*/
public abstract class UICache extends UIComponentBase
{
private static final String COMPONENT_TYPE = "org.jboss.seam.ui.Cache";
private static final String COMPONENT_FAMILY = "org.jboss.seam.ui.Cache";
@Override
public String getFamily()
{
return COMPONENT_FAMILY;
}
public abstract boolean isEnabled();
public abstract void setEnabled(boolean enabled);
public abstract String getKey();
public abstract void setKey(String key);
public abstract String getRegion();
public abstract void setRegion(String region);
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UILoadStyle.java
Index: UILoadStyle.java
===================================================================
package org.jboss.seam.ui.component;
import java.io.UnsupportedEncodingException;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.component.UIParameter;
import org.ajax4jsf.ajax.html.HtmlLoadStyle;
import org.jboss.seam.core.Pages;
import org.jboss.seam.ui.resource.StyleResource;
import org.jboss.seam.ui.util.UrlBuilder;
public abstract class UILoadStyle extends HtmlLoadStyle
{
@Override
public Object getSrc()
{
UIConversationId uiConversationId = UIConversationId.newInstance();
uiConversationId.setViewId(Pages.getViewId(getFacesContext()));
try
{
UrlBuilder urlBuilder = new UrlBuilder(StyleResource.WEB_RESOURCE_PATH + super.getSrc());
urlBuilder.addParameter(uiConversationId);
if (isIsolated())
{
UIComponent namingContainer = getParentNamingContainer(this);
if (namingContainer != null)
{
UIParameter idPrefix = new UIParameter();
idPrefix.setName("idPrefix");
urlBuilder.addParameter("idPrefix", namingContainer.getClientId(getFacesContext()));
}
}
return urlBuilder.getEncodedUrl();
}
catch (UnsupportedEncodingException e)
{
throw new RuntimeException(e);
}
}
public abstract boolean isIsolated();
public abstract void setIsolated(boolean isolated);
private UIComponent getParentNamingContainer(UIComponent cmp)
{
if (cmp == null)
{
return null;
}
else if (cmp instanceof NamingContainer)
{
return cmp;
}
else
{
return getParentNamingContainer(cmp.getParent());
}
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UISpan.java
Index: UISpan.java
===================================================================
/**
* License Agreement.
*
* Ajax4jsf 1.1 - 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.jboss.seam.ui.component;
import javax.faces.component.UIComponentBase;
/**
* JSF component class
*
*/
public abstract class UISpan extends UIComponentBase {
private static final String COMPONENT_TYPE = "org.jboss.seam.ui.Span";
private static final String COMPONENT_FAMILY = "org.jboss.seam.ui.Span";
@Override
public boolean getRendersChildren()
{
return true;
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UIButton.java
Index: UIButton.java
===================================================================
/**
* License Agreement.
*
* Ajax4jsf 1.1 - 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.jboss.seam.ui.component;
/**
* JSF component class
*
*/
public abstract class UIButton extends UISeamCommandBase {
private static final String COMPONENT_TYPE = "org.jboss.seam.ui.Button";
private static final String COMPONENT_FAMILY = "org.jboss.seam.ui.Button";
public abstract String getImage();
public abstract void setImage(String image);
public String getType()
{
if (getImage() == null) {
return "button";
} else {
return "image";
}
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UIAction.java
Index: UIAction.java
===================================================================
/**
* License Agreement.
*
* Ajax4jsf 1.1 - 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.jboss.seam.ui.component;
import javax.faces.component.UIParameter;
import javax.faces.context.FacesContext;
import org.jboss.seam.core.Pages;
import org.jboss.seam.core.SafeActions;
/*
* This is a support component and is not processed by the CDK (doesn't appear in faces-config)
*
*/
public class UIAction extends UIParameter {
private static final String COMPONENT_FAMILY = "org.jboss.seam.ui.Action";
@Override
public String getFamily()
{
return COMPONENT_FAMILY;
}
private String action;
public String getAction()
{
return action;
}
public void setAction(String action)
{
this.action = action;
}
private boolean isMethodBinding()
{
return getAction().startsWith("#{");
}
@Override
public String getName()
{
return isMethodBinding() ? "actionMethod" : "actionOutcome";
}
@Override
public Object getValue()
{
String viewId = Pages.getCurrentViewId();
if ( isMethodBinding() )
{
String actionId = SafeActions.toActionId( viewId, getAction() );
SafeActions.instance().addSafeAction(actionId);
return actionId;
}
else
{
return getAction();
}
}
@Override
public void restoreState(FacesContext context, Object state) {
Object[] values = (Object[]) state;
super.restoreState(context, values[0]);
action = (String) values[1];
}
@Override
public Object saveState(FacesContext context) {
Object[] values = new Object[2];
values[0] = super.saveState(context);
values[1] = action;
return values;
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UIConversationId.java
Index: UIConversationId.java
===================================================================
/**
* License Agreement.
*
* Ajax4jsf 1.1 - 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.jboss.seam.ui.component;
import javax.faces.component.UIParameter;
import javax.faces.context.FacesContext;
import org.jboss.seam.core.Conversation;
import org.jboss.seam.core.Manager;
import org.jboss.seam.core.Pages;
import org.jboss.seam.pages.Page;
/**
* JSF component class
*
*/
public abstract class UIConversationId extends UIParameter {
private static final String COMPONENT_TYPE = "org.jboss.seam.ui.ConversationId";
private static final String COMPONENT_FAMILY = "org.jboss.seam.ui.ConversationId";
@Override
public String getName()
{
Conversation conversation = Conversation.instance();
if (getViewId()!=null && ( !conversation.isNested() || conversation.isLongRunning() ) )
{
return Pages.instance().getPage(getViewId())
.getConversationIdParameter()
.getParameterName();
}
else
{
return Manager.instance().getConversationIdParameter();
}
}
@Override
public Object getValue()
{
Conversation conversation = Conversation.instance();
if ( !conversation.isNested() || conversation.isLongRunning() )
{
if (getViewId()!=null)
{
Page page = Pages.instance().getPage(getViewId());
return page.getConversationIdParameter().getParameterValue();
}
else
{
return conversation.getId();
}
}
else
{
return conversation.getParentId();
}
}
public abstract String getViewId();;
public abstract void setViewId(String viewId);
public static UIConversationId newInstance() {
return (UIConversationId) FacesContext.getCurrentInstance().getApplication().createComponent(COMPONENT_TYPE);
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UIFragment.java
Index: UIFragment.java
===================================================================
/**
* License Agreement.
*
* Ajax4jsf 1.1 - 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.jboss.seam.ui.component;
import javax.faces.component.UIComponentBase;
/**
* JSF component class
*
*/
public abstract class UIFragment extends UIComponentBase {
@SuppressWarnings("unused")
private static final String COMPONENT_TYPE = "org.jboss.seam.ui.Fragment";
@SuppressWarnings("unused")
private static final String COMPONENT_FAMILY = "org.jboss.seam.ui.Fragment";
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UITaskId.java
Index: UITaskId.java
===================================================================
/**
* License Agreement.
*
* Ajax4jsf 1.1 - 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.jboss.seam.ui.component;
import javax.el.ValueExpression;
import javax.faces.component.UIParameter;
import javax.faces.context.FacesContext;
import org.jbpm.taskmgmt.exe.TaskInstance;
/**
* JSF component class
*
*/
public abstract class UITaskId extends UIParameter {
private static final String COMPONENT_TYPE = "org.jboss.seam.ui.TaskId";
private static final String COMPONENT_FAMILY = "org.jboss.seam.ui.TaskId";
@Override
public String getName()
{
return "taskId";
}
@Override
public Object getValue()
{
ValueExpression valueExpression = getValueExpression("taskInstance");
if (valueExpression==null) valueExpression = getFacesContext().getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(), "#{task}", TaskInstance.class);
TaskInstance taskInstance = (TaskInstance) valueExpression.getValue( getFacesContext().getELContext() );
return taskInstance==null ? null : taskInstance.getId();
}
public static UITaskId newInstance() {
return (UITaskId) FacesContext.getCurrentInstance().getApplication().createComponent(COMPONENT_TYPE);
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UIFileUpload.java
Index: UIFileUpload.java
===================================================================
package org.jboss.seam.ui.component;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.el.ValueExpression;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
/**
* JSF component class
*
*/
public abstract class UIFileUpload extends UIInput
{
private String localContentType;
private String localFileName;
private int localFileSize;
private InputStream localInputStream;
private static final String COMPONENT_TYPE = "org.jboss.seam.ui.FileUpload";
private static final String COMPONENT_FAMILY = "org.jboss.seam.ui.FileUpload";
@Override
public void processUpdates(FacesContext context)
{
ValueExpression dataBinding = getValueExpression("data");
if (dataBinding != null)
{
Class cls = dataBinding.getType(context.getELContext());
if (cls.isAssignableFrom(InputStream.class))
{
dataBinding.setValue(context.getELContext(), localInputStream);
}
else if (cls.isAssignableFrom(byte[].class))
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try
{
while (localInputStream.available() > 0)
{
bos.write(localInputStream.read());
dataBinding.setValue(context.getELContext(), bos.toByteArray());
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
ValueExpression vb = getValueExpression("contentType");
if (vb != null) vb.setValue(context.getELContext(), localContentType);
vb = getValueExpression("fileName");
if (vb != null) vb.setValue(context.getELContext(), localFileName);
vb = getValueExpression("fileSize");
if (vb != null) vb.setValue(context.getELContext(), localFileSize);
}
}
public String getLocalContentType()
{
return localContentType;
}
public void setLocalContentType(String localContentType)
{
this.localContentType = localContentType;
}
public String getLocalFileName()
{
return localFileName;
}
public void setLocalFileName(String localFileName)
{
this.localFileName = localFileName;
}
public int getLocalFileSize()
{
return localFileSize;
}
public void setLocalFileSize(int localFileSize)
{
this.localFileSize = localFileSize;
}
public InputStream getLocalInputStream()
{
return localInputStream;
}
public void setLocalInputStream(InputStream localInputStream)
{
this.localInputStream = localInputStream;
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UISelectDate.java
Index: UISelectDate.java
===================================================================
package org.jboss.seam.ui.component;
import javax.faces.component.UIComponentBase;
public abstract class UISelectDate extends UIComponentBase
{
public static final String COMPONENT_TYPE = "org.jboss.seam.ui.UISelectDate";
public static final String COMPONENT_FAMILY = "org.jboss.seam.ui.SelectDate";
public abstract String getDateFormat();
public abstract void setDateFormat(String dateFormat);
public abstract String getFor();
public abstract void setFor(String forField);
public abstract int getStartYear();
public abstract void setStartYear(int startYear);
public abstract int getEndYear();
public abstract void setEndYear(int endYear);
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UIDecorate.java
Index: UIDecorate.java
===================================================================
package org.jboss.seam.ui.component;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import org.jboss.seam.ui.util.Decoration;
public abstract class UIDecorate extends UIComponentBase
{
public static final String COMPONENT_TYPE = "org.jboss.seam.ui.UIDecorate";
public static final String COMPONENT_FAMILY = "org.jboss.seam.ui.Decorate";
public boolean hasMessage()
{
String clientId = getInputClientId();
if (clientId==null)
{
return false;
}
else
{
return getFacesContext().getMessages(clientId).hasNext();
}
}
public String getInputId()
{
String id = getFor();
if (id==null)
{
UIComponent evh = Decoration.getEditableValueHolder(this);
return evh==null ? null : evh.getId();
}
else
{
return id;
}
}
private String getInputClientId()
{
String id = getFor();
if (id==null)
{
UIComponent evh = Decoration.getEditableValueHolder(this);
return evh==null ? null : evh.getClientId( getFacesContext() );
}
else
{
UIComponent component = findComponent(id);
return component==null ? null : component.getClientId( getFacesContext() );
}
}
@Override
public boolean getRendersChildren()
{
return true;
}
public abstract String getFor();
public abstract void setFor(String forId);
public UIComponent getDecoration(String name)
{
return Decoration.getDecoration(name, this);
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UISeamCommandBase.java
Index: UISeamCommandBase.java
===================================================================
package org.jboss.seam.ui.component;
import java.io.UnsupportedEncodingException;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.el.ValueExpression;
import javax.faces.component.ActionSource2;
import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.component.UIOutput;
import javax.faces.component.UIParameter;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionListener;
import javax.faces.model.DataModel;
import org.jboss.seam.core.Pages;
import org.jboss.seam.ui.util.ViewUrlBuilder;
public abstract class UISeamCommandBase extends UIOutput implements ActionSource2
{
private String encodedUrl;
public abstract boolean isDisabled();
public abstract void setDisabled(boolean disabled);
public abstract String getView();
public String getUrl() throws UnsupportedEncodingException
{
if (encodedUrl == null)
{
FacesContext context = getFacesContext();
String viewId = getView();
if (viewId == null)
{
viewId = Pages.getViewId(getFacesContext());
}
ViewUrlBuilder url = new ViewUrlBuilder(viewId, getFragment());
Set<String> usedParameters = new HashSet<String>();
for (Object child : getChildren())
{
if (child instanceof UIParameter)
{
usedParameters.add(((UIParameter) child).getName());
url.addParameter((UIParameter) child);
}
}
if (viewId != null)
{
Map<String, Object> pageParameters = Pages.instance().getConvertedParameters(context,
viewId, usedParameters);
for (Map.Entry<String, Object> me : pageParameters.entrySet())
{
UIParameter uip = new UIParameter();
uip.setName(me.getKey());
uip.setValue(me.getValue());
url.addParameter(uip);
}
}
if (getActionExpression() != null || getOutcome() != null)
{
UIAction uiAction = new UIAction();
uiAction.setAction(getActionExpression() == null ? getOutcome() : getActionExpression()
.getExpressionString());
url.addParameter(uiAction);
}
if ("default".equals(getPropagation()) || "join".equals(getPropagation())
|| "nest".equals(getPropagation()) || "end".equals(getPropagation()))
{
UIConversationId uiConversationId = UIConversationId.newInstance();
uiConversationId.setViewId(viewId);
url.addParameter(uiConversationId);
}
if ("join".equals(getPropagation()) || "nest".equals(getPropagation())
|| "begin".equals(getPropagation()) || "end".equals(getPropagation()))
{
UIConversationPropagation uiPropagation = UIConversationPropagation.newInstance();
uiPropagation.setType(getPropagation());
uiPropagation.setPageflow(getPageflow());
url.addParameter(uiPropagation);
}
ValueExpression taskInstanceValueExpression = getValueExpression("taskInstance");
if (taskInstanceValueExpression != null)
{
UITaskId uiTaskId = UITaskId.newInstance();
uiTaskId.setValueExpression("taskInstance", taskInstanceValueExpression);
url.addParameter(uiTaskId);
}
UISelection uiSelection = getSelection();
if (uiSelection != null)
{
url.addParameter(uiSelection);
}
encodedUrl = url.getEncodedUrl();
}
return encodedUrl;
}
public abstract void setView(String view);
public abstract String getOutcome();
public abstract void setOutcome(String outcome);
public abstract String getPropagation();
public abstract void setPropagation(String propagtion);
public abstract String getPageflow();
public abstract void setPageflow(String pageflow);
public abstract String getFragment();
public abstract void setFragment(String fragment);
public abstract String getOnclick();
public abstract void setOnclick(String onclick);
public UISelection getSelection()
{
UIData parentUIData = getParentUIData();
if (parentUIData != null)
{
if (parentUIData.getValue() instanceof DataModel)
{
String dataModelExpression = parentUIData.getValueExpression("value")
.getExpressionString();
String dataModelName = dataModelExpression.substring(2,
dataModelExpression.length() - 1).replace('$', '.');
UISelection uiSelection = UISelection.newInstance();
uiSelection.setDataModel(dataModelName);
uiSelection.setVar(parentUIData.getVar());
return uiSelection;
}
else
{
return null;
}
}
else
{
return null;
}
}
public UIData getParentUIData()
{
UIComponent parent = this.getParent();
while (parent != null)
{
if (parent instanceof UIData)
{
return (UIData) parent;
}
else
{
parent = parent.getParent();
}
}
return null;
}
public void removeActionListener(ActionListener listener)
{
// TODO Auto-generated method stub
}
public ActionListener[] getActionListeners()
{
// TODO Auto-generated method stub
return null;
}
public void addActionListener(ActionListener listener)
{
// TODO Auto-generated method stub
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UILabel.java
Index: UILabel.java
===================================================================
package org.jboss.seam.ui.component;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlOutputLabel;
public abstract class UILabel extends HtmlOutputLabel
{
/**
* A depth-first search for an EditableValueHolder
*/
protected static UIComponent getEditableValueHolder(UIComponent component)
{
if (component instanceof EditableValueHolder)
{
return component.isRendered() ? component : null;
}
for (Object child: component.getChildren())
{
if (child instanceof UIComponent)
{
UIComponent evh = getEditableValueHolder( (UIComponent) child );
if (evh!=null) return evh;
}
}
return null;
}
private static String getInputId(UIComponent cmp)
{
String forId = cmp instanceof UIDecorate ?
( (UIDecorate) cmp ).getFor() : null;
if (forId==null)
{
UIComponent evh = getEditableValueHolder(cmp);
return evh==null ? null : evh.getId();
}
else
{
return forId;
}
}
private static String getFor(UIComponent component)
{
if ( component.getParent()==null )
{
return null;
}
else if (component instanceof UIDecorate)
{
return getInputId(component);
}
else
{
return getFor( component.getParent() );
}
}
@Override
public String getFor()
{
return getFor(this);
}
}
1.1 date: 2007/06/15 17:06:57; author: pmuir; state: Exp;jboss-seam/ui/src/main/java/org/jboss/seam/ui/component/UIDiv.java
Index: UIDiv.java
===================================================================
/**
* License Agreement.
*
* Ajax4jsf 1.1 - 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.jboss.seam.ui.component;
import javax.faces.component.UIComponentBase;
/**
* JSF component class
*
*/
public abstract class UIDiv extends UIComponentBase {
private static final String COMPONENT_TYPE = "org.jboss.seam.ui.Div";
private static final String COMPONENT_FAMILY = "org.jboss.seam.ui.Div";
@Override
public boolean getRendersChildren()
{
return true;
}
}
More information about the jboss-cvs-commits
mailing list