You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2008/06/04 05:38:00 UTC
svn commit: r662966 [2/3] - in
/myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk:
core12/src/main/resources/META-INF/ sandbox/core12/src/
sandbox/core12/src/main/ sandbox/core12/src/main/conf/
sandbox/core12/src/main/conf/ME...
Added: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIConversation.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIConversation.java?rev=662966&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIConversation.java (added)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIConversation.java Tue Jun 3 20:37:59 2008
@@ -0,0 +1,77 @@
+/*
+ * 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.custom.conversation;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.IOException;
+
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+import javax.faces.component.UIComponent;
+
+/**
+ * puts a bean into the conversation context
+ *
+ * add a bean under context control
+ *
+ * @author imario@apache.org
+ */
+public class UIConversation extends AbstractConversationComponent
+{
+ private final static Log log = LogFactory.getLog(UIConversation.class);
+
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.Conversation";
+
+ public void encodeBegin(FacesContext context) throws IOException
+ {
+ super.encodeBegin(context);
+
+ UIComponent cmp = getParent();
+ if (cmp instanceof UIStartConversation)
+ {
+ // start conversation should to the work
+ return;
+ }
+
+ if (getName() == null)
+ {
+ throw new IllegalArgumentException("conversation name (attribute name=) required if used outside of startConversation tag");
+ }
+
+ elevateBean(context, getName(), getBeanBinding());
+ }
+
+ ValueBinding getBeanBinding()
+ {
+ return getValueBinding("value");
+ }
+
+ public static void elevateBean(FacesContext context, String conversationName, ValueBinding valueBinding)
+ {
+ Conversation conversation = ConversationManager.getInstance().getConversation(conversationName);
+ if (conversation == null)
+ {
+ log.debug("no conversation named '" + conversationName + "' running - can't elevate bean '" + valueBinding.getExpressionString());
+ return;
+ }
+ ConversationManager.getInstance().getConversationBeanElevator().elevateBean(context, conversation, valueBinding);
+ }
+}
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIConversation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIConversation.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIEndConversation.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIEndConversation.java?rev=662966&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIEndConversation.java (added)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIEndConversation.java Tue Jun 3 20:37:59 2008
@@ -0,0 +1,221 @@
+/*
+ * 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.custom.conversation;
+
+import org.apache.myfaces.shared_tomahawk.util.StringUtils;
+
+import javax.faces.component.UICommand;
+import javax.faces.context.FacesContext;
+import javax.faces.el.MethodBinding;
+import javax.faces.el.ValueBinding;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+
+/**
+ * end a conversation
+ *
+ * @author imario@apache.org
+ */
+public class UIEndConversation extends AbstractConversationComponent
+{
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.EndConversation";
+
+ private String onOutcome;
+ private String errorOutcome;
+ private Boolean restart;
+ private MethodBinding restartAction;
+
+ private boolean inited = false;
+
+ /*
+ public static class ConversationEndAction extends AbstractConversationActionListener
+ {
+ public void doConversationAction(AbstractConversationComponent abstractConversationComponent)
+ {
+ ConversationManager.getInstance().registerEndConversation(getConversationName());
+ }
+ }
+ */
+
+ public void encodeBegin(FacesContext context) throws IOException
+ {
+ super.encodeBegin(context);
+
+ UICommand command = ConversationUtils.findParentCommand(this);
+ if (command != null)
+ {
+ if (!inited)
+ {
+ /*
+ ConversationEndAction actionListener = new ConversationEndAction();
+ actionListener.setConversationName(getName());
+ command.addActionListener(actionListener);
+ */
+ MethodBinding original = command.getAction();
+ command.setAction(new EndConversationMethodBindingFacade(
+ getName(),
+ getOnOutcomes(),
+ original,
+ getErrorOutcome(),
+ getRestart(),
+ getRestartAction()));
+ inited = true;
+ }
+ }
+ else
+ {
+ ConversationUtils.endAndRestartConversation(context,
+ getName(),
+ getRestart(),
+ getRestartAction());
+ }
+ }
+
+ private Collection getOnOutcomes()
+ {
+ String onOutcome = getOnOutcome();
+ if (onOutcome == null || onOutcome.trim().length() < 1)
+ {
+ return null;
+ }
+
+ return Arrays.asList(StringUtils.trim(StringUtils.splitShortString(onOutcome, ',')));
+ }
+
+ public void restoreState(FacesContext context, Object state)
+ {
+ Object[] states = (Object[]) state;
+ super.restoreState(context, states[0]);
+ inited = ((Boolean) states[1]).booleanValue();
+ onOutcome = (String) states[2];
+ errorOutcome = (String) states[3];
+ restart = (Boolean) states[4];
+ restartAction = (MethodBinding) restoreAttachedState(context, states[5]);
+ }
+
+ public Object saveState(FacesContext context)
+ {
+ return new Object[]
+ {
+ super.saveState(context),
+ inited ? Boolean.TRUE : Boolean.FALSE,
+ onOutcome,
+ errorOutcome,
+ restart,
+ saveAttachedState(context, restartAction)
+ };
+ }
+
+ /**
+ * end the conversation only if the action outcome matches the given onOutcome.
+ *
+ * This can be a comma separated list.
+ *
+ * @JSFProperty
+ * @return
+ */
+ public String getOnOutcome()
+ {
+ if (onOutcome != null)
+ {
+ return onOutcome;
+ }
+ ValueBinding vb = getValueBinding("onOutcome");
+ if (vb == null)
+ {
+ return null;
+ }
+ return (String) vb.getValue(getFacesContext());
+ }
+
+ public void setOnOutcome(String onOutcome)
+ {
+ this.onOutcome = onOutcome;
+ }
+
+ /**
+ * on exception use the given outcome for further navigation
+ *
+ * @JSFProperty
+ * @return
+ */
+ public String getErrorOutcome()
+ {
+ if (errorOutcome != null)
+ {
+ return errorOutcome;
+ }
+ ValueBinding vb = getValueBinding("errorOutcome");
+ if (vb == null)
+ {
+ return null;
+ }
+ return (String) vb.getValue(getFacesContext());
+ }
+
+ public void setErrorOutcome(String errorOutcome)
+ {
+ this.errorOutcome = errorOutcome;
+ }
+
+ /**
+ * true|false|valueBinding - true if the conversation should be restarted immediately
+ *
+ * @JSFProperty
+ * @return
+ */
+ public Boolean getRestart()
+ {
+ if (restart != null)
+ {
+ return restart;
+ }
+ ValueBinding vb = getValueBinding("restart");
+ if (vb == null)
+ {
+ return null;
+ }
+ return (Boolean) vb.getValue(getFacesContext());
+ }
+
+ public void setRestart(Boolean restart)
+ {
+ this.restart = restart;
+ }
+
+ /**
+ * the action which should be called in case of a restart
+ *
+ * @JSFProperty
+ * methodSignature = "java.lang.String"
+ * returnSignature = "void"
+ * stateHolder = "true"
+ * @return
+ */
+ public MethodBinding getRestartAction()
+ {
+ return restartAction;
+ }
+
+ public void setRestartAction(MethodBinding restartAction)
+ {
+ this.restartAction = restartAction;
+ }
+}
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIEndConversation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIEndConversation.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java?rev=662966&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java (added)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java Tue Jun 3 20:37:59 2008
@@ -0,0 +1,195 @@
+/*
+ * 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.custom.conversation;
+
+import org.apache.myfaces.custom.redirectTracker.RedirectTrackerManager;
+
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+import java.io.IOException;
+
+/**
+ * <p>
+ * Ensures a named conversation is running
+ * </p>
+ * <p>
+ * check if a conversation is active.
+ * </p>
+ * <p>
+ * The way this is done here is sub-optimal, once we are on jsf 1.2 it should be possible to
+ * check this before ANY rendering - and maybe to invoke a navigation then
+ * </p>
+ *
+ * @JSFJspProperty name="action" longDesc = "the action which should be called in case of a not running conversation"
+ *
+ * @author imario@apache.org
+ */
+public class UIEnsureConversation extends AbstractConversationComponent
+{
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.EnsureConversation";
+
+ private String redirectTo;
+ private Boolean preCheck;
+
+ public void encodeBegin(FacesContext context) throws IOException
+ {
+ super.encodeBegin(context);
+
+ checkConversation(context, getName());
+ }
+
+ public void decode(FacesContext context)
+ {
+ super.decode(context);
+
+ try
+ {
+ checkConversation(context, getName());
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void restoreState(FacesContext context, Object state)
+ {
+ Object[] states = (Object[]) state;
+
+ super.restoreState(context, states[0]);
+ redirectTo = (String) states[1];
+ preCheck = (Boolean) states[2];
+ }
+
+ public Object saveState(FacesContext context)
+ {
+ return new Object[]
+ {
+ super.saveState(context),
+ redirectTo,
+ preCheck
+ };
+ }
+
+ protected void checkConversation(FacesContext context, String name) throws IOException
+ {
+ ConversationManager conversationManager = ConversationManager.getInstance();
+
+ if (Boolean.TRUE.equals(preCheck))
+ {
+ String actionResult = (String) getAction().invoke(context, null);
+ if (actionResult == null)
+ {
+ // no further action, maybe the user started a conversation
+ return;
+ }
+
+ conversationManager.getMessager().setConversationNotActive(context, getName());
+ return;
+ }
+ else if (!conversationManager.hasConversation(name))
+ {
+ if (getAction() != null)
+ {
+ String actionResult = (String) getAction().invoke(context, null);
+ if (actionResult == null)
+ {
+ // no further action, maybe the user started a conversation
+ return;
+ }
+ conversationManager.getMessager().setConversationNotActive(context, getName());
+
+ // hopefully the user configured the navigation as redirect ...
+ context.getApplication().getNavigationHandler().handleNavigation(context, null, actionResult);
+ }
+ else
+ {
+ conversationManager.getMessager().setConversationNotActive(context, getName());
+
+ String actionUrl = context.getApplication().getViewHandler().getActionURL(
+ context, getRedirectTo());
+ String encodedActionUrl = context.getExternalContext().encodeActionURL(actionUrl);
+
+ // XXX: figure out a way to avoid this ==>
+ RedirectTrackerManager manager = RedirectTrackerManager.getInstance(context);
+ if (manager != null)
+ {
+ encodedActionUrl = manager.trackRedirect(context, encodedActionUrl);
+ }
+ // XXX: figure out a way to avoid this <==
+
+ context.getExternalContext().redirect(encodedActionUrl);
+ }
+
+ return;
+ }
+ }
+
+ /**
+ * redirect to the given view if the conversation is not running
+ *
+ * @JSFProperty
+ * @return
+ */
+ public String getRedirectTo()
+ {
+ if (redirectTo != null)
+ {
+ return redirectTo;
+ }
+ ValueBinding vb = getValueBinding("redirectTo");
+ if (vb == null)
+ {
+ return null;
+ }
+ return (String) vb.getValue(getFacesContext());
+ }
+
+ public void setRedirectTo(String redirectTo)
+ {
+ this.redirectTo = redirectTo;
+ }
+
+ /**
+ * Delegate the check to the action method at all. The user has to check if
+ * a conversation is running. A action method is mandatory.
+ *
+ * @JSFProperty
+ * @return
+ */
+ public Boolean getPreCheck()
+ {
+ if (preCheck != null)
+ {
+ return preCheck;
+ }
+ ValueBinding vb = getValueBinding("preCheck");
+ if (vb == null)
+ {
+ return null;
+ }
+ return (Boolean) vb.getValue(getFacesContext());
+ }
+
+ public void setPreCheck(Boolean preCheck)
+ {
+ this.preCheck = preCheck;
+ }
+
+}
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UISeparateConversationContext.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UISeparateConversationContext.java?rev=662966&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UISeparateConversationContext.java (added)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UISeparateConversationContext.java Tue Jun 3 20:37:59 2008
@@ -0,0 +1,83 @@
+/*
+ * 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.custom.conversation;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
+
+/**
+ * Separates the current context from the children. e.g. commandLinks will start a
+ * new conversation context
+ *
+ * separate the current context from the to be rendered children.
+ * E.g. when you render commandLinks they will start a new conversationContext
+ *
+ *
+ * @author imario@apache.org
+ */
+public class UISeparateConversationContext extends UIComponentBase
+{
+ public static final String COMPONENT_FAMILY = "javax.faces.Component";
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.SeparateConversationContext";
+
+ private final static ThreadLocal inSeperationMode = new ThreadLocal();
+
+ public static void setInSeparationMode(boolean seperationMode)
+ {
+ inSeperationMode.set(seperationMode?Boolean.TRUE:Boolean.FALSE);
+ }
+
+ public static boolean isInSeparationMode()
+ {
+ return Boolean.TRUE.equals(inSeperationMode.get());
+ }
+
+ public void encodeBegin(FacesContext context) throws IOException
+ {
+ super.encodeBegin(context);
+
+ setInSeparationMode(true);
+ }
+
+ public void encodeChildren(FacesContext context) throws IOException
+ {
+ try
+ {
+ RendererUtils.renderChildren(context, this);
+ }
+ finally
+ {
+ setInSeparationMode(false);
+ }
+ }
+
+ public boolean getRendersChildren()
+ {
+ return true;
+ }
+
+ public String getFamily()
+ {
+ return COMPONENT_FAMILY;
+ }
+}
\ No newline at end of file
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UISeparateConversationContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UISeparateConversationContext.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIStartConversation.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIStartConversation.java?rev=662966&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIStartConversation.java (added)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIStartConversation.java Tue Jun 3 20:37:59 2008
@@ -0,0 +1,206 @@
+/*
+ * 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.custom.conversation;
+
+import javax.faces.component.UICommand;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+import javax.faces.el.VariableResolver;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * start a conversation
+ *
+ *
+ * @author imario@apache.org
+ */
+public class UIStartConversation extends AbstractConversationComponent
+{
+ public final static String COMPONENT_TYPE = "org.apache.myfaces.StartConversation";
+ private final static String CONVERSATION_SYSTEM_SETUP = "org.apache.myfaces.ConversationSystemSetup";
+
+ private boolean inited;
+ private Boolean persistence;
+
+ public static class ConversationStartAction extends AbstractConversationActionListener
+ {
+ private boolean persistence;
+ private List beanToElevate;
+
+ public void doConversationAction(AbstractConversationComponent abstractConversationComponent)
+ {
+ ConversationManager conversationManager = ConversationManager.getInstance();
+ conversationManager.startConversation(getConversationName(), isPersistence());
+
+ if (beanToElevate != null)
+ {
+ FacesContext context = FacesContext.getCurrentInstance();
+
+ Iterator iterBeans = beanToElevate.iterator();
+ while (iterBeans.hasNext())
+ {
+ String vb = (String) iterBeans.next();
+ UIConversation.elevateBean(
+ context,
+ getConversationName(),
+ context.getApplication().createValueBinding(vb));
+ }
+ }
+ }
+
+ public boolean isPersistence()
+ {
+ return persistence;
+ }
+
+ public void setPersistence(boolean persistence)
+ {
+ this.persistence = persistence;
+ }
+
+ public void addBeanToElevate(String beanBinding)
+ {
+ if (beanToElevate == null)
+ {
+ beanToElevate = new ArrayList();
+ }
+ beanToElevate.add(beanBinding);
+ }
+
+
+ public Object saveState(FacesContext context)
+ {
+ return new Object[]
+ {
+ super.saveState(context),
+ Boolean.valueOf(persistence),
+ beanToElevate
+ };
+ }
+
+ public void restoreState(FacesContext context, Object state)
+ {
+ Object[] states = (Object[]) state;
+ super.restoreState(context, states[0]);
+ persistence = ((Boolean) states[1]).booleanValue();
+ beanToElevate = (List) states[2];
+ }
+ }
+
+ public void encodeEnd(FacesContext context) throws IOException
+ {
+ super.encodeEnd(context);
+
+ setupConversationSystem(context);
+
+ UICommand command = ConversationUtils.findParentCommand(this);
+ if (command != null)
+ {
+ if (!inited)
+ {
+ ConversationStartAction actionListener = new ConversationStartAction();
+ actionListener.setConversationName(getName());
+ actionListener.setPersistence(toBoolean(getPersistence()));
+ command.addActionListener(actionListener);
+
+ Iterator iterChildren = getChildren().iterator();
+ while (iterChildren.hasNext())
+ {
+ Object child = iterChildren.next();
+ if (child instanceof UIConversation)
+ {
+ UIConversation conversation = (UIConversation) child;
+ actionListener.addBeanToElevate(conversation.getBeanBinding().getExpressionString());
+ }
+ }
+
+ inited = true;
+ }
+ }
+ else
+ {
+ ConversationManager conversationManager = ConversationManager.getInstance();
+ conversationManager.startConversation(getName(), toBoolean(getPersistence()));
+ }
+ }
+
+ protected boolean toBoolean(Boolean bool)
+ {
+ if (bool != null)
+ {
+ return bool.booleanValue();
+ }
+ return false;
+ }
+
+ protected void setupConversationSystem(FacesContext context)
+ {
+ if (Boolean.TRUE.equals(context.getExternalContext().getApplicationMap().get(CONVERSATION_SYSTEM_SETUP)))
+ {
+ return;
+ }
+
+ VariableResolver originalVR = context.getApplication().getVariableResolver();
+ context.getApplication().setVariableResolver(new ConversationVariableResolver(originalVR));
+
+ context.getExternalContext().getApplicationMap().put(CONVERSATION_SYSTEM_SETUP, Boolean.TRUE);
+ }
+
+ public void restoreState(FacesContext context, Object state)
+ {
+ Object[] states = (Object[]) state;
+ super.restoreState(context, states[0]);
+ inited = ((Boolean) states[1]).booleanValue();
+ persistence = (Boolean) states[2];
+ }
+
+ public Object saveState(FacesContext context)
+ {
+ return new Object[]
+ {
+ super.saveState(context),
+ inited?Boolean.TRUE:Boolean.FALSE,
+ persistence
+ };
+ }
+
+ /**
+ * true|false - if this conversation requires a persistence manager. Default: false
+ *
+ * @JSFProperty
+ * @return
+ */
+ public Boolean getPersistence()
+ {
+ if (persistence != null)
+ {
+ return persistence;
+ }
+ ValueBinding vb = getValueBinding("persistence");
+ return vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
+ }
+
+ public void setPersistence(Boolean persistence)
+ {
+ this.persistence = persistence;
+ }
+}
\ No newline at end of file
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIStartConversation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/conversation/UIStartConversation.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/AbstractHtmlFocus.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/AbstractHtmlFocus.java?rev=662966&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/AbstractHtmlFocus.java (added)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/AbstractHtmlFocus.java Tue Jun 3 20:37:59 2008
@@ -0,0 +1,101 @@
+package org.apache.myfaces.custom.focus2;
+
+import javax.faces.component.UIInput;
+import javax.faces.context.FacesContext;
+
+/**
+ * @JSFComponent
+ * name = "s:focus2"
+ * class = "org.apache.myfaces.custom.focus2.HtmlFocus"
+ * superClass = "org.apache.myfaces.custom.focus2.AbstractHtmlFocus"
+ * tagClass = "org.apache.myfaces.custom.focus2.HtmlFocusTag"
+ *
+ * @author Rogerio Pereira Araujo (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public abstract class AbstractHtmlFocus extends UIInput
+{
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.Focus2";
+ public static final String COMPONENT_FAMILY = "javax.faces.Output";
+ public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.Focus2";
+
+ public String getFamily()
+ {
+ return COMPONENT_FAMILY;
+ }
+
+ public AbstractHtmlFocus()
+ {
+ super.setRendererType(DEFAULT_RENDERER_TYPE);
+ }
+
+ /**
+ * Defines that the first element of the form should receive the
+ * focus by default
+ * (if the overrideFocusId-attribute is not specified, no error has
+ * been queued and the focus
+ * has not already been set).
+ *
+ * @JSFProperty
+ * defaultValue = "true"
+ */
+ public abstract boolean isFocusOnFirst();
+
+ /**
+ * Defines that the first element of the form with an associated error should
+ * receive the focus by default (if the override focus-id attribute wasn't set).
+ *
+ * @JSFProperty
+ * defaultValue = "true"
+ * @return
+ */
+ public abstract boolean isFocusOnError();
+
+ /**The id (locally in this naming container) of the component which
+ * should receive the focus.
+ * Overrides all other behaviour if set.
+ *
+ * @JSFProperty
+ */
+ public abstract String getOverrideFocusId();
+
+ /**
+ * Defines an id of a command-button or command-link that will be
+ * focussed and submitted when the enter-key is pressed.
+ *
+ * @JSFProperty
+ */
+ public abstract String getFocusAndSubmitOnEnter();
+
+ /**
+ * The client-id (fully specified as a concatenation of the id of
+ * this component and all naming container
+ * parent ids) of the component which receives the focus (works only if
+ * overrideFocusId hasn't been set and no error has been queued).
+ *
+ * The value will automatically be updated when the focus is changed.
+ *
+ * @JSFProperty
+ * @see javax.faces.component.UIInput#setValue(java.lang.Object)
+ */
+ public void setValue(Object value)
+ {
+ super.setValue(value);
+ }
+
+ public Object getValue()
+ {
+ return super.getValue();
+ }
+
+ public void updateModel(FacesContext context)
+ {
+ super.updateModel(context);
+ }
+
+ public void processValidators(FacesContext context)
+ {
+ super.processValidators(context);
+ }
+
+}
\ No newline at end of file
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/AbstractHtmlFocus.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/AbstractHtmlFocus.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/HtmlFocusRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/HtmlFocusRenderer.java?rev=662966&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/HtmlFocusRenderer.java (added)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/HtmlFocusRenderer.java Tue Jun 3 20:37:59 2008
@@ -0,0 +1,360 @@
+package org.apache.myfaces.custom.focus2;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
+import javax.faces.component.ContextCallback;
+/**
+ *
+ * @JSFRenderer
+ * renderKitId = "HTML_BASIC"
+ * family = "javax.faces.Output"
+ * type = "org.apache.myfaces.Focus2"
+ *
+ */
+public class HtmlFocusRenderer extends Renderer
+{
+
+ protected void setSubmittedValue(UIComponent component, Object value)
+ {
+ ((EditableValueHolder) component).setSubmittedValue(value);
+ }
+
+ public void decode(FacesContext context, UIComponent component)
+ {
+ super.decode(context, component);
+ }
+
+ public void encodeEnd(FacesContext context, UIComponent component)
+ throws IOException
+ {
+ HtmlFocus focus = (HtmlFocus) component;
+
+ String focusForId = getFocusForId(context, focus);
+
+ ResponseWriter writer = context.getResponseWriter();
+
+ writeForElementStore(context, component, focusForId);
+
+ startScript(component, writer);
+ if (focusForId != null && focusForId.length() > 0)
+ {
+ writeSetFocusScript(component, focusForId, writer);
+ }
+ String focusAndSubmitOnEnter = focus.getFocusAndSubmitOnEnter();
+ if (focusAndSubmitOnEnter != null && focusAndSubmitOnEnter.length() > 0)
+ {
+ UIComponent targetComponent = focus
+ .findComponent(focusAndSubmitOnEnter);
+ if (targetComponent == null)
+ throw new IllegalStateException("Button component for id :"
+ + focusAndSubmitOnEnter + " not found.");
+ writeSetDefaultButtonScript(component, targetComponent
+ .getClientId(context), context);
+ }
+ writeUpdateFocusScript(context, component);
+ endScript(writer);
+
+ }
+
+ private void writeUpdateFocusScript(FacesContext context,
+ UIComponent component) throws IOException
+ {
+
+ UIComponent formParent = getFormParent(component);
+
+ if (formParent == null)
+ throw new IllegalStateException("parent form for component: "
+ + component.getClientId(context) + " not found. ");
+
+ String compClientId = component.getClientId(context);
+ String formParentClientId = formParent.getClientId(context);
+
+ StringBuilder b = new StringBuilder();
+
+ b.append("\nfunction csDomTrackActiveElement(evt) {\n");
+ b.append(" if (evt && evt.target) { \n");
+ b.append(" if (evt.target == document) {\n");
+ b.append(" document.activeElement = null;\n");
+ b.append(" } else {\n");
+ b.append(" if (evt.target.type != 'submit') {\n");
+ b.append(" document.activeElement = evt.target; ;\n");
+ b.append(" }\n");
+ b.append(" }\n");
+ b.append(" }\n");
+ b.append("}\n");
+ b.append("if (document.addEventListener) { \n");
+ b
+ .append("document.addEventListener('focus',csDomTrackActiveElement,true);\n");
+ b.append("}\n");
+ b.append(" var csFocusParentForm =document.getElementById(\"").append(
+ formParentClientId).append("\");\n");
+ b
+ .append(" csFocusParentForm.csFocusSubmitSaver =csFocusParentForm.submit;\n");
+ b
+ .append(" csFocusParentForm.csFocusOnsubmitSaver =csFocusParentForm.onsubmit;\n");
+
+ b.append(" csFocusParentForm.submit=function() {\n");
+ transferId(compClientId, b);
+ b.append(" if(csFocusParentForm.csFocusSubmitSaver) ");
+ b.append(" return csFocusParentForm.csFocusSubmitSaver();\n");
+ b.append(" }\n");
+ b.append(" csFocusParentForm.onsubmit=function() {\n");
+ transferId(compClientId, b);
+ b.append(" if(csFocusParentForm.csFocusOnsubmitSaver) ");
+ b.append(" return csFocusParentForm.csFocusOnsubmitSaver();\n");
+ b.append(" }\n");
+
+ context.getResponseWriter().write(b.toString());
+ }
+
+ private void transferId(String compClientId, StringBuilder b)
+ {
+ b.append(" if(document.activeElement) {\n");
+ b
+ .append("document.getElementById(\"")
+ .append(compClientId)
+ .append(
+ "\").value=document.activeElement.id?document.activeElement.id:document.activeElement.name;\n");
+ b.append(" }\n");
+ }
+
+ private UIComponent getFormParent(UIComponent component)
+ {
+ UIComponent parent = component;
+
+ while (parent != null && !(parent instanceof UIForm))
+ {
+ parent = parent.getParent();
+ }
+
+ return parent;
+ }
+
+ private void writeForElementStore(FacesContext context,
+ UIComponent component, String currentFocusClientId)
+ throws IOException
+ {
+ ResponseWriter writer = context.getResponseWriter();
+ String clientId = component.getClientId(context);
+ writer.startElement("input", component);
+ writer.writeAttribute("type", "hidden", "type");
+ writer.writeAttribute("name", clientId, "clientId");
+ writer.writeAttribute("id", clientId, "clientId");
+ writer.writeAttribute("value", currentFocusClientId, "defaultFocusId");
+ writer.endElement("input");
+ }
+
+ private void writeSetFocusScript(UIComponent component, String clientId,
+ ResponseWriter writer) throws IOException
+ {
+ writer.writeText("setTimeout(\"document.getElementById('" + clientId
+ + "').focus()\", 100);", null);
+ }
+
+ private void writeSetDefaultButtonScript(UIComponent component,
+ String clientId, FacesContext context) throws IOException
+ {
+
+ String formClientId = getFormParent(component).getClientId(context);
+
+ StringBuilder b = new StringBuilder(3000);
+
+ b.append(" var csFocusKeyParentForm =document.getElementById(\"")
+ .append(formClientId).append("\");\n");
+ b
+ .append("\n\ncsFocusKeyParentForm.csFocusOnkeypressSaver =csFocusKeyParentForm.onkeypress;\n");
+
+ b.append("csFocusKeyParentForm.onkeypress=function(evt) {\n");
+ b.append(" var retValue = csSubmitOnEnter(evt,'" + formClientId
+ + "','" + clientId + "'); \n");
+ b.append(" if(csFocusKeyParentForm.csFocusOnkeypressSaver) {\n");
+ b
+ .append(" retValue =csFocusKeyParentForm.csFocusOnkeypressSaver(evt) && retValue;\n");
+ b.append(" }\n");
+ b.append(" return retValue;\n");
+ b.append("}\n");
+ b.append("\n");
+
+ b.append("function csGetKC(evt)\n");
+ b.append("{\n");
+ b.append("if(window.event)\n");
+ b.append(" return window.event.keyCode;\n");
+ b.append(" else if(evt)\n");
+ b.append(" return evt.which;\n");
+ b.append(" return -1;\n");
+ b.append("}\n\n");
+
+ b.append("function csSubmitOnEnter(evt,formId,buttonId)\n");
+ b.append("{\n");
+ b.append(" if(window.event!=(void 0))\n");
+ b.append(" evt=window.event;\n");
+ b.append(" var fromElement;\n");
+ b.append(" if(evt.srcElement==undefined)\n");
+ b.append(" fromElement=evt.target;\n");
+ b.append(" else\n");
+ b.append(" fromElement=evt.srcElement;\n");
+ b.append(" if(!fromElement) return true;\n");
+ b.append(" if(fromElement.tagName.toUpperCase()=='A') return true;\n");
+ b.append(" if((fromElement.tagName.toUpperCase()=='INPUT')&&\n");
+ b.append(" (fromElement.type!='submit')&&\n");
+ b.append(" (fromElement.type!='reset'))\n");
+ b.append(" {\n");
+ b.append(" if(csGetKC(evt)==13)\n");
+ b.append(" {\n");
+ b.append(" if(buttonId!=(void 0))\n");
+ b.append(" {\n");
+ b.append(" document.getElementById(buttonId).click();\n");
+ b.append(" }\n");
+ b.append(" return false;\n");
+ b.append(" }\n");
+ b.append(" }\n");
+ b.append(" return true;\n");
+ b.append("}\n");
+
+ context.getResponseWriter().writeText(b.toString(), null);
+ }
+
+ private void endScript(ResponseWriter writer) throws IOException
+ {
+ writer.writeText("/*]]>*/", null);
+ writer.endElement("script");
+ }
+
+ private void startScript(UIComponent component, ResponseWriter writer)
+ throws IOException
+ {
+ writer.startElement("script", component);
+ writer.writeAttribute("type", "text/javascript", null);
+ writer.writeText("/*<![CDATA[*/", null);
+ }
+
+ /**
+ *
+ * @param context
+ * @param focus
+ * @return
+ */
+ private String getFocusForId(FacesContext context, HtmlFocus focus)
+ {
+
+ //#1: override focus-id has been set
+ String forId = focus.getOverrideFocusId();
+ if (forId != null && forId.length() > 0)
+ {
+ UIComponent targetComponent = focus.findComponent(forId);
+
+ if (targetComponent == null)
+ {
+ throw new IllegalStateException("target-component for id :"
+ + forId + " not found.");
+ }
+ return targetComponent.getClientId(context);
+ }
+
+ //#2: error-messages have been queued
+ if (focus.isFocusOnError())
+ {
+ Iterator it = context.getMessages();
+ Iterator msgs = context.getClientIdsWithMessages();
+ if (msgs.hasNext())
+ {
+ String clientId = (String) msgs.next();
+ return clientId;
+ }
+ }
+
+ //#3: a value has already been submitted, take this one
+ String clientId = (String) focus.getValue();
+ if (clientId != null && clientId.length() > 0)
+ {
+ final StringHolder nextClientId = new StringHolder();
+ context.getViewRoot().invokeOnComponent(context, clientId,
+ new ContextCallback()
+ {
+
+ public void invokeContextCallback(FacesContext context,
+ UIComponent target)
+ {
+ String nextClientIdString = getNextValueHolder(
+ context, target);
+ if (nextClientIdString != null)
+ nextClientId.string = nextClientIdString;
+ }
+ });
+
+ if (nextClientId.string != null && nextClientId.string.length() > 0)
+ return nextClientId.string;
+
+ return clientId;
+ }
+
+ //#4: focus on the first (rendered) editable value holder
+ if (focus.isFocusOnFirst())
+ {
+ UIComponent comp = getFormParent(focus);
+ String firstClientId = getNextValueHolder(context, comp);
+ if (firstClientId != null)
+ return firstClientId;
+ }
+
+ return clientId;
+ }
+
+ private static class StringHolder
+ {
+ public String string;
+ }
+
+ private static String getNextValueHolder(FacesContext context,
+ UIComponent comp)
+ {
+
+ final StringHolder holder = new StringHolder();
+
+ TreeVisitor.traverseTree(context,
+ new TreeVisitor.TreeTraversalListener()
+ {
+
+ private int count = 0;
+
+ public boolean traverse(FacesContext context, int level,
+ UIComponent component)
+ {
+ if (count > 0)
+ {
+ if (!(component instanceof HtmlFocus)
+ && (component instanceof EditableValueHolder && component.isRendered())
+ //&& (!(component instanceof Field) || (component instanceof Field && isVisible(component)))
+ )
+ {
+ holder.string = component.getClientId(context);
+ return false;
+ }
+ }
+
+ count++;
+ return true;
+ }
+
+ private boolean isVisible(UIComponent component)
+ {
+ //Field field = (Field) component;
+ //return (("mutable".equals(field.getDisplay()) || "required"
+ // .equals(field.getDisplay()))
+ // && !field.isReadonly() && !field.isDisabled())
+ // && !"label".equals(field.getOnly());
+ return true;
+ }
+ }, comp);
+
+ return holder.string;
+ }
+
+}
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/HtmlFocusRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/HtmlFocusRenderer.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/TreeVisitor.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/TreeVisitor.java?rev=662966&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/TreeVisitor.java (added)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/TreeVisitor.java Tue Jun 3 20:37:59 2008
@@ -0,0 +1,92 @@
+package org.apache.myfaces.custom.focus2;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+public class TreeVisitor
+{
+
+ public static interface TreeTraversalListener
+ {
+
+ /**
+ * @param context
+ * @param level
+ * @param component
+ * @return false to stop traversal
+ */
+ boolean traverse(FacesContext context, int level, UIComponent component);
+ }
+
+ public static void traverseTree(FacesContext context,
+ TreeTraversalListener listener, UIComponent startingFrom)
+ {
+
+ int level = 0;
+
+ if (!listener.traverse(context, level, startingFrom))
+ return;
+
+ if (!recurseDown(context, listener, startingFrom, level + 1))
+ return;
+
+ recurseUp(context, listener, startingFrom, level - 1);
+ }
+
+ private static boolean recurseDown(FacesContext context,
+ TreeTraversalListener listener, UIComponent comp, int level)
+ {
+ Iterator it = comp.getFacetsAndChildren();
+
+ while (it.hasNext())
+ {
+ UIComponent child = (UIComponent) it.next();
+ if (!listener.traverse(context, level, child))
+ return false;
+ if (!recurseDown(context, listener, child, level + 1))
+ return false;
+ }
+
+ return true;
+ }
+
+ private static boolean recurseUp(FacesContext context,
+ TreeTraversalListener listener, UIComponent comp, int level)
+ {
+ UIComponent parent = comp.getParent();
+ if (parent != null)
+ {
+ Iterator siblingIt = parent.getFacetsAndChildren();
+
+ boolean traverseNow = false;
+
+ while (siblingIt.hasNext())
+ {
+ if (traverseNow)
+ {
+ UIComponent nextSibling = (UIComponent) siblingIt.next();
+
+ if (!listener.traverse(context, level, nextSibling))
+ return false;
+
+ if (!recurseDown(context, listener, nextSibling, level + 1))
+ return false;
+ }
+ else
+ {
+ UIComponent potSibling = (UIComponent) siblingIt.next();
+
+ if (potSibling == comp)
+ {
+ traverseNow = true;
+ }
+ }
+ }
+
+ return recurseUp(context, listener, parent, level - 1);
+ }
+ return false;
+ }
+}
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/TreeVisitor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/focus2/TreeVisitor.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/requestParameterProvider/RequestParameterResponseWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/requestParameterProvider/RequestParameterResponseWrapper.java?rev=662966&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/requestParameterProvider/RequestParameterResponseWrapper.java (added)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/requestParameterProvider/RequestParameterResponseWrapper.java Tue Jun 3 20:37:59 2008
@@ -0,0 +1,241 @@
+/*
+ * 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.custom.requestParameterProvider;
+
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Locale;
+
+/**
+ * @author Thomas Obereder
+ * @version 30.04.2006 14:40:05
+ */
+public class RequestParameterResponseWrapper implements HttpServletResponse
+{
+ protected HttpServletResponse original;
+ private String contentType;
+
+ public RequestParameterResponseWrapper(HttpServletResponse httpServletResponse)
+ {
+ //super();
+ this.original = httpServletResponse;
+ }
+
+ /**
+ * @param url the url to encode
+ * @return wrappedResponse.encodeUrl(url);
+ */
+ public String encodeURL(String url)
+ {
+ if(url == null)
+ return null;
+
+ url = RequestParameterProviderManager.getInstance().encodeAndAttachParameters(url);
+
+ return this.original.encodeURL(url);
+ }
+
+
+ /**
+ * @param url the url to encode
+ * @return wrappedResponse.encodeUrl(url);
+ */
+
+ public String encodeRedirectURL(String url)
+ {
+ return this.original.encodeRedirectURL(url);
+ }
+
+
+ /**
+ * @deprecated uses deprecated Method.
+ * @param url the url to encode
+ * @return wrappedResponse.encodeUrl(url);
+ */
+ public String encodeUrl(String url)
+ {
+ return this.original.encodeUrl(url);
+ }
+
+
+ /**
+ * @deprecated uses deprecated Method.
+ * @param url the url to encode
+ * @return wrappedResponse.encodeUrl(url);
+ */
+ public String encodeRedirectUrl(String url)
+ {
+ return this.original.encodeRedirectUrl(url);
+ }
+
+
+ //simple delegation
+
+ public void addCookie(Cookie cookie)
+ {
+ this.original.addCookie(cookie);
+ }
+
+
+ public boolean containsHeader(String header)
+ {
+ return this.original.containsHeader(header);
+ }
+
+ public void sendError(int i, String string) throws IOException
+ {
+ this.original.sendError(i, string);
+ }
+
+ public void sendError(int i) throws IOException
+ {
+ this.original.sendError(i);
+ }
+
+ public void sendRedirect(String string) throws IOException
+ {
+ this.original.sendRedirect(string);
+ }
+
+ public void setDateHeader(String string, long l)
+ {
+ this.original.setDateHeader(string, l);
+ }
+
+ public void addDateHeader(String string, long l)
+ {
+ this.original.addDateHeader(string, l);
+ }
+
+ public void setHeader(String string, String string1)
+ {
+ this.original.setHeader(string, string1);
+ }
+
+ public void addHeader(String string, String string1)
+ {
+ this.original.addHeader(string, string1);
+ }
+
+ public void setIntHeader(String string, int i)
+ {
+ this.original.setIntHeader(string, i);
+ }
+
+ public void addIntHeader(String string, int i)
+ {
+ this.original.addIntHeader(string, i);
+ }
+
+ public void setStatus(int i)
+ {
+ this.original.setStatus(i);
+ }
+
+
+ /**
+ * @deprecated uses deprecated Method
+ */
+
+ public void setStatus(int i, String string)
+ {
+ this.original.setStatus(i, string);
+ }
+
+ public String getCharacterEncoding()
+ {
+ return this.original.getCharacterEncoding();
+ }
+
+ public ServletOutputStream getOutputStream() throws IOException
+ {
+ return this.original.getOutputStream();
+ }
+
+ public PrintWriter getWriter() throws IOException
+ {
+ return this.original.getWriter();
+ }
+
+ public void setContentLength(int i)
+ {
+ this.original.setContentLength(i);
+ }
+
+ public void setContentType(String string)
+ {
+ this.contentType = string;
+ this.original.setContentType(string);
+ }
+
+ public void setBufferSize(int i)
+ {
+ this.original.setBufferSize(i);
+ }
+
+ public int getBufferSize()
+ {
+ return this.original.getBufferSize();
+ }
+
+ public void flushBuffer() throws IOException
+ {
+ this.original.flushBuffer();
+ }
+
+ public void resetBuffer()
+ {
+ this.original.resetBuffer();
+ }
+
+ public boolean isCommitted()
+ {
+ return this.original.isCommitted();
+ }
+
+ public void reset()
+ {
+ this.original.reset();
+ }
+
+ public void setLocale(Locale locale)
+ {
+ this.original.setLocale(locale);
+ }
+
+ public Locale getLocale()
+ {
+ return this.original.getLocale();
+ }
+
+ public String getContentType()
+ {
+ return contentType;
+ }
+
+ public void setCharacterEncoding(String s)
+ {
+ this.original.setCharacterEncoding(s);
+ }
+}
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/requestParameterProvider/RequestParameterResponseWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/requestParameterProvider/RequestParameterResponseWrapper.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/AbstractSuggestAjax.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/AbstractSuggestAjax.java?rev=662966&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/AbstractSuggestAjax.java (added)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/AbstractSuggestAjax.java Tue Jun 3 20:37:59 2008
@@ -0,0 +1,156 @@
+/*
+ * 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.custom.suggestajax;
+
+import java.io.IOException;
+
+import javax.el.MethodExpression;
+import javax.faces.context.FacesContext;
+import javax.faces.render.Renderer;
+
+import org.apache.myfaces.component.LocationAware;
+import org.apache.myfaces.component.html.ext.HtmlInputText;
+import org.apache.myfaces.custom.ajax.api.AjaxComponent;
+import org.apache.myfaces.custom.ajax.api.AjaxRenderer;
+
+/**
+ *
+ * @JSFComponent
+ * configExcluded = "true"
+ * class = "org.apache.myfaces.custom.suggestajax.SuggestAjax"
+ * superClass = "org.apache.myfaces.custom.suggestajax.AbstractSuggestAjax"
+ * tagClass = "org.apache.myfaces.custom.suggestajax.SuggestAjaxTag"
+ * tagSuperclass = "org.apache.myfaces.custom.suggestajax.AbstractSuggestAjaxTag"
+ * @author Gerald Muellan
+ * Date: 25.03.2006
+ * Time: 17:06:04
+ */
+public abstract class AbstractSuggestAjax extends HtmlInputText
+ implements AjaxComponent, LocationAware
+{
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.SuggestAjax";
+ public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.SuggestAjax";
+
+ private MethodExpression _suggestedItemsMethod;
+
+ public Object saveState(FacesContext context)
+ {
+ Object[] values = new Object[4];
+ values[0] = super.saveState(context);
+ values[1] = saveAttachedState(context, _suggestedItemsMethod);
+
+ return values;
+ }
+
+ public void restoreState(FacesContext context, Object state)
+ {
+ Object values[] = (Object[])state;
+ super.restoreState(context, values[0]);
+ _suggestedItemsMethod = (MethodExpression) restoreAttachedState(context, values[1]);
+ }
+
+ public void encodeAjax(FacesContext context)
+ throws IOException
+ {
+ if (context == null) throw new NullPointerException("context");
+ if (!isRendered()) return;
+ Renderer renderer = getRenderer(context);
+ if (renderer != null && renderer instanceof AjaxRenderer)
+ {
+ ((AjaxRenderer) renderer).encodeAjax(context, this);
+ }
+ }
+
+ public void decodeAjax(FacesContext context)
+ {
+
+ }
+
+ public void encodeChildren(FacesContext context) throws IOException
+ {
+ super.encodeChildren(context);
+ }
+
+ public void setSuggestedItemsMethod(MethodExpression suggestedItemsMethod)
+ {
+ _suggestedItemsMethod = suggestedItemsMethod;
+ }
+
+ /**
+ * Reference to the method which returns the suggested items
+ *
+ * @JSFProperty
+ * inheritedTag = "true"
+ * @return
+ */
+ public MethodExpression getSuggestedItemsMethod()
+ {
+ return _suggestedItemsMethod;
+ }
+
+ /**
+ * optional attribute to identify the max size of suggested Values.
+ * If specified in tableSuggestAjax, paginator functionality is used.
+ *
+ * @JSFProperty
+ * inheritedTag = "true"
+ * @return
+ */
+ public abstract Integer getMaxSuggestedItems();
+
+
+ /**
+ * Force the charset of the Response
+ *
+ * @JSFProperty
+ * literalOnly = "true"
+ * @return
+ */
+ public abstract String getCharset();
+
+ /**
+ * An alternate location to find javascript resources.
+ * If no values is specified, javascript will be loaded
+ * from the resources directory using AddResource and
+ * ExtensionsFilter.
+ *
+ * @JSFProperty
+ */
+ public abstract String getJavascriptLocation();
+
+ /**
+ * An alternate location to find image resources. If no
+ * values is specified, images will be loaded from the
+ * resources directory using AddResource and ExtensionsFilter.
+ *
+ * @JSFProperty
+ */
+ public abstract String getImageLocation();
+
+ /**
+ * An alternate location to find stylesheet resources. If no
+ * values is specified, stylesheets will be loaded from the
+ * resources directory using AddResource and ExtensionsFilter.
+ *
+ * @JSFProperty
+ */
+ public abstract String getStyleLocation();
+
+
+}
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/AbstractSuggestAjax.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/AbstractSuggestAjax.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/AbstractSuggestAjaxTag.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/AbstractSuggestAjaxTag.java?rev=662966&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/AbstractSuggestAjaxTag.java (added)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/AbstractSuggestAjaxTag.java Tue Jun 3 20:37:59 2008
@@ -0,0 +1,129 @@
+/*
+ * 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.custom.suggestajax;
+
+import java.util.Collection;
+import java.util.List;
+
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.generated.taglib.html.ext.HtmlInputTextTag;
+
+/**
+ * @author Gerald Muellan
+ * Date: 25.03.2006
+ * Time: 17:05:58
+ */
+public class AbstractSuggestAjaxTag extends HtmlInputTextTag
+{
+ private final static Class[] DEFAULT_SIGNATURE = new Class[]{String.class};
+ private final static Class[] SUGGEST_ITEM_SIGNATURE = new Class[]{String.class, Integer.class};
+
+ private static Log log = LogFactory.getLog(AbstractSuggestAjaxTag.class);
+
+ private javax.el.ValueExpression _suggestedItemsMethod;
+
+ private ValueExpression _maxSuggestedItems;
+
+ public void setMaxSuggestedItems(ValueExpression maxSuggestedItems)
+ {
+ _maxSuggestedItems = maxSuggestedItems;
+ }
+
+ public void release() {
+
+ super.release();
+ _maxSuggestedItems = null;
+ _suggestedItemsMethod = null;
+ }
+
+ protected void setProperties(UIComponent component) {
+
+ super.setProperties(component);
+
+ FacesContext context = getFacesContext();
+
+ SuggestAjax comp = (SuggestAjax) component;
+
+ //This part is a special hack for set the method for suggestedItemsMethod
+ //First maxSuggestedItems should be resolved and put on component, for
+ //make this value available when setSuggestedItemsMethodProperty is
+ //called. Note on AbstractSuggestAjax the field maxSuggestedItems
+ //the property inheritedTag = "true". In normal generation this should be defined
+ //on SuggestAjaxTag.
+ if (_maxSuggestedItems != null)
+ {
+ comp.setValueExpression("maxSuggestedItems", _maxSuggestedItems);
+ }
+
+ if (!_suggestedItemsMethod.isLiteralText())
+ {
+ AbstractSuggestAjaxTag.setSuggestedItemsMethodProperty(getFacesContext(),component,_suggestedItemsMethod.getExpressionString());
+ }
+ else
+ {
+ AbstractSuggestAjaxTag.log.error("Invalid expression " + _suggestedItemsMethod.getExpressionString());
+ }
+ }
+
+ public static void setSuggestedItemsMethodProperty(FacesContext context,
+ UIComponent component,
+ String suggestedItemsMethod)
+ {
+ if (suggestedItemsMethod != null)
+ {
+
+ if (!(component instanceof SuggestAjax))
+ {
+ throw new IllegalArgumentException("Component " + component.getClientId(context) + " is no InputSuggestAjax");
+ }
+ if (((SuggestAjax) component).getMaxSuggestedItems() != null)
+ {
+ MethodExpression mb = context.getApplication()
+ .getExpressionFactory().createMethodExpression(
+ context.getELContext(), suggestedItemsMethod,
+ Collection.class,
+ SUGGEST_ITEM_SIGNATURE);
+ ((SuggestAjax) component).setSuggestedItemsMethod(mb);
+ }
+ else
+ {
+ MethodExpression mb = context.getApplication()
+ .getExpressionFactory().createMethodExpression(
+ context.getELContext(), suggestedItemsMethod,
+ List.class, DEFAULT_SIGNATURE);
+ ((SuggestAjax) component).setSuggestedItemsMethod(mb);
+ }
+ }
+ }
+
+ // setter methodes to populate the components properites
+
+ public void setSuggestedItemsMethod(javax.el.ValueExpression suggestedItemsMethod)
+ {
+ _suggestedItemsMethod = suggestedItemsMethod;
+ }
+
+}
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/AbstractSuggestAjaxTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/AbstractSuggestAjaxTag.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/SuggestAjaxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/SuggestAjaxRenderer.java?rev=662966&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/SuggestAjaxRenderer.java (added)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/SuggestAjaxRenderer.java Tue Jun 3 20:37:59 2008
@@ -0,0 +1,96 @@
+/*
+ * 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.custom.suggestajax;
+
+import org.apache.myfaces.custom.ajax.api.AjaxDecodePhaseListener;
+import org.apache.myfaces.custom.ajax.api.AjaxSuggestRenderer;
+import org.apache.myfaces.renderkit.html.ext.HtmlTextRenderer;
+import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.el.MethodExpression;
+import javax.el.MethodNotFoundException;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author Gerald Muellan
+ * @author Martin Marinschek
+ * @version $Revision$ $Date$
+ */
+public class SuggestAjaxRenderer extends HtmlTextRenderer implements AjaxSuggestRenderer
+{
+ public static final int DEFAULT_MAX_SUGGESTED_ITEMS = 200;
+
+ public Collection getSuggestedItems(FacesContext context, UIComponent uiComponent)
+ {
+ RendererUtils.checkParamValidity(context, uiComponent, SuggestAjax.class);
+
+ SuggestAjax suggestAjax = (SuggestAjax) uiComponent;
+
+ //getting the suggested items
+ MethodExpression mb = suggestAjax.getSuggestedItemsMethod();
+ Integer maxSuggestedCount = suggestAjax.getMaxSuggestedItems();
+
+ Collection suggesteds;
+
+ if (maxSuggestedCount != null
+ && maxSuggestedCount.intValue() > 0)
+ {
+ try
+ {
+ suggesteds = (Collection) mb.invoke(context.getELContext(),new Object[]{
+ AjaxDecodePhaseListener.getValueForComponent(context, uiComponent),
+ maxSuggestedCount});
+ }
+ catch(MethodNotFoundException dummy)
+ {
+ suggesteds = (List) mb.invoke(context.getELContext(),new Object[]{
+ AjaxDecodePhaseListener.getValueForComponent(context, uiComponent)});
+ }
+ }
+ else
+ {
+ try
+ {
+ suggesteds = (List) mb.invoke(context.getELContext(),new Object[]{
+ AjaxDecodePhaseListener.getValueForComponent(context, uiComponent)});
+ }
+ catch(MethodNotFoundException dummy)
+ {
+ suggesteds = (Collection) mb.invoke(context.getELContext(),new Object[]{
+ AjaxDecodePhaseListener.getValueForComponent(context, uiComponent),
+ new Integer( DEFAULT_MAX_SUGGESTED_ITEMS )});
+ }
+ }
+
+ return suggesteds;
+ }
+
+ public void decode(FacesContext facesContext, UIComponent component)
+ {
+ super.decode(facesContext, component);
+ }
+
+ protected String addQueryString(String url, String queryString)
+ {
+ return url + (url.indexOf("?") > 0 ? "&" : "?") + queryString;
+ }
+}
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/SuggestAjaxRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/SuggestAjaxRenderer.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/inputsuggestajax/AbstractInputSuggestAjax.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/inputsuggestajax/AbstractInputSuggestAjax.java?rev=662966&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/inputsuggestajax/AbstractInputSuggestAjax.java (added)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/inputsuggestajax/AbstractInputSuggestAjax.java Tue Jun 3 20:37:59 2008
@@ -0,0 +1,89 @@
+/*
+ * 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.custom.suggestajax.inputsuggestajax;
+
+import java.io.IOException;
+
+import javax.el.MethodExpression;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.custom.suggestajax.SuggestAjax;
+
+/**
+ * Provides an input textbox with "suggest" functionality, using an ajax request to the server.
+ *
+ * @JSFComponent
+ * name = "s:inputSuggestAjax"
+ * class = "org.apache.myfaces.custom.suggestajax.inputsuggestajax.InputSuggestAjax"
+ * superClass = "org.apache.myfaces.custom.suggestajax.inputsuggestajax.AbstractInputSuggestAjax"
+ * tagClass = "org.apache.myfaces.custom.suggestajax.inputsuggestajax.InputSuggestAjaxTag"
+ *
+ * @author Gerald Muellan (latest modification by $Author$)
+ * @author Martin Marinschek
+ *
+ * @version $Revision$ $Date$
+ */
+
+public abstract class AbstractInputSuggestAjax extends SuggestAjax
+{
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.InputSuggestAjax";
+ public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.InputSuggestAjax";
+
+ public AbstractInputSuggestAjax()
+ {
+ super();
+
+ setRendererType(DEFAULT_RENDERER_TYPE);
+
+ // it makes absolutely no sense to have two autocompletes active at the same time
+ // ensure to disable the browser one - this has nothing to do with the
+ // autocomplete attribute this component provides
+ setAutocomplete("off"); // NON-NLS
+ }
+
+ public void encodeChildren(FacesContext context) throws IOException
+ {
+ super.encodeChildren(context);
+ }
+
+ /**
+ * If false, the input field is not automatically populated with the first suggested value.
+ *
+ * Default: true
+ *
+ * @JSFProperty
+ * defaultValue = "true"
+ * @return
+ */
+ public abstract Boolean getAutoComplete();
+
+ /**
+ * Method which gets a suggested Object as an argument and returns a
+ * calculated String label. With this attribute it is possible to
+ * achieve the same mechanism as it can be found at select menues
+ * with the label/value pair.
+ *
+ * @JSFProperty
+ * methodSignature = "java.lang.Object"
+ * returnSignature = "java.lang.String"
+ * stateHolder = "true"
+ * @return
+ */
+ public abstract MethodExpression getItemLabelMethod();
+}
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/inputsuggestajax/AbstractInputSuggestAjax.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/bigtest/tomahawk12_trunk/sandbox/core12/src/main/java/org/apache/myfaces/custom/suggestajax/inputsuggestajax/AbstractInputSuggestAjax.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL