Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » FXMLBuilder StackOverflowError(trying to load an FXML file in part results in StackOverflowError)
FXMLBuilder StackOverflowError [message #1723345] Sun, 14 February 2016 21:48 Go to next message
John Bodkin is currently offline John BodkinFriend
Messages: 39
Registered: November 2011
Member
What is the correct way to load an FXML file in a e4 part?

The builder.load() method generates a StackOverflowError.

I created an e4 Application project from File->New->Project...->JavaFX->OSGI

I edited the @PostConstruct method to look like the following:

@PostConstruct
public void postConstruct(BorderPane parent, @FXMLLoader FXMLLoaderFactory factory) {
	try {
            FXMLBuilder<Node> builder = factory.loadRequestorRelative("IOS.fxml");
            Node n = builder.load();
            parent.setCenter(n);
        } catch (IOException e) {
            e.printStackTrace();
        }
		// This works when the FXML loader code is commented out.
//		Button btn = new Button("Hello World");
//		btn.setId("hwButton");
//		btn.setOnAction(new EventHandler<ActionEvent>() {
//			@Override
//			public void handle(ActionEvent event) {
//				System.out.println("Button clicked");
//			}
//		});
//		parent.setCenter(btn);
		
	}


The FXML looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!-- 
	Do not edit this file it is generated by e(fx)clipse from ../src/com/parts/IOS.fxgraph
-->

<?import java.lang.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.BorderPane?>
<?scenebuilder-stylesheet /css/default.css?>

<BorderPane xmlns:fx="http://javafx.com/fxml" fx:controller="com.parts.UIPart">

	<center>
		<Button fx:id="hwButton" text="Hello World" onAction="#clicked"/> 
	</center>
</BorderPane>


Thanks for the help,
John

[Updated on: Sun, 14 February 2016 21:50]

Report message to a moderator

Re: FXMLBuilder StackOverflowError [message #1723346 is a reply to message #1723345] Sun, 14 February 2016 22:08 Go to previous messageGo to next message
John Bodkin is currently offline John BodkinFriend
Messages: 39
Registered: November 2011
Member
I always manage to figure this stuff out after I ask for help.

You can't make the Part the Controller as well. I created another class that the FXML is controlled by and the e4 Part loaded as expected.

I'm still learning JavaFX in an e4 app.
Re: FXMLBuilder StackOverflowError [message #1731152 is a reply to message #1723346] Tue, 03 May 2016 08:43 Go to previous messageGo to next message
Denny Bayer is currently offline Denny BayerFriend
Messages: 4
Registered: May 2016
Junior Member
John Bodkin wrote on Sun, 14 February 2016 22:08
I always manage to figure this stuff out after I ask for help.

You can't make the Part the Controller as well. I created another class that the FXML is controlled by and the e4 Part loaded as expected.

I'm still learning JavaFX in an e4 app.


I just ran into the same problem. Is this the preferred way of doing that? I tried to have the MPart be the controller as well. Is that even possible?

Or are you supposed to do it something like this (with MPart being registered somewhere in the application model):

public class MyPart {

	Node view;
	MyController controller;

	@PostConstruct
	void init(HBox p, IEclipseContext context) {
		InjectingFXMLLoader<Node> iFXMLLoader = InjectingFXMLLoader.create(context, getClass(), "view.fxml");
		try {
			Data<Node, MyController> data = iFXMLLoader.loadWithController();
			view = data.getNode();
			controller = data.getController();
			
			p.getChildren().add(view);
                        // ...do other stuff

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}





Re: FXMLBuilder StackOverflowError [message #1731243 is a reply to message #1731152] Tue, 03 May 2016 17:59 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6320
Registered: July 2009
Senior Member
I would generally not advice you to make the Part instance your
controller but anyways the way to do it would be:

a) remove fx:controller from your FXML-File
b) change your MyPart to

class MyPart {

@PostConstruct
void init(HBox box, @LocalInstance FXMLLoader loader) {
loader.setController(this);
loader.setLocation(getClass().getResource("view.fxml"));
box.getChildren().add(loader.load());
}
}

You already see the problem? Because you HAVE TO remove the
fx:controller from the FXML-File the tooling can not assist anymore with
showing errors/warnings/autofixes.

I thought we had a feature request somewhere in bugzilla where we
discussed if it would be possible to directly put the FXML-File into the
e4-MPart-Model and we detect that situation in the framework and instead
of creating an instance we load the FXML-File and push the controller
into the MPart#object slot.

Tom

On 03.05.16 15:29, Denny Bayer wrote:
> John Bodkin wrote on Sun, 14 February 2016 22:08
>> I always manage to figure this stuff out after I ask for help.
>>
>> You can't make the Part the Controller as well. I created another
>> class that the FXML is controlled by and the e4 Part loaded as expected.
>>
>> I'm still learning JavaFX in an e4 app.
>
>
> I just ran into the same problem. Is this the preferred way of doing
> that? I tried to have the MPart be the controller as well. Is that even
> possible?
>
> Or are you supposed to do it something like this (with MPart being
> registered somewhere in the application model):
>
>
> public class MyPart {
>
> Node view;
> MyController controller;
>
> @PostConstruct
> void init(HBox p, IEclipseContext context) {
> InjectingFXMLLoader<Node> iFXMLLoader =
> InjectingFXMLLoader.create(context, getClass(), "view.fxml");
> try {
> Data<Node, MyController> data =
> iFXMLLoader.loadWithController();
> view = data.getNode();
> controller = data.getController();
>
> p.getChildren().add(view);
> // ...do other stuff
>
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> }
>
>
>
>
>
>
Re: FXMLBuilder StackOverflowError [message #1731308 is a reply to message #1731243] Wed, 04 May 2016 08:45 Go to previous message
Denny Bayer is currently offline Denny BayerFriend
Messages: 4
Registered: May 2016
Junior Member
Thanks!
Previous Topic:e4 RCP Application content not changing after first run
Next Topic:Installing e(fx)clipse - what am I missing?
Goto Forum:
  


Current Time: Sun Jun 25 20:59:25 GMT 2017

Powered by FUDForum. Page generated in 0.03056 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software