Author: ishabalov
Date: 2007-07-25 17:43:58 -0400 (Wed, 25 Jul 2007)
New Revision: 1850
Modified:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/common/ComponentNavigator.java
trunk/samples/richfaces-demo/src/main/webapp/templates/main.xhtml
Log:
Improved current component recognizing
Modified:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/common/ComponentNavigator.java
===================================================================
---
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/common/ComponentNavigator.java 2007-07-25
18:50:29 UTC (rev 1849)
+++
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/common/ComponentNavigator.java 2007-07-25
21:43:58 UTC (rev 1850)
@@ -13,14 +13,14 @@
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
+import javax.servlet.http.HttpServletRequest;
public class ComponentNavigator {
private List components = null;
private ComponentDescriptor currentComponent;
private List componentGroups = null;
private Object activeTab;
-
-
+
public Object getActiveTab() {
return activeTab;
}
@@ -30,11 +30,17 @@
public ComponentDescriptor getCurrentComponent() {
String id = getComponentParam();
if (id!=null) {
- setActiveTab(null);
setCurrentComponent(findComponentById(id));
+ } else {
+ String uri = getComponentUri();
+ setCurrentComponent(findComponentByUri(uri));
}
return currentComponent;
}
+ private String getComponentUri() {
+ FacesContext fc = FacesContext.getCurrentInstance();
+ return ((HttpServletRequest)fc.getExternalContext().getRequest()).getRequestURI();
+ }
private String getComponentParam() {
FacesContext fc = FacesContext.getCurrentInstance();
String param = (String)
fc.getExternalContext().getRequestParameterMap().get("c");
@@ -45,13 +51,26 @@
}
}
- public ComponentDescriptor findComponentById(String id) {
+ private List components_() {
if (components==null) {
loadComponents();
}
- Iterator it = components.iterator();
+ return components;
+ }
+ public ComponentDescriptor findComponentByUri(String uri) {
+ Iterator it = components_().iterator();
while (it.hasNext()) {
ComponentDescriptor component = (ComponentDescriptor) it.next();
+ if (uri.endsWith(component.getDemoLocation())) {
+ return component;
+ }
+ }
+ throw new RuntimeException("Component uri=["+uri+"] not found");
+ }
+ public ComponentDescriptor findComponentById(String id) {
+ Iterator it = components_().iterator();
+ while (it.hasNext()) {
+ ComponentDescriptor component = (ComponentDescriptor) it.next();
if (component.getId().equals(id)) {
return component;
}
@@ -60,6 +79,11 @@
}
public void setCurrentComponent(ComponentDescriptor currentComponent) {
+ if (this.currentComponent!=null && currentComponent!=null &
!this.currentComponent.equals(currentComponent)) {
+ setActiveTab(null);
+ } else if (this.currentComponent==null || currentComponent==null) {
+ setActiveTab(null);
+ }
this.currentComponent = currentComponent;
}
@@ -111,10 +135,7 @@
}
public List getComponents() {
- if (components==null) {
- loadComponents();
- }
- Iterator it = components.iterator();
+ Iterator it = components_().iterator();
ComponentDescriptor cur = getCurrentComponent();
while (it.hasNext()) {
ComponentDescriptor desc = (ComponentDescriptor) it.next();
Modified: trunk/samples/richfaces-demo/src/main/webapp/templates/main.xhtml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/templates/main.xhtml 2007-07-25 18:50:29
UTC (rev 1849)
+++ trunk/samples/richfaces-demo/src/main/webapp/templates/main.xhtml 2007-07-25 21:43:58
UTC (rev 1850)
@@ -16,6 +16,7 @@
</head>
<body>
+<span style="display:none">${a4j.version}</span>
<ui:include src="/templates/include/header.xhtml" />
<table class="left_menu" cellpadding="0" cellspacing="0"
border="0">
<tbody>
Show replies by date