Repository: deltaspike Updated Branches: refs/heads/master 9f59afca6 -> 258bec620
DELTASPIKE-487 added sample, simple unit test and bug fixes Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/258bec62 Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/258bec62 Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/258bec62 Branch: refs/heads/master Commit: 258bec620af331399aae20c736edf3937698393e Parents: 9f59afc Author: tandraschko <[email protected]> Authored: Fri Feb 28 17:52:49 2014 +0100 Committer: tandraschko <[email protected]> Committed: Fri Feb 28 17:52:49 2014 +0100 ---------------------------------------------------------------------- .../scope/viewaccess/ViewAccessContext.java | 40 ++++++--- .../viewaccess/ViewAccessScopedBeanHistory.java | 7 +- .../example/PlaygroundClientWindowConfig.java | 62 ------------- .../example/PlaygroundJsfModuleConfig.java | 33 ------- .../deltaspike/example/exception/Jsf.java | 36 -------- .../example/exception/TestException.java | 24 ----- .../exception/TestExceptionController.java | 32 ------- .../example/exception/TestExceptionHandler.java | 34 ------- .../PlaygroundClientWindowConfig.java | 62 +++++++++++++ .../playground/PlaygroundJsfModuleConfig.java | 33 +++++++ .../deltaspike/playground/exception/Jsf.java | 36 ++++++++ .../playground/exception/TestException.java | 24 +++++ .../exception/TestExceptionController.java | 32 +++++++ .../exception/TestExceptionHandler.java | 34 +++++++ .../scope/viewaccess/ViewAccessScopedBean.java | 59 +++++++++++++ .../webapp/views/scope/viewaccess/test1.xhtml | 43 +++++++++ .../webapp/views/scope/viewaccess/test2.xhtml | 46 ++++++++++ .../webapp/views/scope/viewaccess/test3.xhtml | 43 +++++++++ .../request/DeltaSpikeLifecycleWrapper.java | 2 +- .../scope/viewaccess/ViewAccessScopedTest.java | 93 ++++++++++++++++++++ .../viewaccess/beans/ViewAccessScopedBeanX.java | 40 +++++++++ .../viewaccess/beans/ViewAccessScopedBeanY.java | 40 +++++++++ 22 files changed, 615 insertions(+), 240 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessContext.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessContext.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessContext.java index 701e4d0..f9ae8af 100644 --- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessContext.java +++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessContext.java @@ -60,19 +60,35 @@ public class ViewAccessContext extends AbstractContext @Override public <T> T get(Contextual<T> bean) { - PassivationCapable pc = (PassivationCapable) bean; - viewAccessScopedBeanHistory.getAccessedBeans().add(pc.getId()); - - return super.get(bean); + try + { + return super.get(bean); + } + finally + { + if (bean instanceof PassivationCapable) + { + PassivationCapable pc = (PassivationCapable) bean; + viewAccessScopedBeanHistory.getAccessedBeans().add(pc.getId()); + } + } } @Override public <T> T get(Contextual<T> bean, CreationalContext<T> creationalContext) { - PassivationCapable pc = (PassivationCapable) bean; - viewAccessScopedBeanHistory.getAccessedBeans().add(pc.getId()); - - return super.get(bean, creationalContext); + try + { + return super.get(bean, creationalContext); + } + finally + { + if (bean instanceof PassivationCapable) + { + PassivationCapable pc = (PassivationCapable) bean; + viewAccessScopedBeanHistory.getAccessedBeans().add(pc.getId()); + } + } } @Override @@ -106,15 +122,16 @@ public class ViewAccessContext extends AbstractContext public void onRenderingFinished(String view) { + // destroy beans only if the view has been changed if (!view.equals(viewAccessScopedBeanHistory.getLastView())) { viewAccessScopedBeanHistory.setLastView(view); destroyExpiredBeans(); - - // clear list from last request - viewAccessScopedBeanHistory.getAccessedBeans().clear(); } + + // clear history after each rendering process + viewAccessScopedBeanHistory.getAccessedBeans().clear(); } private void destroyExpiredBeans() @@ -130,7 +147,6 @@ public class ViewAccessContext extends AbstractContext Contextual bean = storage.getBean(storageEntry.getKey()); AbstractContext.destroyBean(bean, storageEntry.getValue()); storage.getStorage().remove(storageEntry.getKey()); //ok due to ConcurrentHashMap - break; } } } http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessScopedBeanHistory.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessScopedBeanHistory.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessScopedBeanHistory.java index 06ddbe9..e917301 100644 --- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessScopedBeanHistory.java +++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessScopedBeanHistory.java @@ -29,14 +29,9 @@ public class ViewAccessScopedBeanHistory implements Serializable { private static final long serialVersionUID = 3617603930728148927L; - private List<String> accessedBeans; + private List<String> accessedBeans = new ArrayList<String>(); private String lastView; - public ViewAccessScopedBeanHistory() - { - accessedBeans = new ArrayList<String>(); - } - public List<String> getAccessedBeans() { return accessedBeans; http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/PlaygroundClientWindowConfig.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/PlaygroundClientWindowConfig.java b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/PlaygroundClientWindowConfig.java deleted file mode 100644 index dc952ea..0000000 --- a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/PlaygroundClientWindowConfig.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.deltaspike.example; - -import javax.enterprise.inject.Specializes; -import javax.faces.context.FacesContext; -import org.apache.deltaspike.jsf.spi.scope.window.DefaultClientWindowConfig; - -@Specializes -public class PlaygroundClientWindowConfig extends DefaultClientWindowConfig -{ - @Override - public ClientWindowRenderMode getClientWindowRenderMode(FacesContext facesContext) - { - String path = facesContext.getExternalContext().getRequestPathInfo(); - if (path == null) - { - path = facesContext.getExternalContext().getRequestServletPath(); - } - - ClientWindowRenderMode mode; - - if (path.contains("/windowhandling/clientwindow/")) - { - mode = ClientWindowRenderMode.CLIENTWINDOW; - } - else if (path.contains("/windowhandling/lazy/")) - { - mode = ClientWindowRenderMode.LAZY; - } - else if (path.contains("/windowhandling/none/")) - { - mode = ClientWindowRenderMode.NONE; - } - else if (path.contains("/windowhandling/delegated/")) - { - mode = ClientWindowRenderMode.DELEGATED; - } - else - { - mode = ClientWindowRenderMode.CLIENTWINDOW; - } - - return mode; - } -} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/PlaygroundJsfModuleConfig.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/PlaygroundJsfModuleConfig.java b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/PlaygroundJsfModuleConfig.java deleted file mode 100644 index 432843b..0000000 --- a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/PlaygroundJsfModuleConfig.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.deltaspike.example; - -import java.lang.annotation.Annotation; -import javax.enterprise.inject.Specializes; -import org.apache.deltaspike.example.exception.Jsf; -import org.apache.deltaspike.jsf.api.config.JsfModuleConfig; - -@Specializes -public class PlaygroundJsfModuleConfig extends JsfModuleConfig -{ - public Class<? extends Annotation> getExceptionQualifier() - { - return Jsf.class; - } -} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/exception/Jsf.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/exception/Jsf.java b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/exception/Jsf.java deleted file mode 100644 index 2f00c53..0000000 --- a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/exception/Jsf.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.deltaspike.example.exception; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import static java.lang.annotation.ElementType.TYPE; -import java.lang.annotation.Retention; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import java.lang.annotation.Target; -import javax.inject.Qualifier; - -@Target( { TYPE, ElementType.PARAMETER } ) -@Retention(RUNTIME) -@Documented -@Qualifier -public @interface Jsf -{ - -} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/exception/TestException.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/exception/TestException.java b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/exception/TestException.java deleted file mode 100644 index 5f322c4..0000000 --- a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/exception/TestException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.deltaspike.example.exception; - -public class TestException extends RuntimeException -{ - -} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/exception/TestExceptionController.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/exception/TestExceptionController.java b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/exception/TestExceptionController.java deleted file mode 100644 index 597aea0..0000000 --- a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/exception/TestExceptionController.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.deltaspike.example.exception; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Named; - -@Named -@RequestScoped -public class TestExceptionController -{ - public void throwException() - { - throw new TestException(); - } -} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/exception/TestExceptionHandler.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/exception/TestExceptionHandler.java b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/exception/TestExceptionHandler.java deleted file mode 100644 index b6d3a35..0000000 --- a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/example/exception/TestExceptionHandler.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.deltaspike.example.exception; - -import org.apache.deltaspike.core.api.exception.control.ExceptionHandler; -import org.apache.deltaspike.core.api.exception.control.Handles; -import org.apache.deltaspike.core.api.exception.control.event.ExceptionEvent; - -@ExceptionHandler -public class TestExceptionHandler -{ - public void handleTestException(@Handles @Jsf ExceptionEvent<TestException> event) - { - System.err.println("TestException handled!"); - - event.handled(); - } -} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/PlaygroundClientWindowConfig.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/PlaygroundClientWindowConfig.java b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/PlaygroundClientWindowConfig.java new file mode 100644 index 0000000..691dc80 --- /dev/null +++ b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/PlaygroundClientWindowConfig.java @@ -0,0 +1,62 @@ +/* + * 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.deltaspike.playground; + +import javax.enterprise.inject.Specializes; +import javax.faces.context.FacesContext; +import org.apache.deltaspike.jsf.spi.scope.window.DefaultClientWindowConfig; + +@Specializes +public class PlaygroundClientWindowConfig extends DefaultClientWindowConfig +{ + @Override + public ClientWindowRenderMode getClientWindowRenderMode(FacesContext facesContext) + { + String path = facesContext.getExternalContext().getRequestPathInfo(); + if (path == null) + { + path = facesContext.getExternalContext().getRequestServletPath(); + } + + ClientWindowRenderMode mode; + + if (path.contains("/windowhandling/clientwindow/")) + { + mode = ClientWindowRenderMode.CLIENTWINDOW; + } + else if (path.contains("/windowhandling/lazy/")) + { + mode = ClientWindowRenderMode.LAZY; + } + else if (path.contains("/windowhandling/none/")) + { + mode = ClientWindowRenderMode.NONE; + } + else if (path.contains("/windowhandling/delegated/")) + { + mode = ClientWindowRenderMode.DELEGATED; + } + else + { + mode = ClientWindowRenderMode.CLIENTWINDOW; + } + + return mode; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/PlaygroundJsfModuleConfig.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/PlaygroundJsfModuleConfig.java b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/PlaygroundJsfModuleConfig.java new file mode 100644 index 0000000..f4f4bf0 --- /dev/null +++ b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/PlaygroundJsfModuleConfig.java @@ -0,0 +1,33 @@ +/* + * 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.deltaspike.playground; + +import java.lang.annotation.Annotation; +import javax.enterprise.inject.Specializes; +import org.apache.deltaspike.playground.exception.Jsf; +import org.apache.deltaspike.jsf.api.config.JsfModuleConfig; + +@Specializes +public class PlaygroundJsfModuleConfig extends JsfModuleConfig +{ + public Class<? extends Annotation> getExceptionQualifier() + { + return Jsf.class; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/exception/Jsf.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/exception/Jsf.java b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/exception/Jsf.java new file mode 100644 index 0000000..e42ea55 --- /dev/null +++ b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/exception/Jsf.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.playground.exception; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import static java.lang.annotation.ElementType.TYPE; +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.Target; +import javax.inject.Qualifier; + +@Target( { TYPE, ElementType.PARAMETER } ) +@Retention(RUNTIME) +@Documented +@Qualifier +public @interface Jsf +{ + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/exception/TestException.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/exception/TestException.java b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/exception/TestException.java new file mode 100644 index 0000000..4cbeedc --- /dev/null +++ b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/exception/TestException.java @@ -0,0 +1,24 @@ +/* + * 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.deltaspike.playground.exception; + +public class TestException extends RuntimeException +{ + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/exception/TestExceptionController.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/exception/TestExceptionController.java b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/exception/TestExceptionController.java new file mode 100644 index 0000000..32084c3 --- /dev/null +++ b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/exception/TestExceptionController.java @@ -0,0 +1,32 @@ +/* + * 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.deltaspike.playground.exception; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +@Named +@RequestScoped +public class TestExceptionController +{ + public void throwException() + { + throw new TestException(); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/exception/TestExceptionHandler.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/exception/TestExceptionHandler.java b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/exception/TestExceptionHandler.java new file mode 100644 index 0000000..1939da1 --- /dev/null +++ b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/exception/TestExceptionHandler.java @@ -0,0 +1,34 @@ +/* + * 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.deltaspike.playground.exception; + +import org.apache.deltaspike.core.api.exception.control.ExceptionHandler; +import org.apache.deltaspike.core.api.exception.control.Handles; +import org.apache.deltaspike.core.api.exception.control.event.ExceptionEvent; + +@ExceptionHandler +public class TestExceptionHandler +{ + public void handleTestException(@Handles @Jsf ExceptionEvent<TestException> event) + { + System.err.println("TestException handled!"); + + event.handled(); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/scope/viewaccess/ViewAccessScopedBean.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/scope/viewaccess/ViewAccessScopedBean.java b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/scope/viewaccess/ViewAccessScopedBean.java new file mode 100644 index 0000000..701dcfd --- /dev/null +++ b/deltaspike/examples/jsf-playground/src/main/java/org/apache/deltaspike/playground/scope/viewaccess/ViewAccessScopedBean.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.playground.scope.viewaccess; + +import java.io.Serializable; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Named; +import org.apache.deltaspike.core.api.scope.ViewAccessScoped; + +@Named +@ViewAccessScoped +public class ViewAccessScopedBean implements Serializable +{ + private String value; + + @PostConstruct + public void postConstruct() + { + System.err.println("postConstruct"); + } + + @PreDestroy + public void preDestroy() + { + System.err.println("preDestroy"); + } + + public void touch() + { + System.err.println("touch"); + } + + public String getValue() + { + return value; + } + + public void setValue(String value) + { + this.value = value; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/examples/jsf-playground/src/main/webapp/views/scope/viewaccess/test1.xhtml ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jsf-playground/src/main/webapp/views/scope/viewaccess/test1.xhtml b/deltaspike/examples/jsf-playground/src/main/webapp/views/scope/viewaccess/test1.xhtml new file mode 100644 index 0000000..37bd9f4 --- /dev/null +++ b/deltaspike/examples/jsf-playground/src/main/webapp/views/scope/viewaccess/test1.xhtml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ds="http://deltaspike.apache.org/jsf"> + +<h:head> + <title>DeltaSpike JSF Playground</title> +</h:head> + +<h:body> + <h:form> + <ds:windowId/> + + <h:commandButton value="Touch" action="#{viewAccessScopedBean.touch()}"/> + <h:commandButton value="Touch via AJAX" action="#{viewAccessScopedBean.touch()}"> + <f:ajax render="@form" execute="@this" /> + </h:commandButton> + </h:form> + +</h:body> + +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/examples/jsf-playground/src/main/webapp/views/scope/viewaccess/test2.xhtml ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jsf-playground/src/main/webapp/views/scope/viewaccess/test2.xhtml b/deltaspike/examples/jsf-playground/src/main/webapp/views/scope/viewaccess/test2.xhtml new file mode 100644 index 0000000..08d8a1b --- /dev/null +++ b/deltaspike/examples/jsf-playground/src/main/webapp/views/scope/viewaccess/test2.xhtml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ds="http://deltaspike.apache.org/jsf"> + +<h:head> + <title>DeltaSpike JSF Playground</title> +</h:head> + +<h:body> + <h:form> + <ds:windowId/> + + <!-- Just to touch the bean --> + #{viewAccessScopedBean.value} + + <h:commandButton value="Touch" action="#{viewAccessScopedBean.touch()}"/> + <h:commandButton value="Touch via AJAX" action="#{viewAccessScopedBean.touch()}"> + <f:ajax render="@form" execute="@this" /> + </h:commandButton> + </h:form> + +</h:body> + +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/examples/jsf-playground/src/main/webapp/views/scope/viewaccess/test3.xhtml ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jsf-playground/src/main/webapp/views/scope/viewaccess/test3.xhtml b/deltaspike/examples/jsf-playground/src/main/webapp/views/scope/viewaccess/test3.xhtml new file mode 100644 index 0000000..37bd9f4 --- /dev/null +++ b/deltaspike/examples/jsf-playground/src/main/webapp/views/scope/viewaccess/test3.xhtml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ds="http://deltaspike.apache.org/jsf"> + +<h:head> + <title>DeltaSpike JSF Playground</title> +</h:head> + +<h:body> + <h:form> + <ds:windowId/> + + <h:commandButton value="Touch" action="#{viewAccessScopedBean.touch()}"/> + <h:commandButton value="Touch via AJAX" action="#{viewAccessScopedBean.touch()}"> + <f:ajax render="@form" execute="@this" /> + </h:commandButton> + </h:form> + +</h:body> + +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeLifecycleWrapper.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeLifecycleWrapper.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeLifecycleWrapper.java index ef8ef57..36b4342 100644 --- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeLifecycleWrapper.java +++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeLifecycleWrapper.java @@ -110,7 +110,7 @@ class DeltaSpikeLifecycleWrapper extends Lifecycle { this.wrapped.render(facesContext); - if (facesContext.getViewRoot() != null) + if (facesContext.getViewRoot() != null && facesContext.getViewRoot().getViewId() != null) { ViewAccessContext viewAccessContext = contextExtension.getViewAccessScopedContext(); if (viewAccessContext != null) http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/viewaccess/ViewAccessScopedTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/viewaccess/ViewAccessScopedTest.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/viewaccess/ViewAccessScopedTest.java new file mode 100644 index 0000000..8cda848 --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/viewaccess/ViewAccessScopedTest.java @@ -0,0 +1,93 @@ +/* + * 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.deltaspike.test.jsf.impl.scope.viewaccess; + +import javax.inject.Inject; +import org.apache.deltaspike.core.impl.scope.DeltaSpikeContextExtension; +import org.apache.deltaspike.core.spi.scope.window.WindowContext; +import org.apache.deltaspike.test.category.SeCategory; +import org.apache.deltaspike.test.jsf.impl.scope.viewaccess.beans.ViewAccessScopedBeanX; +import org.apache.deltaspike.test.jsf.impl.scope.viewaccess.beans.ViewAccessScopedBeanY; +import org.apache.deltaspike.test.jsf.impl.util.ArchiveUtils; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +@RunWith(Arquillian.class) +@Category(SeCategory.class) +public class ViewAccessScopedTest +{ + @Deployment + public static WebArchive deploy() + { + String simpleName = ViewAccessScopedTest.class.getSimpleName(); + String archiveName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1); + + JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, archiveName + ".jar") + .addPackage(ViewAccessScopedTest.class.getPackage().getName()) + .addPackage(ViewAccessScopedBeanX.class.getPackage().getName()) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + + return ShrinkWrap.create(WebArchive.class, archiveName + ".war") + .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndJsfArchive()) + .addAsLibraries(testJar) + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Inject + private WindowContext windowContext; + + @Inject + private ViewAccessScopedBeanX viewAccessScopedBeanX; + + @Inject + private ViewAccessScopedBeanY viewAccessScopedBeanY; + + @Inject + private DeltaSpikeContextExtension contextExtension; + + @Test + public void usageOnOnePageTest() + { + windowContext.activateWindow("w1"); + + viewAccessScopedBeanX.setValue("x1"); + viewAccessScopedBeanY.setValue("y1"); + Assert.assertEquals("x1", viewAccessScopedBeanX.getValue()); + Assert.assertEquals("y1", viewAccessScopedBeanY.getValue()); + contextExtension.getViewAccessScopedContext().onRenderingFinished("viewA"); + Assert.assertEquals("x1", viewAccessScopedBeanX.getValue()); + Assert.assertEquals("y1", viewAccessScopedBeanY.getValue()); + contextExtension.getViewAccessScopedContext().onRenderingFinished("viewA"); + + //no access + contextExtension.getViewAccessScopedContext().onRenderingFinished("viewB"); + + //fails: + Assert.assertNull(viewAccessScopedBeanX.getValue()); + Assert.assertNull(viewAccessScopedBeanY.getValue()); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/viewaccess/beans/ViewAccessScopedBeanX.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/viewaccess/beans/ViewAccessScopedBeanX.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/viewaccess/beans/ViewAccessScopedBeanX.java new file mode 100644 index 0000000..957eeef --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/viewaccess/beans/ViewAccessScopedBeanX.java @@ -0,0 +1,40 @@ +/* + * 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.deltaspike.test.jsf.impl.scope.viewaccess.beans; + +import java.io.Serializable; +import javax.inject.Named; +import org.apache.deltaspike.core.api.scope.ViewAccessScoped; + +@Named +@ViewAccessScoped +public class ViewAccessScopedBeanX implements Serializable +{ + private String value; + + public String getValue() + { + return value; + } + + public void setValue(String value) + { + this.value = value; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/258bec62/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/viewaccess/beans/ViewAccessScopedBeanY.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/viewaccess/beans/ViewAccessScopedBeanY.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/viewaccess/beans/ViewAccessScopedBeanY.java new file mode 100644 index 0000000..966c5a3 --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/viewaccess/beans/ViewAccessScopedBeanY.java @@ -0,0 +1,40 @@ +/* + * 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.deltaspike.test.jsf.impl.scope.viewaccess.beans; + +import java.io.Serializable; +import javax.inject.Named; +import org.apache.deltaspike.core.api.scope.ViewAccessScoped; + +@Named +@ViewAccessScoped +public class ViewAccessScopedBeanY implements Serializable +{ + private String value; + + public String getValue() + { + return value; + } + + public void setValue(String value) + { + this.value = value; + } +}
