Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seamfaces 147 - viewActions #64

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@
*/
package org.jboss.seam.faces.event.qualifier;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.inject.Qualifier;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Qualifies observer method parameters to select events that occur in a "after" phase in the JSF lifecycle
*
* @author Nicklas Karlsson
*/
@Qualifier
@Target({FIELD, PARAMETER})
@Target({TYPE, FIELD, METHOD, PARAMETER})
@Retention(RUNTIME)
public @interface After {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import javax.inject.Qualifier;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
Expand All @@ -36,7 +38,7 @@
* @see javax.faces.event.PhaseEvent
*/
@Qualifier
@Target({FIELD, PARAMETER})
@Target({TYPE, FIELD, METHOD, PARAMETER})
@Retention(RUNTIME)
public @interface ApplyRequestValues {
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@
*/
package org.jboss.seam.faces.event.qualifier;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.inject.Qualifier;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Qualifies observer method parameters to select events that occur in a "before" phase in the JSF lifecycle
*
* @author Nicklas Karlsson
*/
@Qualifier
@Target({FIELD, PARAMETER})
@Target({TYPE, FIELD, METHOD, PARAMETER})
@Retention(RUNTIME)
public @interface Before {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import javax.inject.Qualifier;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
Expand All @@ -34,7 +36,7 @@
* @author Nicklas Karlsson
*/
@Qualifier
@Target({FIELD, PARAMETER})
@Target({TYPE, FIELD, METHOD, PARAMETER})
@Retention(RUNTIME)
public @interface InvokeApplication {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import javax.inject.Qualifier;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
Expand All @@ -35,7 +37,7 @@
* @After}. The event parameter is a {@link PhaseEvent}.
*/
@Qualifier
@Target({FIELD, PARAMETER})
@Target({TYPE, FIELD, METHOD, PARAMETER})
@Retention(RUNTIME)
public @interface ProcessValidations {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import javax.inject.Qualifier;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
Expand All @@ -34,7 +36,7 @@
* @author Nicklas Karlsson
*/
@Qualifier
@Target({FIELD, PARAMETER})
@Target({TYPE, FIELD, METHOD, PARAMETER})
@Retention(RUNTIME)
public @interface RenderResponse {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import javax.inject.Qualifier;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
Expand All @@ -34,7 +36,7 @@
* @author Nicklas Karlsson
*/
@Qualifier
@Target({FIELD, PARAMETER})
@Target({TYPE, FIELD, METHOD, PARAMETER})
@Retention(RUNTIME)
public @interface RestoreView {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import javax.inject.Qualifier;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
Expand All @@ -35,7 +37,7 @@
* @After}. The event parameter is a {@link PhaseEvent}.
*/
@Qualifier
@Target({FIELD, PARAMETER})
@Target({TYPE, FIELD, METHOD, PARAMETER})
@Retention(RUNTIME)
public @interface UpdateModelValues {
}
37 changes: 37 additions & 0 deletions api/src/main/java/org/jboss/seam/faces/view/action/ViewAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.jboss.seam.faces.view.action;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.jboss.seam.faces.event.qualifier.RenderResponse;

/**
* The EL MethodExpression is executed when this annotation is applied to a ViewConfig.
*
* The MethodExpression is called by default before RENDER_RESPONSE phase. You can change this
* behaviour by using phase and before fields.
*
* @author Adriàn Gonzalez
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ViewAction {
/**
* El MethodExpression
*/
String value();

/**
* On which JSF phase must this viewAction be executed ?
*/
Class<?> phase() default RenderResponse.class;

/**
* Is this viewAction executed before phase ?
*/
boolean before() default true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.jboss.seam.faces.view.action;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Applied to an annotation to indicate that it is a faces action binding type.
*
* By default, this method will be called before RENDER_RESPONSE phase.
* You can change the jsf phase by using the annotations from org.jboss.seam.faces.event.qualifier package
* on your custom annotation.
*
* @author Adriàn Gonzalez
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ViewActionBindingType {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jboss.seam.faces.view.action;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.jboss.seam.faces.event.qualifier.After;
import org.jboss.seam.faces.event.qualifier.ApplyRequestValues;
import org.jboss.seam.faces.event.qualifier.Before;
import org.jboss.seam.faces.event.qualifier.InvokeApplication;
import org.jboss.seam.faces.event.qualifier.ProcessValidations;
import org.jboss.seam.faces.event.qualifier.RenderResponse;
import org.jboss.seam.faces.event.qualifier.UpdateModelValues;

/**
* This annotation must be used on a ViewConfig to specify its viewControllers.
*
* <p>A viewController is a managed bean handling a specific view.
* Some methods of the bean can be called during the lifecycle of the view.
* Those methods must be annotated with {@link BeforeRenderResponse}, {@link AfterRenderResponse}, or a mixture of
* {@link Before}, {@link After}, {@link ApplyRequestValues}, {@link ProcessValidations}, {@link UpdateModelValues},
* {@link InvokeApplication} or {@link RenderResponse}.</p>
*
* <p>Classic use case are :
* <ul>
* <li> {@link BeforeRenderResponse} for handling view initialization data (i.e. fetching data from database).</li>
* <li> {@link AfterRenderResponse} for view cleanup.</li>
* </ul></p>
*
* @author Adriàn Gonzalez
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Documented
public @interface ViewController {
Class<?>[] value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package org.jboss.seam.faces.view.config;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

import org.jboss.solder.logging.Logger;

/**
* Information about {@link ViewConfig} enum.
*
* @author Adriàn Gonzalez
*/
public class ViewConfigDescriptor {
private transient final Logger log = Logger.getLogger(ViewConfigDescriptor.class);

private String viewId;
private List<Object> values = new ArrayList<Object>();
private List<Annotation> metaData = new ArrayList<Annotation>();
private final ConcurrentHashMap<Class<? extends Annotation>, Annotation> metaDataByAnnotation = new ConcurrentHashMap<Class<? extends Annotation>, Annotation>();
private ConcurrentHashMap<Class<? extends Annotation>, List<? extends Annotation>> metaDataByQualifier = new ConcurrentHashMap<Class<? extends Annotation>, List<? extends Annotation>>();

/**
* ViewConfigDescriptor for view <code>viewId</code>
*/
public ViewConfigDescriptor(String viewId, Object value) {
this.viewId = viewId;
this.values = new ArrayList<Object>();
values.add(value);
}

public String getViewId() {
return viewId;
}

public void setViewId(String viewId) {
this.viewId = viewId;
}

public void addValue(Object value) {
if (!values.contains(value)) {
values.add(value);
}
}

public List<Object> getValues() {
return values;
}

public void setValues(List<Object> values) {
this.values = values;
}

public void addMetaData(Annotation metaData) {
this.metaData.add(metaData);
//add to metaDataByAnnotation
metaDataByAnnotation.put(metaData.annotationType(), metaData);
log.debugf("Putting new annotation (type: %s) for viewId: %s", metaData.annotationType().getName(), getViewId());
//add to metaDataByQualifier
Annotation[] annotations = metaData.annotationType().getAnnotations();
for (Annotation qualifier : annotations) {
if (qualifier.annotationType().getName().startsWith("java.")) {
log.debugf("Disregarding java.* package %s", qualifier.annotationType().getName());
continue;
}
List<Annotation> qualifiedAnnotations = new ArrayList<Annotation>();
List<? extends Annotation> exisitngQualifiedAnnotations = metaDataByQualifier.get(qualifier
.annotationType());
if (exisitngQualifiedAnnotations != null && !exisitngQualifiedAnnotations.isEmpty()) {
qualifiedAnnotations.addAll(exisitngQualifiedAnnotations);
}
qualifiedAnnotations.add(metaData);
log.debugf("Adding new annotation (type: %s) for Qualifier %s", metaData.annotationType().getName(), qualifier.annotationType().getName());
metaDataByQualifier.put(qualifier.annotationType(), qualifiedAnnotations);
}
}

/**
* Returns read-only list.
*
* Use {@link #addMetaData(Annotation)} to modify metaDatas.
*/
public List<Annotation> getMetaData() {
return Collections.unmodifiableList(metaData);
}

/**
* returns all metaData of the corresponding type.
*/
public <T extends Annotation> T getMetaData(Class<T> type) {
return (T) metaDataByAnnotation.get(type);
}

/**
* returns all qualified data from metadata annotations.
*
* returns empty list if there's no metaData for the qualifier.
*/
@SuppressWarnings("unchecked")
public List<? extends Annotation> getAllQualifierData(Class<? extends Annotation> qualifier) {
List<? extends Annotation> metaData = metaDataByQualifier.get(qualifier);
return metaData!=null ? Collections.unmodifiableList(metaData) : Collections.EMPTY_LIST;
}

public String toString() {
return super.toString()+"{viewId="+getViewId()+"}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ public interface ViewConfigStore {
*/
public <T extends Annotation> Map<String, Annotation> getAllAnnotationViewMap(Class<T> type);

/**
* return the registered viewConfigs
*/
public List<ViewConfigDescriptor> getAllViewConfigDescriptors();
}
Loading