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

initialize method of ViewModel is called twice #308

Closed
sideisra opened this issue Oct 13, 2015 · 4 comments
Closed

initialize method of ViewModel is called twice #308

sideisra opened this issue Oct 13, 2015 · 4 comments

Comments

@sideisra
Copy link
Contributor

When using Weld as DI framework it is possible to annotate a method with @PostConstruct to make Weld call this method after intantiation.

I accidentally named this method "initialize" which collides with a feature of FluentViewLoader. This method is called twice. Weld calls it because of @PostConstruct and the FluentViewLoader calls it because of its name.

This feature should be documented more clearly. Would it be possible to throw an exception when this constellation appears? It would avoid a lot of headache ;-)

@manuel-mauky
Copy link
Collaborator

We should throw an exception in this case with a message that asks the user to rename the post-construct method. This is better then silently include a hack that only calls the initialize method once in this case. We will address this in the next main version

@manuel-mauky manuel-mauky modified the milestones: 1.6.0, 1.5.0 Jun 1, 2016
@mainrs
Copy link
Contributor

mainrs commented Jun 22, 2016

Created a pull request for this.

@tfleis
Copy link

tfleis commented Jan 23, 2017

There is another problem with the initialize method in view model. If you make your view model class package private or the initialize method private you get an error. JavaFX is able to call the initialize method in the view class if the visibility is not public.

I think you have to call "initializeMethod.setAccessible(true);" in JavaViewLoader before invoking the method.

@manuel-mauky
Copy link
Collaborator

Hi,
there is already an issue with this feature request (#332) and a discussion on possible solutions for this.
I think we shouldn't mix it with this issue here. For this reason I will close this issue now and we can discuss in #332 about your request (or if you think it's a different issue, you can create a new one?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants