myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r551482 [3/19] - in /myfaces/trinidad/branches/matzew121core_release/trinidad-examples: ./ trinidad-demo/ trinidad-demo/src/ trinidad-demo/src/conf/ trinidad-demo/src/main/ trinidad-demo/src/main/java/ trinidad-demo/src/main/java/org/ trini...
Date Thu, 28 Jun 2007 07:19:20 GMT
Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PartialDemoUtilBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PartialDemoUtilBean.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PartialDemoUtilBean.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PartialDemoUtilBean.java Thu Jun 28 00:19:04 2007
@@ -0,0 +1,138 @@
+/*
+ *  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.application.ViewHandler;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.ValueChangeEvent;
+
+import org.apache.myfaces.trinidad.component.UIXOutput;
+import org.apache.myfaces.trinidad.context.RequestContext;
+
+public class PartialDemoUtilBean
+{
+  public void action(ActionEvent action)
+  {
+    // Just update the string which says when the last update was.
+    _status.setLinkUpdate();
+  }
+
+  // This is called for the resetButton
+  public void reset(ActionEvent action)
+  {
+    _status.reset();
+    _resetList();
+  }
+
+  public void valueChanged(ValueChangeEvent vce)
+  {
+    Object newValue = vce.getNewValue();
+    UIComponent component = vce.getComponent();
+
+    String rendererType = component.getRendererType();
+
+    // For these first components the listeners have registered themselves
+    // by setting the partialTriggers attribute. So we just update the model.
+    if (rendererType.equals("org.apache.myfaces.trinidad.Checkbox"))
+    {
+      _status.setChecked((Boolean) newValue);
+      _status.incrementCheckBoxUpdateCount();
+    }
+    else if (rendererType.equals("org.apache.myfaces.trinidad.Radio"))
+    {
+      if (Boolean.TRUE.equals(newValue))
+      {
+        String text = (String) component.getAttributes().get("text");
+        _status.setSelectBooleanState(text);
+      }
+      else if (newValue instanceof String)
+        _status.setSelectOneState((String) newValue);
+    }
+    else if (rendererType.equals("org.apache.myfaces.trinidad.Text"))
+    {
+      if (newValue instanceof String)
+        _status.setTextValue((String) newValue);
+    }
+    else if (rendererType.equals("org.apache.myfaces.trinidad.Choice"))
+    {
+      if (newValue instanceof String)
+        _status.setChoiceInt((String) newValue);
+    }
+
+    // This component illustrates a method of dynamically adding a
+    // partialTarget (i.e. without setting the partialTriggers attribute). It
+    // updates a component binding and adds the updated component directly to
+    // the list of partial targets.
+    else if (rendererType.equals("org.apache.myfaces.trinidad.Listbox"))
+    {
+      _listUpdate.setValue(component.getAttributes().get("value"));
+      _addTarget(_listUpdate);
+    }
+  }
+
+  public UIXOutput getListUpdate()
+  {
+    return _listUpdate;
+  }
+
+  public void setListUpdate(UIXOutput listUpdate)
+  {
+    _listUpdate = listUpdate;
+  }
+
+  public PartialDemoStatusBean getStatus()
+  {
+    return _status;
+  }
+
+  public void setStatus(PartialDemoStatusBean status)
+  {
+    _status = status;
+  }
+
+  public void navigate(ValueChangeEvent vce)
+  {
+    Object newValue = vce.getNewValue();
+    if ((newValue != null) && !"".equals(newValue))
+    {
+      FacesContext fContext = FacesContext.getCurrentInstance(); 
+      ViewHandler vh = fContext.getApplication().getViewHandler(); 
+      UIViewRoot root = vh.createView(fContext, newValue.toString()); 
+      fContext.setViewRoot(root); 
+    }
+  }
+
+  private void _resetList()
+  {
+    _listUpdate.setValue("nothing yet.");
+    _addTarget(_listUpdate);
+  }
+
+  private void _addTarget(UIComponent target)
+  {
+    RequestContext adfContext = RequestContext.getCurrentInstance();
+    adfContext.addPartialTarget(target);
+  }
+
+  private PartialDemoStatusBean _status;
+  private UIXOutput _listUpdate;
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PollBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PollBean.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PollBean.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PollBean.java Thu Jun 28 00:19:04 2007
@@ -0,0 +1,53 @@
+/*
+ *  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.event.ActionEvent;
+import org.apache.myfaces.trinidad.event.PollEvent;
+
+/**
+ * Bean for poll component demos.
+ *
+ * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-demo/src/main/java/oracle/adfdemo/view/faces/PollBean.java#1 $) $Date: 16-aug-2005.15:12:28 $
+ */
+
+public class PollBean implements java.io.Serializable
+{
+  public PollBean()
+  {
+    _POLL_COUNT = 0;
+  }
+  
+  public void onPoll(PollEvent event)
+  {
+    ++_POLL_COUNT;
+  }
+  
+  public int getPollCount()
+  {
+    return _POLL_COUNT;
+  }
+  
+  public void resetPoll(ActionEvent event)
+  {
+    _POLL_COUNT = 0;
+  }
+  
+  private static int _POLL_COUNT;
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PreferencesProxy.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PreferencesProxy.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PreferencesProxy.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PreferencesProxy.java Thu Jun 28 00:19:04 2007
@@ -0,0 +1,57 @@
+/*
+ *  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.Collections;
+
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+/**
+ * A proxy class to ask the e-mail demo for preferences information,
+ * but only when we're inside the e-mail demo!
+ */
+public class PreferencesProxy
+{
+  public Object getProxy()
+  {
+    // If we're in the e-mail demo, use its preferences
+    FacesContext context = FacesContext.getCurrentInstance();
+    if ((context.getViewRoot() != null) &&
+        (context.getViewRoot().getViewId().indexOf("/email/") >= 0))
+    {
+      ValueBinding vb =
+        context.getApplication().createValueBinding("#{email.preferences}");
+      return vb.getValue(context);
+    }
+    // If we are showing the SkinDemo page, get the skinFamily from the 
+    // sessionScope.
+    else if ((context.getViewRoot() != null) &&
+        (context.getViewRoot().getViewId().indexOf("SkinDemo") >= 0))
+    {
+      ValueBinding vb =
+        context.getApplication().createValueBinding("#{sessionScope}");
+      return vb.getValue(context);     
+    }
+    // Otherwise, go to an empty map (blank preferences)
+    else
+      return Collections.EMPTY_MAP;
+
+  }
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ProgressBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ProgressBean.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ProgressBean.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ProgressBean.java Thu Jun 28 00:19:04 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;
+
+import java.io.Serializable;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.event.ActionEvent;
+
+import org.apache.myfaces.trinidad.model.BoundedRangeModel;
+import org.apache.myfaces.trinidad.model.DefaultBoundedRangeModel;
+
+/**
+ * Bean for progress component demos.
+ *
+ * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-demo/src/main/java/oracle/adfdemo/view/faces/ProgressBean.java#1 $) $Date: 16-aug-2005.15:12:28 $
+ */
+public class ProgressBean implements Serializable
+{
+  public BoundedRangeModel getProgressModel()
+  {
+    if (null == __model)
+    {
+      prepare();
+    }
+    return __model;
+  }
+  
+  public void cancelProcess(ActionEvent event)
+  {
+    endProcess();
+  }
+  
+  protected void prepare()
+  {
+    __model = new DefaultBoundedRangeModel(-1, 125);
+    //pu: simulate asynchronous model updates on a different thread
+    __processThread = new ProcessThread(500, 0);
+    __processThread.start();
+  }
+  
+  protected void endProcess()
+  {
+    __processThread = null;
+    __model = null;
+  }
+  
+  protected class ProcessThread extends Thread implements Serializable
+  {
+    /**
+     * @param updateIntervalFactor - controls the speed of the thread
+     * @param updateValueFactor - The value by which the 'value' from the 
+     *    model should be incremented for every cycle. Randomizes the increment
+     *    if updateValueFactor supplied is '0'.
+     */
+    ProcessThread(long updateIntervalFactor, long updateValueFactor)
+    {
+      _updateIntervalFactor = updateIntervalFactor;
+      _updateValueFactor = updateValueFactor;
+    }
+    
+    @Override
+    public void run()
+    {
+      try
+      {
+        //pu: Be in indeterminate mode for some time to start with
+        sleep(3000);
+        //pu: Take care to get out if we are the discarded thread upon endProcess()
+        while ( (__processThread == Thread.currentThread()) &&
+                (__model != null) &&
+                (__model.getValue() < __model.getMaximum()) 
+              )
+        {
+          long sleepFactor = Math.round(Math.random()*10);
+          long updatedValue = __model.getValue() + 
+            ((_updateValueFactor == 0) ? sleepFactor:_updateValueFactor);
+          long maximum = __model.getMaximum();
+          if (updatedValue > maximum)
+          {
+            updatedValue = maximum;
+          }
+          __model.setValue(updatedValue);
+          sleep(sleepFactor * _updateIntervalFactor);
+        }
+      }
+      catch (InterruptedException ie)
+      {
+        _LOG.log(Level.WARNING, "Background task thread interrupted", ie);
+      }
+      __model = null;
+    }
+    private long _updateIntervalFactor;
+    private long _updateValueFactor;
+  }
+  
+  protected volatile DefaultBoundedRangeModel __model;
+  protected volatile ProcessThread __processThread;
+
+  static private final Logger _LOG = Logger.getLogger(
+    ProgressBean.class.getName());
+
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ProgressStepsBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ProgressStepsBean.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ProgressStepsBean.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ProgressStepsBean.java Thu Jun 28 00:19:04 2007
@@ -0,0 +1,95 @@
+/*
+ *  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.IOException;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.trinidad.event.PollEvent;
+import org.apache.myfaces.trinidad.model.DefaultBoundedRangeModel;
+
+/**
+ * Bean for progress steps demos.
+ *
+ * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-demo/src/main/java/oracle/adfdemo/view/faces/ProgressStepsBean.java#1 $) $Date: 16-aug-2005.15:12:28 $
+ */
+public class ProgressStepsBean extends ProgressBean 
+{
+  public List<String> getProgressSteps()
+  {
+    return _PROGRESS_STEPS;
+  }
+  
+  public void onPoll(PollEvent event)
+  {
+    if ( __model != null && (__model.getMaximum() <= __model.getValue()) )
+    {
+      //pu: This means the background task is complete.
+      //  End the task and navigate off to a different page.
+      endProcess();
+      try
+      {
+        ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
+        ec.redirect("../components/progressEnd.jspx?taskStatus=completed");
+      }
+      catch(IOException ioe)
+      {
+        _LOG.log(Level.WARNING, "Could not redirect", ioe);
+      }
+      catch (RuntimeException re)
+      {
+        _LOG.log(Level.SEVERE, "Could not redirect", re);
+        throw re;
+      }
+    }
+  }
+  
+  @Override
+  protected void prepare()
+  {
+    __model = new DefaultBoundedRangeModel(-1, 6);
+    //pu: simulate asynchronous model updates on a different thread
+    __processThread = new ProcessThread(1500, 1);
+    __processThread.start();
+  }
+  
+  static private List<String> _PROGRESS_STEPS;
+  
+  static private final Logger _LOG = Logger.getLogger(
+    ProgressStepsBean.class.getName());
+  
+  static
+  {
+    _PROGRESS_STEPS = new ArrayList<String>();
+    _PROGRESS_STEPS.add("Checking for latest version");
+    _PROGRESS_STEPS.add("Checking available disk space");
+    _PROGRESS_STEPS.add("Copying files");
+    _PROGRESS_STEPS.add("Analyzing dependencies");
+    _PROGRESS_STEPS.add("Install in progress");
+    _PROGRESS_STEPS.add("Building icons and shortcuts");
+  }
+
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ReorderTest.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ReorderTest.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ReorderTest.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ReorderTest.java Thu Jun 28 00:19:04 2007
@@ -0,0 +1,84 @@
+/*
+ *  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.List;
+import javax.faces.component.UIComponent;
+import javax.faces.event.ActionEvent;
+import org.apache.myfaces.trinidad.component.core.output.CoreOutputText;
+
+public class ReorderTest
+{
+  public void setPanel(UIComponent panel)
+  {
+    _panel = panel;
+  }
+
+  public UIComponent getPanel()
+  {
+    return _panel;
+  }
+
+  @SuppressWarnings("unchecked")
+  public void add(ActionEvent event)
+  {
+    List<UIComponent> children = _panel.getChildren();
+    CoreOutputText output = new CoreOutputText();
+    output.setValue("Item " + (children.size() + 1));
+    children.add(0, output);
+  }
+
+  @SuppressWarnings("unchecked")
+  public void remove(ActionEvent event)
+  {
+    List<UIComponent> children = _panel.getChildren();
+    children.remove(children.size() - 1);
+  }
+
+  @SuppressWarnings("unchecked")
+  public void removeFirst(ActionEvent event)
+  {
+    List<UIComponent> children = _panel.getChildren();
+    children.remove(0);
+  }
+
+  @SuppressWarnings("unchecked")
+  public void rotate(ActionEvent event)
+  {
+    List<UIComponent> children = _panel.getChildren();
+    UIComponent o = children.get(0);
+    children.remove(0);
+    children.add(o);
+  }
+
+  public void removeSeparator(ActionEvent event)
+  {
+    _panel.getFacets().remove("separator");
+  }
+
+  @SuppressWarnings("unchecked")
+  public void setSeparator(ActionEvent event)
+  {
+    CoreOutputText output = new CoreOutputText();
+    output.setValue("New Separator");
+    _panel.getFacets().put("separator", output);
+  }
+  
+  private UIComponent _panel;
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/SelectItemTestBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/SelectItemTestBean.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/SelectItemTestBean.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/SelectItemTestBean.java Thu Jun 28 00:19:04 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;
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TableBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TableBean.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TableBean.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TableBean.java Thu Jun 28 00:19:04 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;
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ToggleBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ToggleBean.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ToggleBean.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ToggleBean.java Thu Jun 28 00:19:04 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;
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeModelAdapter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeModelAdapter.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeModelAdapter.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeModelAdapter.java Thu Jun 28 00:19:04 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();
+  }
+  
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeNodeImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeNodeImpl.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeNodeImpl.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/TreeNodeImpl.java Thu Jun 28 00:19:04 2007
@@ -0,0 +1,85 @@
+/*
+ *  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: adfrt/faces/adf-faces-demo/src/main/java/oracle/adfdemo/view/faces/TreeNodeImpl.java#1 $) $Date: 16-aug-2005.15:12:29 $
+ */
+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;
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBean.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBean.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBean.java Thu Jun 28 00:19:04 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;
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBeanState.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBeanState.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBeanState.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/UIBeanState.java Thu Jun 28 00:19:04 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;
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/change/ChangeBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/change/ChangeBean.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/change/ChangeBean.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/change/ChangeBean.java Thu Jun 28 00:19:04 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: adfrt/faces/adf-faces-demo/src/main/java/oracle/adfdemo/view/faces/change/ChangeBean.java#1 $) $Date: 16-aug-2005.15:12:29 $
+ */
+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());
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/CompositeTest.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/CompositeTest.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/CompositeTest.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/CompositeTest.java Thu Jun 28 00:19:04 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";
+    }
+  }
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java Thu Jun 28 00:19:04 2007
@@ -0,0 +1,253 @@
+/*
+ *  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>
+ */
+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;
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java Thu Jun 28 00:19:04 2007
@@ -0,0 +1,256 @@
+/*
+ *  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>
+ */
+public class DateFieldAsRenderer extends Renderer
+{
+  @SuppressWarnings("unchecked")
+  @Override
+  public void decode(FacesContext context, UIComponent component)
+  {
+    _addChildren(context, component);
+
+    Map<String, Object> 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;
+  }
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldTag.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldTag.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldTag.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldTag.java Thu Jun 28 00:19:04 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;
+  }
+}

Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ConvertSSNTag.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ConvertSSNTag.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ConvertSSNTag.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ConvertSSNTag.java Thu Jun 28 00:19:04 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;
+  }
+}



Mime
View raw message