Table of Contents
Submit and Create
Submit and Create is a SOLoist sample application that demonstrates a simple, classical form for entering data and creating a new object (of class Person in this example) when the form is submitted. The new object is created upon the Submit command, with the attributes configured from the data entered in the form. Commands are also used here.
Live example
UML Model
Business Logic Code
- CreatePerson.java
public void execute() // -------------<SOL id="928f2fbc-e47e-4718-84e3-8ceff8e61bc0:___throw__" /> // -------------<LOS id="928f2fbc-e47e-4718-84e3-8ceff8e61bc0:___throw__" /> { // ---------<SOL id="928f2fbc-e47e-4718-84e3-8ceff8e61bc0:___body___" /> Text nameVal = name.val(); Integer ageVal = age.val(); Date dateOfBirthVal = dateOfBirth.val(); Gender genderVal = gender.val(); Real heightVal = height.val(); Boolean isMarriedVal = isMarried.val(); if (nameVal == null || nameVal.isEmpty()) { throw new CommandPreconditionsException("Please, type in the name for new person."); } Person p = new Person(); p.name.set(nameVal); p.age.set(ageVal); p.dateOfBirth.set(dateOfBirthVal); p.gender.set(genderVal); p.height.set(heightVal); p.isMarried.set(isMarriedVal); // ---------<LOS id="928f2fbc-e47e-4718-84e3-8ceff8e61bc0:___body___" /> }
GUI Code
package rs.sol.sampleapps; import rs.sol.sampleapps.commands.CreatePerson; import rs.sol.soloist.helpers.init.DefaultContextInit; import rs.sol.soloist.helpers.init.Initializer; import rs.sol.soloist.helpers.init.InitializerFailedException; import rs.sol.soloist.modelreader.Repository; import rs.sol.soloist.server.builtindomains.builtindatatypes.Boolean; import rs.sol.soloist.server.builtindomains.builtindatatypes.Date; import rs.sol.soloist.server.builtindomains.builtindatatypes.Integer; import rs.sol.soloist.server.builtindomains.builtindatatypes.Real; import rs.sol.soloist.server.builtindomains.builtindatatypes.Text; import rs.sol.soloist.server.guiconfiguration.components.GUIApplicationComponent; import rs.sol.soloist.server.guiconfiguration.components.GUIButtonComponent; import rs.sol.soloist.server.guiconfiguration.components.GUILabelComponent; import rs.sol.soloist.server.guiconfiguration.components.GUIPanelComponent; import rs.sol.soloist.server.guiconfiguration.construction.GUIComponentBinding; import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIInput; import rs.sol.soloist.server.server.SoloistServiceServlet; public enum SubmitPerson implements Initializer{ INSTANCE; @Override public void init() throws InitializerFailedException { GUIApplicationComponent page = new GUIApplicationComponent(); page.setName("SubmitPerson"); SoloistServiceServlet.registerApplication(page); page.setContext(DefaultContextInit.getRoot()); GUIPanelComponent root = GUIPanelComponent.createFlow(page); GUILabelComponent title = GUILabelComponent.create(root, "Submit Person"); title.setStyle("titleStyle"); GUIPanelComponent topPanel = GUIPanelComponent.createFlow(root); topPanel.setStyle("topPanel"); GUIPanelComponent table = GUIPanelComponent.createTable(topPanel); int row = 0; GUILabelComponent.create(table, "Name: ", row, 0); GUIInput nameInput = GUIInput.createField(table, Text.CLASSIFIER, row++, 1); nameInput.addInitialValue(Text.fromString("New Person")); GUILabelComponent.create(table, "Gender: ", row, 0); GUIInput genderInput = GUIInput.createField(table, Repository.getRepository().getEnumeration(Gender.FQ_TYPE_NAME), row++, 1); GUILabelComponent.create(table, "Age: ", row, 0); GUIInput ageInput = GUIInput.createField(table, Integer.CLASSIFIER, row++, 1); GUILabelComponent.create(table, "Date of birth: ", row, 0); GUIInput dateOfBirthInput = GUIInput.createField(table, Date.CLASSIFIER, row++, 1); GUILabelComponent.create(table, "Height [m]: ", row, 0); GUIInput heightInput = GUIInput.createField(table, Real.CLASSIFIER, row++, 1); GUILabelComponent.create(table, "Is married: ", row, 0); GUIInput isMarriedInput = GUIInput.createField(table, Boolean.CLASSIFIER, row++, 1); // true is initial value isMarriedInput.setLowerBound(1); isMarriedInput.addInitialValue(Boolean.TRUE); // if you wish to allow marriage status to be undefined, i.e. a three-value combo (empty, yes, and no) instead of two value checkbox use this: // GUIElementComponent isMarriedInput2 =GUIInput.createField(table, Boolean.CLASSIFIER, row++, 1); // Take a look at the date picker in CSS. // Also, take a look at .gwt-TextBox-validation_failed and .dateBoxFormatError. // These define how these input widgets react when invalid values are typed in, // for example, if an invalid value "Java" is typed in the ageInput that accepts Integers. // Now let's create the buttons GUIPanelComponent hp = GUIPanelComponent.createHorizontal(topPanel); GUIButtonComponent createButton = GUIButtonComponent.create(hp, "Create Person", new CreatePerson()); createButton.setConfirmationRequired(true); createButton.setConfirmationMessage("Are you sure you want to create a person?"); // Let's now bind the button with input parameters' provider components GUIComponentBinding.create(nameInput.opValue(), createButton, CreatePerson.PROPERTIES.name); GUIComponentBinding.create(ageInput.opValue(), createButton, CreatePerson.PROPERTIES.age); GUIComponentBinding.create(genderInput.opValue(), createButton, CreatePerson.PROPERTIES.gender); GUIComponentBinding.create(dateOfBirthInput.opValue(), createButton, CreatePerson.PROPERTIES.dateOfBirth); GUIComponentBinding.create(heightInput.opValue(), createButton, CreatePerson.PROPERTIES.height); GUIComponentBinding.create(isMarriedInput.opValue(), createButton, CreatePerson.PROPERTIES.isMarried); // Let's reset input fields after command execution GUIComponentBinding.create(createButton.opCommandExecuted(), nameInput.ipReset()); GUIComponentBinding.create(createButton.opCommandExecuted(), ageInput.ipReset()); GUIComponentBinding.create(createButton.opCommandExecuted(), genderInput.ipReset()); GUIComponentBinding.create(createButton.opCommandExecuted(), dateOfBirthInput.ipReset()); GUIComponentBinding.create(createButton.opCommandExecuted(), heightInput.ipReset()); GUIComponentBinding.create(createButton.opCommandExecuted(), isMarriedInput.ipReset()); // Let's now create clear and reset form buttons // Note the difference between reset and clear: reset re-sets the initial values in the input fields, while clear actually makes them empty GUIButtonComponent clearButton = GUIButtonComponent.create(hp, "Clear Form"); GUIComponentBinding.create(clearButton.opClick(), nameInput.ipClearValue()); GUIComponentBinding.create(clearButton.opClick(), ageInput.ipClearValue()); GUIComponentBinding.create(clearButton.opClick(), genderInput.ipClearValue()); GUIComponentBinding.create(clearButton.opClick(), dateOfBirthInput.ipClearValue()); GUIComponentBinding.create(clearButton.opClick(), heightInput.ipClearValue()); GUIComponentBinding.create(clearButton.opClick(), isMarriedInput.ipClearValue()); GUIButtonComponent resetButton = GUIButtonComponent.create(hp, "Reset Form"); GUIComponentBinding.create(resetButton.opClick(), nameInput.ipReset()); GUIComponentBinding.create(resetButton.opClick(), ageInput.ipReset()); GUIComponentBinding.create(resetButton.opClick(), genderInput.ipReset()); GUIComponentBinding.create(resetButton.opClick(), dateOfBirthInput.ipReset()); GUIComponentBinding.create(resetButton.opClick(), heightInput.ipReset()); GUIComponentBinding.create(resetButton.opClick(), isMarriedInput.ipReset()); } }