dooApp/FXForm2

Accessing generated fields

Closed this issue · 3 comments

I'd like to begin by saying I'm an absolute novice as I guess will be evident by my question. Also apologies in advance if this should have been posted in Stack Overflow , I did search without much luck.

In my application I can create the forms by the methods described here online. I can also edit the CSS file using the "style your form with CSS "info.

The Textfields generated by the Fxform also validate nicely using Bean validation using validator version 5.4.0-final by adding the dependencies to the pom.

I would like to ask , how does one access the text fields generated ? how can I use a textfield.getText() ?
I understand that the fields may be named based on the bean variables but would appreciate any help with the appropriate method. the following is the bits of code which generates the form.

`public class Station {
private final SimpleStringProperty stationName;
private final SimpleStringProperty stationCode;

public Station(String stationName, String stationCode) {
    this.stationName = new SimpleStringProperty(stationName);
    this.stationCode = new SimpleStringProperty(stationCode);
}

 
public String getStationName() {
    return stationName.getValue();
}


public String getStationCode() {
    return stationCode.getValue();
}`

First method which successfully generates :

`private void createStationForm() {

    String css = AdminController.class.getResource("AdminController.css").toExternalForm();
    Station station = new Station(null, null);
      
    FXForm<Station> fXForm;

    fXForm = new FXFormBuilder()
            .source(station)
            .build();
    fXForm.setSkin(FXFormSkinFactory.DEFAULT_FACTORY.createSkin(fXForm));
    fXForm.getStylesheets().add(css);
    fXForm.setTitle("ADD STATION TO DATABASE");
    
    tabStation.setContent(fXForm);

}
**The following "3 lines to generate" method also works** FXForm fXForm = new FXForm(station);

    fXForm.setSkin(FXFormSkinFactory.DEFAULT_FACTORY.createSkin(fXForm));

    fXForm.addFilters(new ReorderFilter("stationName", "stationCode"));

    fXForm.setTitle("ADD STATION TO DATABASE");
    
    VBox tabStationVBox = new VBox();

    tabStationVBox.getChildren().addAll(fXForm);
    
    tabStation.setContent(tabStationVBox);

`
How do I use the .getText method ? what field names can I use.

Solved ! ..perhaps we could add it to the Wiki to help a fellow newbie like me ?

`
Textfield stationName = new TextField(); // same with stationCode.... then...

    tabStation.setContent(fXForm);

    Node nodeStationName = fXForm.getScene().lookup("#stationName-form-editor");

    Node nodeStationCode = fXForm.getScene().lookup("#stationCode-form-editor");

    this.stationName = (TextField) nodeStationName ;

    this.stationCode = (TextField) nodeStationCode;

`

Thanks, I have updated the wiki : How to retrieve a specific node of the form

Note that you don't need to retrieve the scene, you can directly call lookup on the form.

Excellent ! many thanks