[seam-dev] SEAMFACES-147 viewActions

Adrian Gonzalez adr_gonzalez at yahoo.fr
Thu Oct 27 11:44:29 EDT 2011


Hello,

I'm working a bit on this issue.

But I'm stuck now and would like to know the better way to continue (sorry to bother once more ;( ).

For the moment I've :
1. registered all viewActionBindings into the viewConfigStore.
2. more or less replicated SecurityPhaseListener functionnality into a ViewActionPhaseListener.

But... viewConfigStore can only store Annotations. I need to store AnnotatedMethod (have a link back to the Method I'll need to call).

I see 4 possible solutions :

 1 - Duplicate ViewConfigStoreImpl to store AnnotatedMethod elements.
 Ugly, no ?
 2 - Make ViewConfigStore manage all kind of AnnotatedElements with a wrapper interface like
interface AnnotatedElement<T> {
Annotation<T> annotation;
Object value;
}
ViewConfigStore :
public interface ViewConfigStore {
public abstract void addAnnotationData(String viewId, AnnotatedElement annotation);
public abstract AnnotatedElement<T> T getAnnotationData(String viewId, Class<T> type);
public abstract List<AnnotatedElement<T>> getAllAnnotationData(String viewId, Class<T> type);
public abstract List<AnnotatedElement> getAllQualifierData(String viewId, Class<? extends Annotation> qualifier);
public <T extends Annotation> Map<String, Annotation> getAllAnnotationViewMap(Class<T> type);
}
3 - ViewConfigStore could store Annotated elements instead of Annotations
 This would make ViewConfigStore usage a little more complicated though.
4 - Have somes typed Page or View objects.
 This need really more reflection since we need to know what is a View (security, view actions, ...).
And it's a big impact on current code.
The ViewConfigStore would be sthing like (really incomplete) :
ViewConfigStore :
public Map<String,ViewInfo> getView(String viewId);
public List<View> getViews();
}
with for instance :
class/interface View {
List<Restriction> getRestrictions();
List<ViewAction> getViewActions(); //or event List<Action> getAction(PhaseId)
}

WDYT ?

P.S. Sorry for the rather long mail........


More details on what I have done for now :

As noted in the ticket, I can now create a viewAction annotation like this one :


@ViewActionBindingType
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
public @interface MyViewAction {
MyAppViewConfig.Pages value();
}

MyAppViewConfig being the sample @ViewConfig annotated class in viewconfig sample.

I can then use MyViewAction like this :


@ViewScoped
@Named
public class PageController implements Serializable {
    @MyViewAction(Pages.ITEM)
    public void loadEntry() {
    System.out.println("loadEntry called");
    }
}

For the moment, my code doesn't call this method (I'll just need to copy Seam Security code for it ;) ).


I've also created the following annotation that you can use to annotate your own viewAction annotation :
 - @Condition(condition=String) -> not really type safe.....
 - @Immediate(immediate=Boolean)
 - @OnPostback(onPostback=boolean)
 - @Phase(value=PhaseIdType)

Also, if you need to customise those behaviour per-usage, you can add attributes into your viewAction annotation :
@MyViewAction(Pages.ITEM, immediate=true, condition="#{myBean.eager}")
public void loadEntry()



More information about the seam-dev mailing list