Advanced validation

49 views
Skip to first unread message

mosk...@gmail.com

unread,
Dec 17, 2014, 7:08:41 AM12/17/14
to dataf...@googlegroups.com
Hey,

First of all, thank you for developing this great framework. It's a real pleasure to use it.

Lately I have come into need to provide some additional validation before letting the flow to proceed and I am not sure how to do it.

My situation looks like this (and I will describe it to you, because you might find some problems with my logic I can't find myself):
  1. I have a main view (borderpane) that contains a global menu of four buttons. Hitting any of them opens the corresponding view in the center.
  2. Each of the subviews has a flow of their own. But, there is some information that is pertinent to each of the four views (chosen client, product etc.). This information is injected using a dedicated data model.
  3. In one of the subviews, when the button is clicked, a textarea has to be validated and additional actions need to be performed before the flow can advance:
    1. Split its text into an array (on newline) and validate each line.
    2. If there are no valid lines, inform the user and do nothing.
    3. If not, pass the general data (client, product) from the general data model to a specific data model that will be used inside this flow.
    4. Then and only then can the next view be reached.

This configuration poses two problems.

The first is not such a huge one, I guess and I only mention it as a kind of a sidenote. I need to create a subflow that will take the data model from the main flow and use it. I don't want the specific flow to clutter my main flow, so I guess in the future I will create a simple placeholder view (containing only a stackpane) that I will include in the main flow, which will then create a flow of its own, the subflow I need. I think this will work quite well, but haven't tried it -- if you think it won't please let me know.

The second one is quite a big one and it's of a more pressing nature: I need to have a link between views with some advanced validation. Right now I handle it his way:

(MainWindowController.java)

final Flow innerFlow = new Flow(ClientViewController.class)
                .withAction(Subflow1ViewController.class, "save", new FlowActionChain(
                        new FlowMethodAction("saveIt"), new FlowLink<>(Subflow2ViewController.class)));

(Then Subflow1ViewController.java)

    public void saveIt() throws VetoException {
        subflowModel.setProduct(model.selectedProductProperty().get());
        subflowModel.addLines(JavaFX.getText(textArea)); // JavaFX.getText() simply splits textarea.getText() on newline

        if(scanModel.getLines().size() < 1) {
            new Alert(Alert.AlertType.ERROR, "The data is incorrect.", ButtonType.CLOSE).showAndWait();
            throw new VetoException(new Veto());
        }

And here comes the problem: in order to prevent the flow from advancing I need to throw the VetoException which I cannot catch anywhere (or I simply don't know where and how to catch it). It works, but there is an unhandled exception running wild in my code.

Hendrik Ebbers

unread,
Dec 21, 2014, 10:04:14 AM12/21/14
to dataf...@googlegroups.com
Hi,

I will try to write an answer over holidays. First of all the veto exception is made for exactly this use cases. Maybe we need to add some better support for this feature. I will have a deeper look later.
Reply all
Reply to author
Forward
0 new messages