You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by ma...@apache.org on 2007/03/29 07:51:08 UTC
svn commit: r523607 [4/14] - in /incubator/adffaces/trunk/trinidad:
trinidad-assembly/ trinidad-assembly/src/ trinidad-assembly/src/main/
trinidad-assembly/src/main/assembly/ trinidad-assembly/src/main/resources/
trinidad-examples/ trinidad-examples/bl...
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/SelectItemTestBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/SelectItemTestBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/SelectItemTestBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/SelectItemTestBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo;
+
+import javax.faces.model.SelectItem;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class SelectItemTestBean
+{
+ public SelectItemTestBean()
+ {
+ _oneItem = new SelectItem("foo", "Foo", "Description of foo", false);
+
+ _itemList = new ArrayList<SelectItem>();
+ _itemList.add(new SelectItem("foo", "Foo", "Description of foo", false));
+ _itemList.add(new SelectItem("bar", "Bar", "Description of bar", false));
+ _itemList.add(new SelectItem("baz", "Baz", "Description of baz", false));
+
+ _itemArray = new SelectItem[3];
+ _itemArray[0] = new SelectItem("foo", "Foo", "Description of foo", false);
+ _itemArray[1] = new SelectItem("bar", "Bar", "Description of bar", false);
+ _itemArray[2] = new SelectItem("baz", "Baz", "Description of baz", false);
+
+ _itemMap = new HashMap<String, String>();
+ _itemMap.put("Foo", "foo");
+ _itemMap.put("Bar", "bar");
+ _itemMap.put("Baz", "baz");
+ }
+
+ public SelectItem getOneItem()
+ {
+ return _oneItem;
+ }
+
+ public ArrayList<SelectItem> getItemList()
+ {
+ return _itemList;
+ }
+
+ public HashMap<String, String> getItemMap()
+ {
+ return _itemMap;
+ }
+
+ public SelectItem[] getItemArray()
+ {
+ return _itemArray;
+ }
+
+ private SelectItem _oneItem;
+ private ArrayList<SelectItem> _itemList;
+ private HashMap<String, String> _itemMap;
+ private SelectItem[] _itemArray;
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/SelectItemTestBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/SelectItemTestBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TableBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TableBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TableBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TableBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.event.ActionEvent;
+
+import org.apache.myfaces.trinidad.component.UIXCollection;
+import org.apache.myfaces.trinidad.component.UIXTree;
+import org.apache.myfaces.trinidad.component.UIXTable;
+import org.apache.myfaces.trinidad.model.RowKeySet;
+
+public class TableBean
+{
+ @SuppressWarnings("unchecked")
+ public TableBean()
+ {
+ _selection = Collections.EMPTY_LIST;
+ }
+
+ public UIComponent getTable()
+ {
+ return _table;
+ }
+
+ public void setTable(UIComponent hgrid)
+ {
+ _table = hgrid;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void performReport(ActionEvent action)
+ {
+ UIXCollection table = (UIXCollection) _table;
+ final RowKeySet state;
+ if (table instanceof UIXTable)
+ state = ((UIXTable) table).getSelectedRowKeys();
+ else
+ state = ((UIXTree) table).getSelectedRowKeys();
+ Iterator<Object> selection = state.iterator();
+ Object oldKey = table.getRowKey();
+ _selection = new ArrayList<Object>();
+ while (selection.hasNext())
+ {
+ table.setRowKey(selection.next());
+ _selection.add(table.getRowData());
+ }
+ table.setRowKey(oldKey);
+ FacesContext context = FacesContext.getCurrentInstance();
+ FacesMessage message =
+ new FacesMessage("Report Performed","Report was performed on "+
+ _selection.size()+" records");
+ context.addMessage(null, message);
+ }
+
+ public List<Object> getReportItems()
+ {
+ return _selection;
+ }
+
+ private UIComponent _table = null;
+ private List<Object> _selection;
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TableBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TableBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ToggleBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ToggleBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ToggleBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ToggleBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo;
+
+import org.apache.myfaces.trinidad.event.DisclosureEvent;
+
+public class ToggleBean implements java.io.Serializable
+{
+ public void onDisclosure(DisclosureEvent event)
+ {
+ _totalCount++;
+ }
+
+ public int getTotalCount()
+ {
+ return _totalCount;
+ }
+
+ private int _totalCount;
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ToggleBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ToggleBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeModelAdapter.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeModelAdapter.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeModelAdapter.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeModelAdapter.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo;
+
+import java.beans.IntrospectionException;
+import java.util.List;
+import org.apache.myfaces.trinidad.model.ChildPropertyTreeModel;
+import org.apache.myfaces.trinidad.model.TreeModel;
+
+/**
+ * This class facilitates the construction of a ChildPropertyTreeModel instance
+ * via managed-beans. ChildPropertyTreeModel does not have a no-arg constructor.
+ * This class does, and so can be instantiated as a managed-bean.
+ * Two properties need to be set: "childProperty" and "instance"
+ */
+public class TreeModelAdapter implements java.io.Serializable
+{
+ public TreeModelAdapter()
+ {
+ }
+
+ private String _propertyName = null;
+ private Object _instance = null;
+ private transient TreeModel _model = null;
+
+ public TreeModel getModel() throws IntrospectionException
+ {
+ if (_model == null)
+ {
+ _model = new ChildPropertyTreeModel(getInstance(), getChildProperty());
+ }
+ return _model;
+ }
+
+ public String getChildProperty()
+ {
+ return _propertyName;
+ }
+
+ /**
+ * Sets the property to use to get at child lists
+ * @param propertyName
+ */
+ public void setChildProperty(String propertyName)
+ {
+ _propertyName = propertyName;
+ _model = null;
+ }
+
+ public Object getInstance()
+ {
+ return _instance;
+ }
+
+ /**
+ * Sets the root list for this tree.
+ * @param instance must be something that can be converted into a List
+ */
+ public void setInstance(Object instance)
+ {
+ _instance = instance;
+ _model = null;
+ }
+
+ /**
+ * Sets the root list for this tree.
+ * This is needed for passing a List when using the managed bean list
+ * creation facility, which requires the parameter type is List.
+ * @param instance the list of root nodes
+ */
+ public void setListInstance(List<Object> instance)
+ {
+ setInstance(instance);
+ }
+
+ /**
+ * This should only be called if setListInstance was called.
+ *
+ * This method shouldn't be needed according to
+ * faces spec 1.1 rev 1, see 5.3.1.3
+ * However without this we get the following error in websphere:
+ * java.beans.IntrospectionException: No method
+ * "getListInstance" with 0 arg(s) of
+ * matching types in websphere
+ */
+ @SuppressWarnings("unchecked")
+ public List<Object> getListInstance()
+ {
+ return (List<Object>)getInstance();
+ }
+
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeModelAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeModelAdapter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeNodeImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeNodeImpl.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeNodeImpl.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeNodeImpl.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * A basic implementation of TreeNode that exposes the extra magic
+ * keys that will be requested by the tree renderer.
+ * <p>
+ * @version $Name: $ ($Revision$) $Date$
+ * @author Adam Winer
+ */
+public class TreeNodeImpl implements Serializable
+{
+ public String getText()
+ {
+ return _text;
+ }
+
+ public void setText(String text)
+ {
+ _text = text;
+ }
+
+
+ public String getIcon()
+ {
+ return _icon;
+ }
+
+ public void setIcon(String icon)
+ {
+ _icon = icon;
+ }
+
+ public String getDestination()
+ {
+ return _destination;
+ }
+
+
+ public void setDestination(String destination)
+ {
+ _destination = destination;
+ }
+
+ public void setChildren(List<TreeNodeImpl> nodes)
+ {
+ // Clone on the way in.
+ _nodes = new ArrayList<TreeNodeImpl>(nodes);
+ }
+
+ public List<TreeNodeImpl> getChildren()
+ {
+ if (_nodes == null)
+ return null;
+
+ return Collections.unmodifiableList(_nodes);
+ }
+
+
+ private String _text = null;
+ private String _destination = null;
+ private String _icon = null;
+ private List<TreeNodeImpl> _nodes;
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeNodeImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeNodeImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.faces.event.ValueChangeEvent;
+
+import org.apache.myfaces.trinidad.component.core.layout.CorePanelPage;
+
+import org.apache.myfaces.trinidad.model.UploadedFile;
+
+public class UIBean
+{
+ public UIBean()
+ {
+ }
+
+ public CorePanelPage getPanelPage()
+ {
+ return _panelPage;
+ }
+
+ public UIBeanState getState()
+ {
+ return _state;
+ }
+
+ public void setState(UIBeanState state)
+ {
+ _state = state;
+ }
+
+ public void setPanelPage(CorePanelPage panelPage)
+ {
+ _panelPage = panelPage;
+ }
+
+ public void fileUploaded(ValueChangeEvent event)
+ {
+ UploadedFile file = (UploadedFile) event.getNewValue();
+ if (file != null)
+ {
+ FacesContext context = FacesContext.getCurrentInstance();
+ FacesMessage message = new FacesMessage(
+ "Uploaded file " + file.getFilename() +
+ " (" + file.getLength() + " bytes)");
+ context.addMessage(event.getComponent().getClientId(context), message);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testFailover()
+ {
+ FacesContext context = FacesContext.getCurrentInstance();
+ Map<String, Object> session =
+ context.getExternalContext().getSessionMap();
+
+ Map.Entry<String, Object> writing = null;
+ try
+ {
+ ObjectOutputStream oos =
+ new ObjectOutputStream(new ByteArrayOutputStream(2 << 16));
+ Iterator<Map.Entry<String, Object>> entries = session.entrySet().iterator();
+ while (entries.hasNext())
+ {
+ writing = entries.next();
+ oos.writeObject(writing.getValue());
+ context.addMessage(null,
+ new FacesMessage("Successfully serialized " + writing.getValue() + " [at " + writing.getKey() + "]"));
+ }
+ }
+ catch (IOException ioe)
+ {
+ context.addMessage(null,
+ new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ "Failed while outputting object " + writing.getValue() +
+ " [at " + writing.getKey() + "]",
+ ioe.getMessage()));
+ }
+ }
+
+ //
+ // For testing purposes, here's a series of methods that can
+ // be EL-addressed that blow up. These exceptions should
+ // be displayed somewhere (preferably in a logged error
+ // message), not swallowed.
+ //
+
+ public String actionThatFails()
+ {
+ throw new IllegalStateException("Calling this action is a bad move");
+ }
+
+ public void listenerThatFails(ValueChangeEvent event)
+ {
+ throw new IllegalStateException("Using this listener is a bad move");
+ }
+
+ public String getFailedProperty()
+ {
+ throw new IllegalStateException("Getting this property is a bad move");
+ }
+
+
+ private CorePanelPage _panelPage;
+ private UIBeanState _state;
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBeanState.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBeanState.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBeanState.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBeanState.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo;
+
+public class UIBeanState implements java.io.Serializable
+{
+ public UIBeanState()
+ {
+ }
+
+ public boolean isTitleSet()
+ {
+ return _isTitleSet;
+ }
+
+ public void setTitleSet(boolean set)
+ {
+ _isTitleSet = set;
+ }
+
+ private boolean _isTitleSet;
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBeanState.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBeanState.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/change/ChangeBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/change/ChangeBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/change/ChangeBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/change/ChangeBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,405 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.change;
+
+import java.io.IOException;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.event.ActionEvent;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.myfaces.trinidad.change.AddChildComponentChange;
+import org.apache.myfaces.trinidad.change.AddChildDocumentChange;
+import org.apache.myfaces.trinidad.change.SetFacetChildComponentChange;
+import org.apache.myfaces.trinidad.change.AttributeComponentChange;
+import org.apache.myfaces.trinidad.change.ChangeManager;
+import org.apache.myfaces.trinidad.change.ComponentChange;
+import org.apache.myfaces.trinidad.change.DocumentChange;
+import org.apache.myfaces.trinidad.change.RemoveChildComponentChange;
+import org.apache.myfaces.trinidad.change.RemoveFacetComponentChange;
+import org.apache.myfaces.trinidad.change.ReorderChildrenComponentChange;
+import org.apache.myfaces.trinidad.component.core.nav.CoreCommandButton;
+
+import org.apache.myfaces.trinidad.component.core.output.CoreImage;
+import org.apache.myfaces.trinidad.component.core.output.CoreOutputFormatted;
+import org.apache.myfaces.trinidad.context.RequestContext;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+
+import org.xml.sax.SAXException;
+import java.io.ByteArrayInputStream;
+
+/**
+ * Managed bean for Change persistence demos.
+ * @version $Name: $ ($Revision$) $Date$
+ */
+public class ChangeBean
+{
+ /**
+ * Picks up an image randomly from a list and changes it on the image.
+ */
+ @SuppressWarnings("unchecked")
+ public void modifyObjectImage(ActionEvent event)
+ {
+ UIComponent uic = event.getComponent().findComponent("oi1");
+ String source = "/components/images/" + _images[_getRandIndex()];
+ uic.getAttributes().put("source", source);
+ _addAttributeChange(uic, "source", source);
+ }
+
+ /**
+ * Picks up a string randomly from a list and changes the text attribute value
+ * of the panelBox.
+ */
+ @SuppressWarnings("unchecked")
+ public void modifyPanelBox(ActionEvent event)
+ {
+ UIComponent uic = event.getComponent().findComponent("pb1");
+ String text = _texts[_getRandIndex()];
+ uic.getAttributes().put("text", text);
+ _addAttributeChange(uic, "text", text);
+ }
+
+ /**
+ * Modifies the sortable property of the column.
+ */
+ @SuppressWarnings("unchecked")
+ public void modifyColumn(ActionEvent event)
+ {
+ //=-=pu: 'uic1' gets null, while 'uic' gets valid component, maybe a bug ?.
+ //UIComponent uic1 = event.getComponent().findComponent("c1");
+ UIComponent uic2 = event.getComponent().findComponent("t1");
+ UIComponent uic = uic2.findComponent("c1");
+
+ Object sortableAttrib = uic.getAttributes().get("sortable");
+ Boolean isSortable =
+ (sortableAttrib == null)? Boolean.TRUE:(Boolean)sortableAttrib;
+ Boolean newSortableValue =
+ Boolean.TRUE.equals(isSortable)? Boolean.FALSE:Boolean.TRUE;
+ uic.getAttributes().put("sortable", newSortableValue);
+ _addAttributeChange(uic, "sortable", newSortableValue);
+ }
+
+ /**
+ * Picks up a string randomly from a list and changes the label attribute
+ * value of the inputText.
+ */
+ @SuppressWarnings("unchecked")
+ public void modifyInputText(ActionEvent event)
+ {
+ UIComponent uic = event.getComponent().findComponent("it1");
+ String label = _labels[_getRandIndex()];
+ uic.getAttributes().put("label", label);
+ _addAttributeChange(uic, "label", label);
+ }
+
+ /**
+ * Appends an image child to the panelGroup in the underlying JSP document
+ */
+ public void appendChildToDocument(ActionEvent event)
+ {
+ UIComponent eventSource = event.getComponent();
+ UIComponent uic = eventSource.findComponent("pg1");
+
+ // only allow the image to be added once
+ if (_findChildById(uic,"oi3") != null)
+ return;
+
+ FacesContext fc = FacesContext.getCurrentInstance();
+
+ DocumentFragment imageFragment = _createDocumentFragment(_IMAGE_MARK_UP);
+
+ if (imageFragment != null)
+ {
+ DocumentChange change = new AddChildDocumentChange(imageFragment);
+
+ ChangeManager apm = RequestContext.getCurrentInstance().getChangeManager();
+
+ apm.addDocumentChange(fc, uic, change);
+ }
+ }
+
+ /**
+ * Appends an image child to the panelGroup.
+ */
+ @SuppressWarnings("unchecked")
+ public void appendChild(ActionEvent event)
+ {
+ UIComponent eventSource = event.getComponent();
+ UIComponent uic = eventSource.findComponent("pg1");
+ if (_findChildById(uic,"oi2") != null)
+ return;
+ FacesContext fc = FacesContext.getCurrentInstance();
+
+ CoreImage newChild =
+ (CoreImage) fc.getApplication().createComponent(
+ "org.apache.myfaces.trinidad.CoreImage");
+ newChild.setId("oi2");
+ newChild.setInlineStyle("height: 100px, width: 120px");
+ newChild.setSource(
+ "http://homepage.mac.com/awiner/.Pictures/WindyHill/PaleSwallowtail.jpg");
+ uic.getChildren().add(newChild);
+
+ ComponentChange aca = new AddChildComponentChange(newChild);
+
+ ChangeManager apm = RequestContext.getCurrentInstance().getChangeManager();
+ apm.addComponentChange(fc, uic, aca);
+ }
+
+ /**
+ * Adds a 'brandingAppContextual' facet to the panelGroup.
+ */
+ @SuppressWarnings("unchecked")
+ public void addFacet(ActionEvent event)
+ {
+ UIComponent eventSource = event.getComponent();
+ UIComponent uic = eventSource.findComponent("pp1");
+ FacesContext fc = FacesContext.getCurrentInstance();
+ CoreOutputFormatted newFacetComponent =
+ (CoreOutputFormatted) fc.getApplication().createComponent(
+ "org.apache.myfaces.trinidad.CoreOutputFormatted");
+ newFacetComponent.setStyleUsage("inContextBranding" );
+ newFacetComponent.setValue(
+ "Customer Company - Menlo Park");
+ uic.getFacets().put("brandingAppContextual", newFacetComponent);
+
+ ComponentChange afa = new SetFacetChildComponentChange("brandingAppContextual", newFacetComponent);
+
+ ChangeManager apm = RequestContext.getCurrentInstance().getChangeManager();
+ apm.addComponentChange(fc, uic, afa);
+ }
+
+ /**
+ * Reverses the order of children of the panelGroup.
+ */
+ @SuppressWarnings("unchecked")
+ public void reorderChildren(ActionEvent event)
+ {
+ UIComponent uic = event.getComponent().findComponent("pg1");
+ int numChildren = uic.getChildCount();
+ if (numChildren == 0)
+ return;
+ List<UIComponent> children = uic.getChildren();
+ Collections.reverse(children);
+ List<String> reorderedChildIdList = new ArrayList<String>();
+ for(UIComponent child : children)
+ {
+ reorderedChildIdList.add(child.getId());
+ }
+
+ ComponentChange ra = new ReorderChildrenComponentChange(reorderedChildIdList);
+
+ FacesContext fc = FacesContext.getCurrentInstance();
+ ChangeManager apm = RequestContext.getCurrentInstance().getChangeManager();
+ apm.addComponentChange(fc, uic, ra);
+ }
+
+ /**
+ * Removes a pair of children, based on some characteristic of the
+ * event source.
+ */
+ public void removeChildren(ActionEvent event)
+ {
+ UIComponent eventSource = event.getComponent();
+ UIComponent uic = eventSource.findComponent("pg1");
+ int numChildren = uic.getChildCount();
+ if (numChildren == 0)
+ return;
+ String eventSourceId = eventSource.getId();
+ if (eventSourceId.equals("cb2"))
+ {
+ _removeChild(uic, "sic1");
+ _removeChild(uic, "cc1");
+ }
+ else if (eventSourceId.equals("cb3"))
+ {
+ _removeChild(uic, "cd1");
+ _removeChild(uic, "sid1");
+ }
+ }
+
+ /**
+ * Removes one or more facets, based on some characteristic of the
+ * event source.
+ */
+ @SuppressWarnings("unchecked")
+ public void removeFacets(ActionEvent event)
+ {
+ CoreCommandButton eventSource = (CoreCommandButton) event.getComponent();
+ //pu: Anything until ":" in the button text represents the facet name/s
+ String facetNameFromButtonText = (eventSource.getText().split(":"))[0];
+ //pu: In case of the button that removes multiple facets, this is again
+ // delimited by "_"
+ String removableFacetNames[] = facetNameFromButtonText.split("_");
+
+ //pu: Get the CorePanelPage components that has all the removable facets
+ UIComponent uic = eventSource.findComponent("pp1");
+ Map<String, UIComponent> facets = uic.getFacets();
+ if (facets.keySet().size() == 0)
+ return;
+
+ for (int i=0; i<removableFacetNames.length; i++)
+ {
+ if (facets.get(removableFacetNames[i]) != null)
+ {
+ facets.remove(removableFacetNames[i]);
+ ComponentChange rfa = new RemoveFacetComponentChange(removableFacetNames[i]);
+ FacesContext fc = FacesContext.getCurrentInstance();
+ ChangeManager apm = RequestContext.getCurrentInstance().getChangeManager();
+ apm.addComponentChange(fc, uic, rfa);
+ }
+ }
+ }
+
+ /**
+ * Creates a DocumentFragment containing the parsed content
+ * @param markUp JSP Document markup
+ * @return DocumentFragment containing the parsed content
+ */
+ private static DocumentFragment _createDocumentFragment(
+ String markUp)
+ {
+ // prepend XML declaration
+ markUp = "<?xml version = '1.0' encoding = 'ISO-8859-1'?>" + markUp;
+
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ factory.setValidating(false);
+
+ DocumentBuilder builder;
+
+ try
+ {
+ builder = factory.newDocumentBuilder();
+ }
+ catch (ParserConfigurationException pce)
+ {
+ _LOG.log(Level.WARNING, "Unable to get XML Parser:", pce);
+
+ return null;
+ }
+
+ try
+ {
+ // use a version explicitly with ISO-8859-1 instead
+ byte[] markupBytes = markUp.getBytes();
+ Document newDoc = builder.parse(new ByteArrayInputStream(markupBytes));
+
+ DocumentFragment fragment = newDoc.createDocumentFragment();
+
+ // add the document's root element to the fragment
+ fragment.appendChild(newDoc.getDocumentElement());
+
+ return fragment;
+ }
+ catch (SAXException se)
+ {
+ _LOG.log(Level.WARNING, "Unable to parse markup:" + markUp, se);
+
+ return null;
+ }
+ catch (IOException ioe)
+ {
+ _LOG.log(Level.WARNING, "IO Problem with markup:" + markUp, ioe);
+
+ return null;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private static void _removeChild(UIComponent uic, String removableChildId)
+ {
+ UIComponent removableChild = _findChildById(uic, removableChildId);
+ if (removableChild != null)
+ {
+ List<UIComponent> children = uic.getChildren();
+ children.remove(removableChild);
+ ComponentChange rca = new RemoveChildComponentChange(removableChildId);
+ FacesContext fc = FacesContext.getCurrentInstance();
+ ChangeManager apm = RequestContext.getCurrentInstance().getChangeManager();
+ apm.addComponentChange(fc, uic, rca);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private static UIComponent _findChildById(UIComponent uic, String id)
+ {
+ int numChildren = uic.getChildCount();
+ if (numChildren == 0)
+ return null;
+ List<UIComponent> children = uic.getChildren();
+ UIComponent child = null;
+ for (int i=0; i<numChildren; i++)
+ {
+ child = children.get(i);
+ if (id.equals(child.getId()))
+ return child;
+ }
+ return null;
+ }
+
+ private static void _addAttributeChange(
+ UIComponent uic,
+ String attribName,
+ Object attribValue
+ )
+ {
+ FacesContext fc = FacesContext.getCurrentInstance();
+ ChangeManager apm = RequestContext.getCurrentInstance().getChangeManager();
+ ComponentChange aa = new AttributeComponentChange(attribName, attribValue);
+ apm.addComponentChange(fc, uic, aa);
+ }
+
+ private static int _getRandIndex()
+ {
+ return (int) (Math.random()*10)/2;
+ }
+
+ private static final String _images[] =
+ {"cobrand.gif","corporateBrand.gif","largeAd.gif","mediumAd.gif","new.gif"};
+ private static final String _labels[] =
+ {"Label One","Label Two","Label Three","Label Four","Label Five"};
+ private static final String _texts[] =
+ {"PanelBoxText One",
+ "PanelBoxText Two",
+ "PanelBoxText Three",
+ "PanelBoxText Four",
+ "PanelBoxText Five"};
+
+ // markup to use for image added to document
+ private static final String _IMAGE_MARK_UP =
+ "<tr:Image id='oi3' inlineStyle='height: 100px; width: 120px;' " +
+ "source='http://homepage.mac.com/awiner/.Pictures/WindyHill/PaleSwallowtail.jpg' " +
+ "xmlns:af='http://myfaces.apache.org/adf/faces/EA17'/>";
+
+ static private final Logger _LOG = Logger.getLogger(ChangeBean.class.getName());
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/change/ChangeBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/change/ChangeBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/CompositeTest.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/CompositeTest.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/CompositeTest.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/CompositeTest.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.composite;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
+
+public class CompositeTest
+{
+ public CompositeTest()
+ {
+ }
+
+ public UIComponent getDateInput()
+ {
+ return _dateInput;
+ }
+
+ public void setDateInput(UIComponent dateInput)
+ {
+ _dateInput = dateInput;
+ }
+
+ private UIComponent _dateInput = new ForceRendererType();
+
+ /**
+ * Turns out there's no easy way to simply replace the renderer
+ * for a control like UIInput; UIComponentTag will call setRendererType()
+ * after consulting the "binding" attribute, overriding anything
+ * done in either the getter or setter. So, here's a subclass
+ * that forces the renderer type to a constant. The alternative
+ * is writing a custom JSP tag to do the same, but then you
+ * have to re-invent the wheel as far as the input tag goes.
+ */
+ static public class ForceRendererType extends UIInput
+ {
+ @Override
+ public String getRendererType()
+ {
+ return "org.apache.myfaces.trinidaddemo.DateField";
+ }
+ }
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/CompositeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/CompositeTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.composite;
+
+import java.io.IOException;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.NumberConverter;
+import javax.faces.event.ValueChangeEvent;
+import javax.faces.validator.LongRangeValidator;
+
+import org.apache.myfaces.trinidad.component.UIXEditableValue;
+import org.apache.myfaces.trinidad.component.core.output.CoreOutputText;
+import org.apache.myfaces.trinidad.component.core.input.CoreInputText;
+
+/**
+ * An experiment in building a composite component. Some basic
+ * principles:
+ * <ul>
+ * <li> We're a NamingContainer, so our children won't show up in
+ * findComponent() calls.
+ * <li> The child components get re-created on each pass through
+ * the system; this means seeing if they exist in both Apply Request
+ * Values (<code>processDecodes</code>) and Render Response
+ * (<code>encodeBegin()</code>), and marking the components
+ * transient so they don't get saved.
+ * <li> The model is the tricky part: instead of using real
+ * <code>ValueBindings</code> on the children, I let them
+ * use local values, and then manully transfer over their local values
+ * into an overall "local value" during validate(). Unfortunately,
+ * using ValueBindings to automate the transfer wouldn't quite work,
+ * since the transfer wouldn't happen 'til Update Model, which is
+ * too late to preserve the semantics of an editable value component in JSF.
+ * <li>Apply Request Values and Update Model don't need to do anything special
+ * for the children; they just run as needed.
+ * </ul>
+ * @author Adam Winer
+ */
+public class DateField extends UIXEditableValue implements NamingContainer
+{
+ public DateField()
+ {
+ super(null);
+ }
+
+ @Override
+ public void processDecodes(FacesContext context)
+ {
+ _addChildren(context);
+ super.processDecodes(context);
+ }
+
+ @Override
+ public void validate(FacesContext context)
+ {
+ if (!_month.isValid() ||
+ !_year.isValid() ||
+ !_day.isValid())
+ {
+ setValid(false);
+ return;
+ }
+
+ int year = ((Number) _year.getValue()).intValue();
+ // We'll be 1970 - 2069. Good enough for a demo.
+ if (year < 70)
+ year += 100;
+
+ int month = ((Number) _month.getValue()).intValue() - 1;
+ int day = ((Number) _day.getValue()).intValue();
+
+ Date oldValue = (Date) getValue();
+ Calendar calendar = Calendar.getInstance();
+ calendar.setLenient(true);
+ calendar.setTime(oldValue);
+ calendar.set(Calendar.YEAR, year);
+ calendar.set(Calendar.MONTH, month);
+ calendar.set(Calendar.DAY_OF_MONTH, day);
+
+ //=-=AEW RUN VALIDATORS!
+
+ // Invalid day given the month
+ if (day != calendar.get(Calendar.DAY_OF_MONTH))
+ {
+ int numberOfDaysInMonth = day - calendar.get(Calendar.DAY_OF_MONTH);
+ FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ "Invalid date.",
+ "This month only has " + numberOfDaysInMonth + " days!");
+ setValid(false);
+ context.addMessage(getClientId(context), message);
+ }
+ // Looks good
+ else
+ {
+ setValid(true);
+
+ // And if the value actually changed, store it and send a value change
+ // event.
+ Date newValue = calendar.getTime();
+ if (!calendar.getTime().equals(oldValue))
+ {
+ setValue(newValue);
+ queueEvent(new ValueChangeEvent(this, oldValue, newValue));
+ }
+ }
+ }
+
+ @Override
+ public void encodeBegin(FacesContext context) throws IOException
+ {
+ _addChildren(context);
+ super.encodeBegin(context);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void encodeChildren(FacesContext context) throws IOException
+ {
+ for(UIComponent child : (List<UIComponent>)getChildren())
+ {
+ assert(child.getChildCount() == 0);
+ assert(child.getFacets().isEmpty());
+ child.encodeBegin(context);
+ child.encodeChildren(context);
+ child.encodeEnd(context);
+ }
+ }
+
+ @Override
+ public boolean getRendersChildren()
+ {
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void _addChildren(FacesContext context)
+ {
+ if (_month != null)
+ return;
+
+ List<UIComponent> children = getChildren();
+ children.clear();
+
+ Date value = (Date) getValue();
+ Calendar calendar = null;
+ if(value != null)
+ {
+ calendar = Calendar.getInstance();
+ calendar.setLenient(true);
+ calendar.setTime(value);
+ }
+
+ // A proper implementation would add children in the correct
+ // order for the current locale
+ _month = _createTwoDigitInput(context);
+ _month.setId("month");
+ _month.setShortDesc("Month");
+ LongRangeValidator monthRange = _createLongRangeValidator(context);
+ monthRange.setMinimum(1);
+ monthRange.setMaximum(12);
+ _month.addValidator(monthRange);
+ if (value != null)
+ _month.setValue(new Integer(calendar.get(Calendar.MONTH) + 1));
+
+ _day = _createTwoDigitInput(context);
+ _day.setId("day");
+ _day.setShortDesc("Day");
+ LongRangeValidator dayRange = _createLongRangeValidator(context);
+ dayRange.setMinimum(1);
+ dayRange.setMaximum(31);
+ _day.addValidator(dayRange);
+ if (value != null)
+ _day.setValue(new Integer(calendar.get(Calendar.DAY_OF_MONTH)));
+
+ _year = _createTwoDigitInput(context);
+ _year.setId("year");
+ _year.setShortDesc("Year");
+ if (value != null)
+ {
+ int yearValue = calendar.get(Calendar.YEAR) - 1900;
+ if (yearValue >= 100)
+ yearValue -= 100;
+ _year.setValue(new Integer(yearValue));
+ }
+
+ children.add(_month);
+ children.add(_createSeparator(context));
+ children.add(_day);
+ children.add(_createSeparator(context));
+ children.add(_year);
+ }
+
+ private LongRangeValidator _createLongRangeValidator(FacesContext context)
+ {
+ return (LongRangeValidator)
+ context.getApplication().createValidator(LongRangeValidator.VALIDATOR_ID);
+ }
+
+ private CoreInputText _createTwoDigitInput(FacesContext context)
+ {
+ CoreInputText input = new CoreInputText();
+ input.setColumns(2);
+ input.setMaximumLength(2);
+ input.setTransient(true);
+ input.setRequired(true);
+ input.setSimple(true);
+
+ NumberConverter converter = (NumberConverter)
+ context.getApplication().createConverter(NumberConverter.CONVERTER_ID);
+ converter.setIntegerOnly(true);
+ converter.setMaxIntegerDigits(2);
+ converter.setMinIntegerDigits(2);
+ input.setConverter(converter);
+
+ return input;
+ }
+
+ // A proper implementation would create a separator appropriate
+ // to the current locale
+ private CoreOutputText _createSeparator(FacesContext context)
+ {
+ CoreOutputText output = new CoreOutputText();
+ output.setValue("/");
+ output.setTransient(true);
+ return output;
+ }
+
+ private transient CoreInputText _month;
+ private transient CoreInputText _year;
+ private transient CoreInputText _day;
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,257 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.composite;
+
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Map;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.convert.ConverterException;
+import javax.faces.convert.NumberConverter;
+import javax.faces.render.Renderer;
+import javax.faces.validator.LongRangeValidator;
+
+import org.apache.myfaces.trinidad.component.core.input.CoreInputText;
+
+/**
+ * An experiment in building a renderer that uses a composite
+ * component strategy to render. Some basic principles:
+ * <ul>
+ * <li> The child components get re-created on each pass through
+ * the system; this means seeing if they exist in both Apply Request
+ * Values (<code>decode()</code>) and Render Response
+ * (<code>encodeBegin()</code>), and marking the components
+ * transient so they don't get saved.
+ * <li> The model is the tricky part: instead of using real
+ * <code>ValueBindings</code> on the children, I let them
+ * use local values, and then manully transfer over their local values
+ * into an overall "local value" during validate(). Unfortunately,
+ * using ValueBindings to automate the transfer wouldn't quite work,
+ * since the transfer wouldn't happen 'til Update Model, which is
+ * too late to preserve the semantics of an editable value component in JSF.
+ * </ul>
+ * @author Adam Winer
+ */
+public class DateFieldAsRenderer extends Renderer
+{
+ @SuppressWarnings("unchecked")
+ @Override
+ public void decode(FacesContext context, UIComponent component)
+ {
+ _addChildren(context, component);
+
+ Map<String, UIComponent> attrs = component.getAttributes();
+ if (Boolean.TRUE.equals(attrs.get("readOnly")) ||
+ Boolean.TRUE.equals(attrs.get("disabled")))
+ return;
+
+ // Just clue in component that we have been "submitted" so
+ // that it doesn't short-circuit anything
+ EditableValueHolder evh = (EditableValueHolder) component;
+ evh.setSubmittedValue(Boolean.TRUE);
+
+ // Because these components weren't around during processDecodes(),
+ // they didn't get decoded. So, run that now.
+ component.getFacet("month").processDecodes(context);
+ component.getFacet("year").processDecodes(context);
+ component.getFacet("day").processDecodes(context);
+ }
+
+ @Override
+ public Object getConvertedValue(
+ FacesContext context,
+ UIComponent component,
+ Object submittedValue)
+ {
+ EditableValueHolder monthComp = (EditableValueHolder) component.getFacet("month");
+ EditableValueHolder yearComp = (EditableValueHolder) component.getFacet("year");
+ EditableValueHolder dayComp = (EditableValueHolder) component.getFacet("day");
+
+ if (!monthComp.isValid() ||
+ !yearComp.isValid() ||
+ !dayComp.isValid())
+ {
+ // =-=AEW What to do????????
+ //setValid(false);
+ return null;
+ }
+
+ int year = ((Number) yearComp.getValue()).intValue();
+ // We'll be 1970 - 2069. Good enough for a demo.
+ if (year < 70)
+ year += 100;
+
+ int month = ((Number) monthComp.getValue()).intValue() - 1;
+ int day = ((Number) dayComp.getValue()).intValue();
+
+ Date oldValue = (Date) ((EditableValueHolder) component).getValue();
+ //Date newValue = (Date) oldValue.clone();
+ Calendar calendar = Calendar.getInstance();
+ calendar.setLenient(true);
+ calendar.setTime(oldValue);
+ calendar.set(Calendar.YEAR, year);
+ calendar.set(Calendar.MONTH, month);
+ calendar.set(Calendar.DAY_OF_MONTH, day);
+
+ // Invalid day given the month
+ if (day != calendar.get(Calendar.DAY_OF_MONTH))
+ {
+ int numberOfDaysInMonth = day - calendar.get(Calendar.DAY_OF_MONTH);
+ FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ "Invalid date.",
+ "This month only has " + numberOfDaysInMonth + " days!");
+ throw new ConverterException(message);
+ }
+
+ return calendar.getTime();
+ }
+
+ @Override
+ public void encodeBegin(FacesContext context,
+ UIComponent component) throws IOException
+ {
+ _addChildren(context, component);
+ }
+
+ @Override
+ public void encodeChildren(FacesContext context,
+ UIComponent component) throws IOException
+ {
+ ResponseWriter out = context.getResponseWriter();
+
+ UIComponent month = component.getFacet("month");
+ month.encodeBegin(context);
+ month.encodeChildren(context);
+ month.encodeEnd(context);
+
+ out.writeText("\u00a0/\u00a0", null);
+
+ UIComponent day = component.getFacet("day");
+ day.encodeBegin(context);
+ day.encodeChildren(context);
+ day.encodeEnd(context);
+
+ out.writeText("\u00a0/\u00a0", null);
+
+ UIComponent year = component.getFacet("year");
+ year.encodeBegin(context);
+ year.encodeChildren(context);
+ year.encodeEnd(context);
+ }
+
+ @Override
+ public boolean getRendersChildren()
+ {
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void _addChildren(FacesContext context, UIComponent component)
+ {
+ // If the components are already there, bail.
+ if (component.getFacet("month") != null)
+ return;
+
+ String id = component.getId();
+ if (id == null)
+ {
+ id = context.getViewRoot().createUniqueId();
+ component.setId(id);
+ }
+
+ Map<String, UIComponent> facets = component.getFacets();
+ facets.clear();
+
+ Date value = (Date) ((EditableValueHolder) component).getValue();
+ Calendar calendar = null;
+ if(value != null)
+ {
+ calendar = Calendar.getInstance();
+ calendar.setLenient(true);
+ calendar.setTime(value);
+ }
+
+ CoreInputText month = _createTwoDigitInput(context);
+ month.setShortDesc("Month");
+ month.setId(id + "_month");
+
+ LongRangeValidator monthRange = _createLongRangeValidator(context);
+ monthRange.setMinimum(1);
+ monthRange.setMaximum(12);
+ month.addValidator(monthRange);
+ if (value != null)
+ month.setValue(new Integer(calendar.get(Calendar.MONTH) + 1));
+ facets.put("month", month);
+
+ CoreInputText day = _createTwoDigitInput(context);
+ day.setShortDesc("Day");
+ day.setId(id + "_day");
+ LongRangeValidator dayRange = _createLongRangeValidator(context);
+ dayRange.setMinimum(1);
+ dayRange.setMaximum(31);
+ day.addValidator(dayRange);
+ if (value != null)
+ day.setValue(new Integer(calendar.get(Calendar.DAY_OF_MONTH)));
+ facets.put("day", day);
+
+ CoreInputText year = _createTwoDigitInput(context);
+ year.setShortDesc("Year");
+ year.setId(id + "_year");
+ if (value != null)
+ {
+ int yearValue = calendar.get(Calendar.YEAR) - 1900;
+ if (yearValue >= 100)
+ yearValue -= 100;
+ year.setValue(new Integer(yearValue));
+ }
+
+ facets.put("year", year);
+ }
+
+ private LongRangeValidator _createLongRangeValidator(FacesContext context)
+ {
+ return (LongRangeValidator)
+ context.getApplication().createValidator(LongRangeValidator.VALIDATOR_ID);
+ }
+
+ private CoreInputText _createTwoDigitInput(FacesContext context)
+ {
+ CoreInputText input = new CoreInputText();
+ input.setColumns(2);
+ input.setMaximumLength(2);
+ input.setTransient(true);
+ input.setRequired(true);
+ input.setSimple(true);
+
+ NumberConverter converter = (NumberConverter)
+ context.getApplication().createConverter(NumberConverter.CONVERTER_ID);
+ converter.setIntegerOnly(true);
+ converter.setMaxIntegerDigits(2);
+ converter.setMinIntegerDigits(2);
+ input.setConverter(converter);
+
+ return input;
+ }
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldTag.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldTag.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldTag.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldTag.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.composite;
+
+import org.apache.myfaces.trinidadinternal.taglib.UIXEditableValueTag;
+
+
+/**
+ * NOTE: a clients may not extend UIXEditableValueTag (or
+ * any other tag classes), as these are not part of the public
+ * API (note the package); I'm doing it for expedience here.
+ */
+public class DateFieldTag extends UIXEditableValueTag
+{
+ @Override
+ public String getComponentType()
+ {
+ return "org.apache.myfaces.trinidaddemo.DateField";
+ }
+
+ @Override
+ public String getRendererType()
+ {
+ return null;
+ }
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldTag.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ConvertSSNTag.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ConvertSSNTag.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ConvertSSNTag.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ConvertSSNTag.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.convertValidate;
+
+import javax.faces.convert.Converter;
+import javax.faces.webapp.ConverterTag;
+
+import javax.servlet.jsp.JspException;
+
+
+public class ConvertSSNTag extends ConverterTag
+{
+
+ public ConvertSSNTag()
+ {
+ }
+
+ @Override
+ public int doStartTag() throws JspException
+ {
+ super.setConverterId(SSNConverter.CONVERTER_ID);
+ return super.doStartTag();
+ }
+
+ /**
+ *
+ */
+ @Override
+ protected Converter createConverter() throws JspException
+ {
+ SSNConverter converter =
+ (SSNConverter)super.createConverter();
+ return converter;
+ }
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ConvertSSNTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ConvertSSNTag.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/PasswordValidator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/PasswordValidator.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/PasswordValidator.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/PasswordValidator.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.convertValidate;
+
+import java.util.Collection;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+import org.apache.myfaces.trinidad.validator.ClientValidator;
+import org.apache.myfaces.trinidad.util.LabeledFacesMessage;
+
+/**
+ * <p>Password validator - this is an incredibly simple
+ * password validator that makes sure there's at least one number
+ * in the password.</p>
+ *
+ */
+public class PasswordValidator implements Validator, ClientValidator
+{
+ public static final String VALIDATOR_ID = "org.apache.myfaces.trinidaddemo.PasswordValidator";
+
+ public void validate(
+ FacesContext context,
+ UIComponent component,
+ Object value) throws ValidatorException
+ {
+
+ String password = "";
+
+ if ( value != null)
+ password = value.toString().trim();
+
+ for (int j = 0;j < password.length();j++)
+ {
+ if (Character.isDigit(password.charAt(j)))
+ {
+ return;
+ }
+ }
+
+ // Using the LabeledFacesMessage allows the <tr:messages> component to
+ // properly prepend the label as a link.
+ LabeledFacesMessage lfm =
+ new LabeledFacesMessage(FacesMessage.SEVERITY_ERROR,
+ "Validation Error",
+ "The password must contain at least one number");
+ lfm.setLabel(_getLabel(component));
+ throw new ValidatorException(lfm);
+ }
+
+
+ public String getClientValidation(
+ FacesContext context,
+ UIComponent component)
+ {
+ return (_VALIDATOR_INSTANCE_STRING);
+ }
+
+
+ public Collection<String> getClientImportNames()
+ {
+ return null;
+ }
+
+ public String getClientLibrarySource(
+ FacesContext context)
+ {
+ return context.getExternalContext().getRequestContextPath() +
+ "/jsLibs/passwordValidator.js";
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public String getClientScript(
+ FacesContext context,
+ UIComponent component)
+ {
+ return null;
+ }
+
+ private static Object _getLabel(UIComponent component)
+ {
+ Object o = null;
+ if (component != null)
+ {
+ o = component.getAttributes().get("label");
+ if (o == null)
+ o = component.getValueBinding("label");
+ }
+ return o;
+ }
+
+ // in a real app the messages would be translated
+ // The fourth field marker gets the field label
+ private static final String _VALIDATOR_INSTANCE_STRING =
+ "new PasswordValidator({"
+ + "NS:'The password is invalid.',"
+ + "ND:'The password value must contain at least one number.'})";
+
+
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/PasswordValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/PasswordValidator.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/SSNConverter.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/SSNConverter.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/SSNConverter.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/SSNConverter.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.convertValidate;
+
+import java.util.Collection;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+
+import org.apache.myfaces.trinidad.convert.ClientConverter;
+import org.apache.myfaces.trinidad.util.LabeledFacesMessage;
+
+/**
+ * <p>Social Security number converter.</p>
+ *
+ */
+public class SSNConverter implements Converter, ClientConverter
+{
+ public static final String CONVERTER_ID = "org.apache.myfaces.trinidaddemo.SSN";
+
+ public Object getAsObject(
+ FacesContext context,
+ UIComponent component,
+ String value)
+ {
+ // In a real app all the error messages would be translated
+ if ( value == null || value.trim().length() == 0)
+ return null;
+
+ String tValue = value.trim();
+
+ int length = tValue.length();
+ if ( length < 9 )
+ {
+ throw new ConverterException(_getMessage(component, _SHORT_ERROR_TEXT));
+ }
+
+ if ( length > 11 )
+ {
+ throw new ConverterException(_getMessage(component, _LONG_ERROR_TEXT));
+ }
+
+ if (length == 9)
+ {
+ try
+ {
+ return Integer.valueOf(tValue);
+ }
+ catch(NumberFormatException nfe)
+ {
+ throw new ConverterException(_getMessage(component,
+ _INVALID_ERROR_TEXT));
+ }
+ }
+
+ if ( length == 11 &&
+ tValue.charAt(3) == '-' &&
+ tValue.charAt(6) == '-')
+ {
+ String v = tValue.substring(0,3) +
+ tValue.substring(4,6) +
+ tValue.substring(7);
+
+ try
+ {
+ return Integer.valueOf(v);
+ }
+ catch(NumberFormatException nfe)
+ {
+ throw new ConverterException(_getMessage(component,
+ _INVALID_ERROR_TEXT));
+ }
+
+ }
+ throw new ConverterException(_getMessage(component, _INVALID_ERROR_TEXT));
+ }
+
+ public String getAsString(
+ FacesContext context,
+ UIComponent component,
+ Object value)
+ {
+ if ( value == null || !(value instanceof Integer))
+ return null;
+
+ Integer integerValue = (Integer)value;
+
+ String valueString = integerValue.toString();
+
+ String ssn = valueString.substring(0,3) + '-' +
+ valueString.substring(3,5) + '-' +
+ valueString.substring(5,9);
+ return ssn;
+ }
+
+
+ public Collection<String> getClientImportNames()
+ {
+ return null;
+ }
+
+ public String getClientLibrarySource(
+ FacesContext context)
+ {
+ return context.getExternalContext().getRequestContextPath() +
+ "/jsLibs/ssnConverter.js";
+ }
+
+ public String getClientConversion(
+ FacesContext context,
+ UIComponent component)
+ {
+
+ // in a real app the messages would be translated
+ return ("new SSNConverter({"
+ + "SUM:'Invalid social security number.',"
+ + "S:'Value \"{1}\" is too short.',"
+ + "L:'Value \"{1}\" is too long.',"
+ + "N:'Value \"{1}\" is not a valid social security number.'})"
+ );
+ }
+
+ @SuppressWarnings("unchecked")
+ public String getClientScript(
+ FacesContext context,
+ UIComponent component)
+ {
+ return null;
+ }
+
+ private LabeledFacesMessage _getMessage(
+ UIComponent component,
+ String text)
+ {
+ // Using the LabeledFacesMessage allows the <tr:messages> component to
+ // properly prepend the label as a link.
+ LabeledFacesMessage lfm =
+ new LabeledFacesMessage(FacesMessage.SEVERITY_ERROR,
+ "Conversion Error", text);
+ if (component != null)
+ {
+ Object label = null;
+ label = component.getAttributes().get("label");
+ if (label == null)
+ label = component.getValueBinding("label");
+ if (label != null)
+ lfm.setLabel(label);
+ }
+ return lfm;
+ }
+
+ private static final String _SHORT_ERROR_TEXT
+ = "The value is too short to be a social security number";
+
+ private static final String _LONG_ERROR_TEXT
+ = "The value is too long to be a social security number";
+
+ private static final String _INVALID_ERROR_TEXT
+ = "The value is not a valid social security number";
+
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/SSNConverter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/SSNConverter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ValidatePasswordTag.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ValidatePasswordTag.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ValidatePasswordTag.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ValidatePasswordTag.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.convertValidate;
+
+import javax.faces.validator.Validator;
+import javax.faces.webapp.ValidatorTag;
+import javax.servlet.jsp.JspException;
+
+
+public class ValidatePasswordTag extends ValidatorTag
+{
+
+ public ValidatePasswordTag()
+ {
+ }
+
+ @Override
+ public int doStartTag() throws JspException
+ {
+ super.setValidatorId(PasswordValidator.VALIDATOR_ID);
+ return super.doStartTag();
+ }
+
+ /**
+ *
+ */
+ @Override
+ protected Validator createValidator() throws JspException
+ {
+ PasswordValidator validator =
+ (PasswordValidator)super.createValidator();
+ return validator;
+ }
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ValidatePasswordTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ValidatePasswordTag.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/ChooseIntegerBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/ChooseIntegerBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/ChooseIntegerBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/ChooseIntegerBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.dialog;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.trinidad.event.ReturnEvent;
+
+public class ChooseIntegerBean
+{
+ public Integer getValue1()
+ {
+ return _value1;
+ }
+
+ public void setValue1(Integer value1)
+ {
+ _value1 = value1;
+ }
+
+ public Integer getValue2()
+ {
+ return _value2;
+ }
+
+ public void setValue2(Integer value2)
+ {
+ _value2 = value2;
+ }
+
+ public void sayHello(ReturnEvent event)
+ {
+ FacesMessage message = new FacesMessage("Hello!");
+ FacesContext.getCurrentInstance().addMessage(null, message);
+ }
+
+ private Integer _value1;
+ private Integer _value2;
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/ChooseIntegerBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/ChooseIntegerBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL