Hello,
This is my first post in this group, so excuse me if I missed something.
I'm trying to use JRebirth in my business applications, and have success (littler or more) so far.
Now, I'm working on application with heavily use of Waves.
Current status definition:
I have a model in which I want to receive some data from wave.
Wave definition: (the wave is defined in ErrorPageService.class)
public static final Wave MESSAGE_WAVE = Builders.wave().waveGroup(WaveGroup.RETURN_DATA);
public static final WaveType MESSAGE_WAVE_TYPE = Builders.waveType("GET_MESSAGE")
.items(JRebirthItems.voidItem)
.returnAction("GET_MESSAGE_DONE")
.returnItem(ERROR_MESSAGE);
In my model I have to define function
public void doGetMessageDone(String message, final Wave wave){
....
}
somewhere in init model have to call
listen(ErrorPageService.MESSAGE_WAVE_TYPE.returnWaveType());
and finally when I want to receive a message I have to call
getModel().returnData(ErrorPageService.class, ErrorPageService.MESSAGE_WAVE_TYPE);
if I have to listen for more waves, I have to call listen method for every wave type, and define method for listening every wave.
I tried to use OnWave annotation, and this is very good approach. Now I don't need to call listen method for every wave because it is already done in model construction.
Just define :
@OnWave(value="GET_MESSAGE_DONE")
public void doGetMessageDone(String message, final Wave wave){
....
}
and it is registered for listening wave.
Problem definition:
If I have more similar waves with different types of messages, I have to create different method for receiving every of them, and they must have name like doGetMessage1Done, doGetMessage2Done....etc.
Why OnWave annotation don't understand its annotated method, why annotated methods must have strict names?
Then I could write something like
@OnWave(value="GET_MESSAGE1_DONE")
public void getMessage1(String message, final Wave wave){
.....
}
@OnWave(value="GET_MESSAGE2_DONE")
public void getMessage2(String message, final Wave wave){
.....
}
and more likely
@OnWaves(
{
@OnWave(value="GET_MESSAGE1_DONE"),
@OnWave(value="GET_MESSAGE2_DONE")
}
)
(value="GET_MESSAGE_DONE")
public void getMessage(String message, final Wave wave){
.....
}
OK, I found partial solution in ComponentEnhancer class, you have method
public static void manageOnWaveAnnotation(final Component<?> component) {
// Retrieve class annotations (Java 8 add support for repeatable annotations)
for (final OnWave clsOnWave : component.getClass().getAnnotationsByType(OnWave.class)) {
manageUniqueWaveTypeAction(component, clsOnWave.value(), null);
}
// Iterate over each annotated Method and all annotations
for (final Method method : ClassUtility.getAnnotatedMethods(component.getClass(), OnWave.class)) {
for (final OnWave clsOnWave : method.getAnnotationsByType(OnWave.class)) {
manageUniqueWaveTypeAction(component, clsOnWave.value(), null);
}
}
}
In second part of the method you have to change
manageUniqueWaveTypeAction(component, clsOnWave.value(), null);
into
manageUniqueWaveTypeAction(component, clsOnWave.value(), method);
this solves the problem of naming receiving methods.
now you can define
@OnWave(value="GET_MESSAGE1_DONE")
public void whatEverName(String message, final Wave wave){
.....
}
But, what with multiple wave listener method (Method which listen multiple waves types), like I mention in @OnWaves annotation?
Uff, this post is long, but I think it is clear, and maybe someone will learn from it, like I am, reading other posts.
Tnx.
Darko