You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2007/01/09 22:22:15 UTC
svn commit: r494586 - in /myfaces/tobago/trunk:
core/src/main/java/org/apache/myfaces/tobago/
core/src/main/java/org/apache/myfaces/tobago/component/
core/src/main/java/org/apache/myfaces/tobago/taglib/component/
theme/scarborough/src/main/java/org/apa...
Author: bommel
Date: Tue Jan 9 13:22:14 2007
New Revision: 494586
URL: http://svn.apache.org/viewvc?view=rev&rev=494586
Log:
(TOBAGO-237) Unified attribute selectedIndex and state of UITabGroup
Modified:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/TobagoConstants.java
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITabGroup.java
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTag.java
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTagDeclaration.java
myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/TobagoConstants.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/TobagoConstants.java?view=diff&rev=494586&r1=494585&r2=494586
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/TobagoConstants.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/TobagoConstants.java Tue Jan 9 13:22:14 2007
@@ -118,6 +118,7 @@
public static final String ATTR_SCRIPT_FILES = "scriptFiles";
public static final String ATTR_SCROLLBAR_HEIGHT = "scrollbarHeight";
public static final String ATTR_SCROLLBARS = "scrollbars";
+ public static final String ATTR_SELECTED_INDEX = "selectedIndex";
public static final String ATTR_SELECTED_LIST_STRING = "selectedListString";
// public static final String ATTR_SERVER_SIDE_TABS = "serverSideTab";
public static final String ATTR_SORTABLE = "sortable";
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITabGroup.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITabGroup.java?view=diff&rev=494586&r1=494585&r2=494586
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITabGroup.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITabGroup.java Tue Jan 9 13:22:14 2007
@@ -22,7 +22,7 @@
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_IMMEDIATE;
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_HEIGHT;
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_WIDTH;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STATE;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SELECTED_INDEX;
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SWITCH_TYPE;
import org.apache.myfaces.tobago.ajax.api.AjaxComponent;
import org.apache.myfaces.tobago.ajax.api.AjaxUtils;
@@ -48,7 +48,7 @@
public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.TabGroup";
- private int activeIndex;
+ private Integer selectedIndex;
private int renderedIndex;
private String switchType;
private Boolean immediate;
@@ -65,17 +65,6 @@
@Override
public void encodeBegin(FacesContext facesContext) throws IOException {
-
- ValueBinding stateBinding = getValueBinding(ATTR_STATE);
- Object state
- = stateBinding != null ? stateBinding.getValue(facesContext) : null;
- if (state instanceof Integer) {
- activeIndex = (Integer) state;
- } else if (state != null) {
- LOG.warn("Illegal class in stateBinding: " + state.getClass().getName());
- }
-
- setRenderedIndex(activeIndex);
super.encodeBegin(facesContext);
}
@@ -113,6 +102,7 @@
public void encodeEnd(FacesContext facesContext) throws IOException {
resetTabLayout();
super.encodeEnd(facesContext);
+ setRenderedIndex(getSelectedIndex());
}
private void resetTabLayout() {
@@ -138,7 +128,7 @@
}
public UIPanel getActiveTab() {
- return getTab(getActiveIndex());
+ return getTab(getSelectedIndex());
}
@@ -201,8 +191,13 @@
public void broadcast(FacesEvent facesEvent) throws AbortProcessingException {
super.broadcast(facesEvent);
if (facesEvent instanceof TabChangeEvent) {
- setActiveIndex(((TabChangeEvent) facesEvent).getNewTabIndex());
- updateState(getFacesContext());
+ Integer index = ((TabChangeEvent) facesEvent).getNewTabIndex();
+ ValueBinding vb = getValueBinding(ATTR_SELECTED_INDEX);
+ if (vb !=null) {
+ vb.setValue(getFacesContext(), index);
+ } else {
+ setSelectedIndex(index);
+ }
MethodBinding tabChangeListenerBinding = getTabChangeListener();
if (tabChangeListenerBinding != null) {
try {
@@ -227,12 +222,6 @@
return tabChangeListener;
}
- public void updateState(FacesContext facesContext) {
- ValueBinding stateBinding = getValueBinding(ATTR_STATE);
- if (stateBinding != null) {
- stateBinding.setValue(facesContext, activeIndex);
- }
- }
public void addTabChangeListener(TabChangeListener listener) {
if (LOG.isWarnEnabled() && isClientType()) {
@@ -257,7 +246,7 @@
Object[] state = new Object[6];
state[0] = super.saveState(context);
state[1] = renderedIndex;
- state[2] = activeIndex;
+ state[2] = selectedIndex;
state[3] = saveAttachedState(context, tabChangeListener);
state[4] = switchType;
state[5] = immediate;
@@ -268,35 +257,33 @@
Object[] values = (Object[]) state;
super.restoreState(context, values[0]);
renderedIndex = (Integer) values[1];
- activeIndex = (Integer) values[2];
+ selectedIndex = (Integer) values[2];
tabChangeListener = (MethodBinding) restoreAttachedState(context, values[3]);
switchType = (String) values[4];
immediate = (Boolean) values[5];
}
public void encodeAjax(FacesContext facesContext) throws IOException {
- if (activeIndex < 0 || !(activeIndex < getChildCount())) {
- LOG.error("This should never occur! Problem in decoding?");
- ValueBinding stateBinding = getValueBinding(ATTR_STATE);
- Object state
- = stateBinding != null ? stateBinding.getValue(facesContext) : null;
- if (state instanceof Integer) {
- activeIndex = (Integer) state;
- } else if (state != null) {
- LOG.warn("Illegal class in stateBinding: " + state.getClass().getName());
- }
- }
-
- setRenderedIndex(activeIndex);
+ setRenderedIndex(getSelectedIndex());
AjaxUtils.encodeAjaxComponent(facesContext, this);
}
- public int getActiveIndex() {
- return activeIndex;
+ public int getSelectedIndex() {
+ if (selectedIndex!=null) {
+ return selectedIndex;
+ }
+ ValueBinding vb = getValueBinding(ATTR_SELECTED_INDEX);
+ if (vb != null) {
+ Integer value = (Integer) vb.getValue(getFacesContext());
+ if (value != null) {
+ return value;
+ }
+ }
+ return 0;
}
- public void setActiveIndex(int activeIndex) {
- this.activeIndex = activeIndex;
+ public void setSelectedIndex(int selectedIndex) {
+ this.selectedIndex = selectedIndex;
}
private void setRenderedIndex(int index) {
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTag.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTag.java?view=diff&rev=494586&r1=494585&r2=494586
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTag.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTag.java Tue Jan 9 13:22:14 2007
@@ -20,7 +20,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_IMMEDIATE;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STATE;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SELECTED_INDEX;
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SWITCH_TYPE;
import org.apache.myfaces.tobago.component.ComponentUtil;
import org.apache.myfaces.tobago.component.UITabGroup;
@@ -34,9 +34,10 @@
private static final Log LOG = LogFactory.getLog(TabGroupTag.class);
- private String state;
+ private String selectedIndex;
private String switchType;
private String immediate;
+ private String state;
@Override
public String getComponentType() {
@@ -46,7 +47,8 @@
@Override
protected void setProperties(UIComponent component) {
super.setProperties(component);
- ComponentUtil.setValueBinding(component, ATTR_STATE, state);
+ ComponentUtil.setIntegerProperty(component, ATTR_SELECTED_INDEX, selectedIndex);
+ ComponentUtil.setIntegerProperty(component, ATTR_SELECTED_INDEX, state);
ComponentUtil.setStringProperty(component, ATTR_SWITCH_TYPE, switchType);
ComponentUtil.setBooleanProperty(component, ATTR_IMMEDIATE, immediate);
}
@@ -57,6 +59,7 @@
state = null;
switchType = null;
immediate = null;
+ selectedIndex = null;
}
public void setServerside(String serverside) {
@@ -67,6 +70,10 @@
public void setState(String state) {
this.state = state;
+ }
+
+ public void setSelectedIndex(String selectedIndex) {
+ this.selectedIndex = selectedIndex;
}
public void setSwitchType(String switchType) {
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTagDeclaration.java?view=diff&rev=494586&r1=494585&r2=494586
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTagDeclaration.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTagDeclaration.java Tue Jan 9 13:22:14 2007
@@ -45,7 +45,7 @@
rendererType = "TabGroup")
public interface TabGroupTagDeclaration extends TobagoTagDeclaration, HasIdBindingAndRendered, HasDeprecatedDimension,
- HasState, IsImmediateCommand {
+ IsImmediateCommand {
/**
* Deprecated! Use 'switchType' instead.
* Flag indicating that tab switching is done by server request.
@@ -70,4 +70,23 @@
{UITabGroup.SWITCH_TYPE_CLIENT, UITabGroup.SWITCH_TYPE_RELOAD_PAGE, UITabGroup.SWITCH_TYPE_RELOAD_TAB},
defaultValue = UITabGroup.SWITCH_TYPE_CLIENT)
void setSwitchType(String switchType);
+
+ /**
+ *
+ * <strong>ValueBindingExpression</strong> pointing to a Integer to save the
+ * component's selected Tab.
+ *
+ */
+ @TagAttribute @UIComponentTagAttribute(type = "java.lang.Integer")
+ void setSelectedIndex(String selectedIndex);
+
+ /**
+ *
+ * <strong>ValueBindingExpression</strong> pointing to a Integer to save the
+ * component's selected Tab.
+ */
+ @TagAttribute
+ @UIComponentTagAttribute(type = "java.lang.Integer")
+ @Deprecated()
+ void setState(String state);
}
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java?view=diff&rev=494586&r1=494585&r2=494586
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java Tue Jan 9 13:22:14 2007
@@ -32,6 +32,7 @@
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_HEADER;
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TIP;
import static org.apache.myfaces.tobago.TobagoConstants.SUBCOMPONENT_SEP;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SELECTED_INDEX;
import org.apache.myfaces.tobago.ajax.api.AjaxRenderer;
import org.apache.myfaces.tobago.ajax.api.AjaxUtils;
import org.apache.myfaces.tobago.component.ComponentUtil;
@@ -56,6 +57,7 @@
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
import java.io.IOException;
import java.util.Map;
import java.util.List;
@@ -97,7 +99,7 @@
layoutTabs(facesContext, component);
- int activeIndex = ensureRenderedActiveIndex(component);
+ int activeIndex = ensureRenderedActiveIndex(facesContext, component);
final String clientId = component.getClientId(facesContext);
final String hiddenId = clientId + TabGroupRenderer.ACTIVE_INDEX_POSTFIX;
@@ -170,21 +172,27 @@
}
}
- private int ensureRenderedActiveIndex(UITabGroup tabGroup) {
- int activeIndex = tabGroup.getActiveIndex();
+ private int ensureRenderedActiveIndex(FacesContext context, UITabGroup tabGroup) {
+ int activeIndex = tabGroup.getSelectedIndex();
// ensure to select a rendered tab
int index = 0;
for (UIComponent tab: (List<UIComponent>) tabGroup.getChildren()) {
if (tab instanceof UIPanel) {
if (tab.isRendered()) {
if (activeIndex == index) {
- break;
+ return index;
}
}
index++;
}
}
- tabGroup.setActiveIndex(index);
+ ValueBinding vb = tabGroup.getValueBinding(ATTR_SELECTED_INDEX);
+ if (vb !=null) {
+ vb.setValue(context, index);
+ } else {
+ tabGroup.setSelectedIndex(index);
+ }
+ tabGroup.setSelectedIndex(index);
return index;
}
@@ -335,7 +343,7 @@
renderTabGroupView(context,
(TobagoResponseWriter) context.getResponseWriter(),
(UITabGroup) component,
- ensureRenderedActiveIndex((UITabGroup) component),
+ ensureRenderedActiveIndex(context, (UITabGroup) component),
(HtmlStyleMap) component.getAttributes().get(ATTR_STYLE),
SWITCH_TYPE_RELOAD_TAB,
ResourceManagerUtil.getImageWithPath(context, "image/1x1.gif"));