It seems some function are not work with Model extends DefaultFxmlModel

32 views
Skip to first unread message

ke bo

unread,
Mar 15, 2017, 11:46:28 AM3/15/17
to JRebirth Users
It is a project created using Intellij
I create two fxml and related model and controller, and I want test wave, 
but OnWave and listen neither works

public class App extends DefaultApplication<StackPane> {
@Override
public Class<? extends Model> firstModelClass() {
return MainPageModel.class;
}

public static void main(String[] args) {
launch(args);
}
}

@BootComponent
public class MainPageModel extends DefaultFXMLModel<MainPageModel> {

@Override
protected void initModel() {
listen(AppWaves.DO_CHANGE);
}

@Override
@OnWave(AppWaves.DO_CHANGE_ACTION)
protected void processWave(Wave wave) {
System.out.println(wave.waveType().action());
}

}

public interface AppWaves {
String DO_CHANGE_ACTION="DO_CHANGE";
WaveType DO_CHANGE= WBuilder.waveType(DO_CHANGE_ACTION);

}

public class SecondPageController extends AbstractFXMLController<SecondPageModel,View<SecondPageModel,?,?>>{
public void onOk(ActionEvent actionEvent) {
MainPageController controller= (MainPageController) model().getModel(MainPageModel.class).getFXMLController();
controller.txtMessage.setText("Hello, world");
}

public void onButton2(ActionEvent actionEvent) {
model().sendWave(AppWaves.DO_CHANGE);
}
}

when i insert @OnWave annotation in MainPageModel, the app can't load MainPageModel, all the code in the MainPageModel do not execute, I use the secend way: put listen() in the initModel,
and add public void doChange(final Wave wave) {...} in the MainPageModel, when call sendWave, it was not executed.
FxTest.zip

Sebastien Bordes

unread,
Mar 15, 2017, 12:08:45 PM3/15/17
to JRebirth Users
Hi,

It seems that you find an issue with 8.5.0 when the first model use fxml AND @OnWave feature.

This part has been refactored for next version (8.6.0)

Please add this into your App.java (fix the ShowView bug in your special case)

    @Override
    protected void preInit() {
        super.preInit();
       
        try {
         Class.forName(JRebirthWaves.class.getCanonicalName());
     } catch (final ClassNotFoundException e) {
     }
    }

Add @Preload to AppWaves
Allow to prelod Wave into registry to let them used with annoation @OnWave

And add theses dependencies:

           <dependency>
            <groupId>org.jrebirth.af</groupId>
            <artifactId>processor</artifactId>
            <version>8.5.0</version>
            <scope>provided</scope>
        </dependency>
       
           <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.5</version>
        </dependency>

Allow logging, useful to see errors and allow annoation processing to manage preload.


Seb

Sebastien Bordes

unread,
Mar 15, 2017, 12:52:09 PM3/15/17
to JRebirth Users
2 others errors


In MainPageModel, don't reuse defaut processWave method

    @OnWave(AppWaves.DO_CHANGE_ACTION)
    public void whatyouwant(Wave wave) {
        System.out.println(wave.waveType().action());
    }

In AppWaves:

String DO_CHANGE_ACTION="CHANGE";

no redundant do !! the do will be append according to default JRebirthParameters
Message has been deleted
Message has been deleted

Seb

unread,
Mar 15, 2017, 2:29:02 PM3/15/17
to jrebirth-users
Here the fixed project

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "JRebirth Users".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse jrebirth-users+unsubscribe@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.



--
FxTest.zip

ke bo

unread,
Mar 15, 2017, 8:25:15 PM3/15/17
to JRebirth Users, s...@jrebirth.org
It still does not work, even can't pass the compile, 

Information:javac 1.8.0_121 was used to compile java sources
Information:Module "FxTest" was fully rebuilt due to project configuration/dependencies changes
Information:2017/3/16 8:12 - Compilation completed with 1 error and 0 warnings in 11s 442ms
Error:java: java.lang.RuntimeException: java.lang.NullPointerException

It should remove this code in fxtest.pom
<dependency>
<groupId>org.jrebirth.af</groupId>
<artifactId>processor</artifactId>
<version>8.5.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.5</version>
</dependency>
then it can pass the compile, but it still does not work
now I use jrebirth 8.5.1-SNAPSHOT, it's works.

在 2017年3月16日星期四 UTC+8上午2:29:02,Seb写道:
Here the fixed project

Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse jrebirth-user...@googlegroups.com.

Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

Sebastien Bordes

unread,
Mar 16, 2017, 3:51:20 AM3/16/17
to JRebirth Users, s...@jrebirth.org
By Adding

    <properties>
        <archiveName>FxTest</archiveName>
        <appClass>com.xzsoft.App</appClass>
    </properties>

and 

    <parent>
        <groupId>org.jrebirth</groupId>
        <artifactId>ria</artifactId>
        <version>3.0.0</version>
    </parent>

to the pom file of the latest version I sent

just doing:

mvn clean install -P AutoJar
java -jar target/FxTest-1.0-SNAPSHOT.jar

Launch the app with full features working

If you experience trouble flush your maven cache and paste your error log with 8.5.0.

Does it compile and work with 8.5.1-SNAPSHOT ?

Seb
Message has been deleted

Sebastien Bordes

unread,
Mar 16, 2017, 3:54:32 AM3/16/17
to JRebirth Users, s...@jrebirth.org
Here the project modified and compiled
FxTest.zip

Sebastien Bordes

unread,
Mar 16, 2017, 10:53:10 AM3/16/17
to JRebirth Users, s...@jrebirth.org
To conclude this topic, I have reviewed the 8.5.0 source code and all is fine !
Some parts have been improved for future 8.6.0 but there isn't any issue.

There is no need to add the preinit patch in normal situation to force loading JRebirthWaves.

It was a side effect of other errors into your code:
==> bad waveType Action name (extra DO_)
==> wavehandler method name (don't use processWave with @OnWave)

So you was near to have a working sample, don't forget to activate log engine to have some error information, please share your thoughts if error logs are not enough understandable.

I will add a sample module into the showcase demo application to see Wave communication in action.

Keep coding !

Seb

ke bo

unread,
Mar 16, 2017, 12:04:24 PM3/16/17
to JRebirth Users, s...@jrebirth.org
The last modified project still doesn't work, even can't pass compiling, I compile project with intellij 2017.1 jdk 1.8.0_121

Information:javac 1.8.0_121 was used to compile java sources
Information:2017/3/16 23:51 - Compilation completed with 1 error and 0 warnings in 2s 34ms
Error:java: java.lang.RuntimeException: java.lang.NullPointerException

Now I use jrebrith 8.5.1-SNAPSHOT, it works, project is in the attach file.
but there is a new problem, when sendWave with a wavedata, it throw exception and fail to send
model().sendWave(AppWaves.DO_CHANGE, WBuilder.waveData(AppWaves.MESSAGE, "second"));


在 2017年3月16日星期四 UTC+8下午10:53:10,Sebastien Bordes写道:
FxTest.zip

Seb

unread,
Mar 16, 2017, 12:18:50 PM3/16/17
to jrebirth-users
You have done 2 mistakes:

AppWaves shall have the @Preload annotation

the waveHandler method shall contain explicit waveData type as parameter:

public void doChange(String s, Wave wave)

Please make sure to trigger the Maven build to be sure that annotation processor is called, check into target\generated-sources\annotations\com\xzsoft\FxTest the presence of generated class:

package com.xzsoft.FxTest;

import org.jrebirth.af.core.module.AbstractModuleStarter;
import com.xzsoft.AppWaves;

public class FxTestModuleStarter extends AbstractModuleStarter {

    @Override
    public void start() {
        preloadClass(AppWaves.class);
    }
}

Seb

Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse jrebirth-users+unsubscribe@googlegroups.com.

Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

ke bo

unread,
Mar 16, 2017, 8:18:23 PM3/16/17
to JRebirth Users, s...@jrebirth.org
thanks,

after change the doChange function to below, it works
public void doChange(String s, Wave wave);

@Preload is needless
and others is needless

do not add any other annotations or codes, only use 8.5.1-SNAPSHOT, and the write right prototype of the doChange function, everything is ok.

public class App extends DefaultApplication<StackPane> {
@Override
public Class<? extends Model> firstModelClass() {
return MainPageModel.class;
}

public static void main(String[] args) {
launch(args);
}
}
public interface AppWaves {
WaveItemBase<String> MESSAGE = new WaveItemBase<String>() {
};
String DO_CHANGE_ACTION = "CHANGE";
WaveType DO_CHANGE = WBuilder.waveType(DO_CHANGE_ACTION).items(MESSAGE);
}
public class MainPageModel extends DefaultFXMLModel<MainPageModel> {

    @OnWave(AppWaves.DO_CHANGE_ACTION)
public void doChange(String message, Wave wave) {
((MainPageController)getFXMLController()).txtMessage.setText(message);
}

}
public class SecondPageController extends AbstractFXMLController<SecondPageModel, View<SecondPageModel, ?, ?>> {
    public Label lbtlMessage;

public void onButton2(ActionEvent actionEvent) {
model().sendWave(AppWaves.DO_CHANGE, WBuilder.waveData(AppWaves.MESSAGE, "second"));
}
}
maven dependencies
<dependencies>
<dependency>
<groupId>org.jrebirth.af</groupId>
        <artifactId>core</artifactId>
<version>8.5.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jrebirth.af</groupId>
<artifactId>component</artifactId>
<version>8.5.1-SNAPSHOT</version>

</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
        <version>1.2.1</version>
</dependency>
</dependencies>


在 2017年3月17日星期五 UTC+8上午12:18:50,Seb写道:

Seb

unread,
Mar 17, 2017, 5:13:47 AM3/17/17
to jrebirth-users
You probably have cached generated code that was not deleted! the famous ModuleStarter...

If you perform a mvn clean that will remove files under target/generated-sources, the MainPageModel will fail to load !

Using @Preload is mandatory when using @OnWave, it allows to put WaveType into registry before a component (taht requires it) is retrieved and setup.

Without it when the component is initialized the wave type action is searched int the WaveTypeRegistry and cannot be found except if the class holding the WaveType defintion has been loaded by the application.
It's not the case with your application because the first model requires a WaveType not loaded at startup (no reference to AppWaves before loading of MainPageModel).

Hope you understand well why it's required.


Seb

Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse jrebirth-users+unsubscribe@googlegroups.com.

Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages