Buttons in Form With Advanced Layout, how to place?

I welcome!

Confronted with the problem. For example, take the
form
as shown below -
12197.png

How do I put the button in this position? How do I put the button in this position? I would be very grateful for the information!:smiley:

Cheers,
Thx

I have GroupCargoRecord class implements Serializable :


...
    /**
     * @author
     */
    public class GroupCargoRecord implements Serializable {
        private String companyName = "";
        private String groupCargoName = "";

        private Integer currentYearPower = 0;
        private Integer nextYearPower = 0;
        private Integer year2015Power = 0;
        private Integer year2020Power = 0;
        private Integer year2030Power = 0;

        /**
         * @return
         */
        public String getCompanyName() {
            return companyName;
        }
        /**
         * @param companyName
         */
        public void setCompanyName(String companyName) {
            this.companyName = companyName;
        }
        /**
         * @return
         */
        public String getGroupCargo() {
            return groupCargoName;
        }
        /**
         * @param groupCargo
         */
        public void setGroupCargo(String groupCargoName) {
            this.groupCargoName = groupCargoName;
        }
        /**
         * @return
         */
        public Integer getCurrentYearPower() {
            return currentYearPower;
        }
        /**
         * @param currentYearPower
         */
        public void setCurrentYearPower(Integer currentYearPower) {
            this.currentYearPower = currentYearPower;
        }
        /**
         * @return
         */
        public Integer getNextYearPower() {
            return nextYearPower;
        }
        /**
         * @param nextYearPower
         */
        public void setNextYearPower(Integer nextYearPower) {
            this.nextYearPower = nextYearPower;
        }
        /**
         * @return
         */
        public Integer getYear2015Power() {
            return year2015Power;
        }
        /**
         * @param year2015Power
         */
        public void setYear2015Power(Integer year2015Power) {
            this.year2015Power = year2015Power;
        }
        /**
         * @return
         */
        public Integer getYear2020Power() {
            return year2020Power;
        }
        /**
         * @param year2020Power
         */
        public void setYear2020Power(Integer year2020Power) {
            this.year2020Power = year2020Power;
        }
        /**
         * @return
         */
        public Integer getYear2030Power() {
            return year2030Power;
        }
        /**
         * @param year2030Power
         */
        public void setYear2030Power(Integer year2030Power) {
            this.year2030Power = year2030Power;
        }
    }
...

…and GroupCargoRecordFieldFactory class extends DefaultFieldFactory -


...
    /**
     * @author 
     */
    private class GroupCargoRecordFieldFactory extends DefaultFieldFactory {
    	public GroupCargoRecordFieldFactory() {
        }
    	
        @Override
        public Field createField(Item item, Object propertyId, Component uiContext) {
            Field f;
            
            f = super.createField(item, propertyId, uiContext);            
            
            if("companyName".equals(propertyId)) {
                TextField tf = (TextField) f;
                tf.setCaption("Предприятие");
                tf.setRequired(true);                
                tf.setRequiredError("Поле \"Предприятие\" является обязательным для заполнения");                
                tf.setNullRepresentation("");
                tf.setNullSettingAllowed(true);
                tf.addValidator(new IntegerValidator("Мощность представляет собой целое"));
                tf.setWidth(COMMON_FIELD_WIDTH);
            } else if ("groupCargoName".equals(propertyId)) {
                TextField tf = (TextField) f;
                tf.setCaption("Группа груза");
                tf.setRequired(true);                
                tf.setRequiredError("Поле \"Группа груза\" является обязательным для заполнения");                
                tf.setNullRepresentation("");
                tf.setNullSettingAllowed(true);
                tf.addValidator(new IntegerValidator("Мощность представляет собой целое"));
                tf.setWidth(COMMON_FIELD_WIDTH); 
            } else if("currentYearPower".equals(propertyId)) {
                TextField tf = (TextField) f;
                tf.setCaption("Мощности на " + new DateCustom().getCurrentYear() + " год");
                tf.setRequired(true);                
                tf.setRequiredError("Поле " + tf.getCaption() + " является обязательным для заполнения");                
                tf.setNullRepresentation("");
                tf.setNullSettingAllowed(true);
                tf.addValidator(new IntegerValidator("Мощность представляет собой целое"));
                tf.setWidth(COMMON_FIELD_WIDTH);
            } else if("nextYearPower".equals(propertyId)) {
                TextField tf = (TextField) f;                
                tf.setCaption("Мощности на " + new DateCustom().getNextYear() + " год");
                tf.setRequired(true);                
                tf.setRequiredError("Поле " +  tf.getCaption() +  " является обязательным для заполнения");                
                tf.setNullRepresentation("");
                tf.setNullSettingAllowed(true);
                tf.addValidator(new IntegerValidator("Мощность представляет собой целое"));
                tf.setWidth(COMMON_FIELD_WIDTH);
            } else if("year2015Power".equals(propertyId)) {
                TextField tf = (TextField) f;
                tf.setCaption("Мощности на 2015 год");
                tf.setRequired(true);                
                tf.setRequiredError("Поле " +  tf.getCaption() +  " является обязательным для заполнения");                
                tf.setNullRepresentation("");
                tf.setNullSettingAllowed(true);
                tf.addValidator(new IntegerValidator("Мощность представляет собой целое"));
                tf.setWidth(COMMON_FIELD_WIDTH);
            } else if("year2020Power".equals(propertyId)) {
                TextField tf = (TextField) f;
                tf.setCaption("Мощности на 2020 год");
                tf.setRequired(true);                
                tf.setRequiredError("Поле " +  tf.getCaption() +  " является обязательным для заполнения");                
                tf.setNullRepresentation("");
                tf.setNullSettingAllowed(true);
                tf.addValidator(new IntegerValidator("Мощность представляет собой целое"));
                tf.setWidth(COMMON_FIELD_WIDTH);
            } else if("year2030Power".equals(propertyId)) {
                TextField tf = (TextField) f;
                tf.setCaption("Мощности на 2030 год");
                tf.setRequired(true);                
                tf.setRequiredError("Поле " +  tf.getCaption() +  " является обязательным для заполнения");                
                tf.setNullRepresentation("");
                tf.setNullSettingAllowed(true);
                tf.addValidator(new IntegerValidator("Мощность представляет собой целое"));
                tf.setWidth(COMMON_FIELD_WIDTH);
            }
            return f;
        }
    }
...

…also - attachField method in class, extends Form class:


...
        @Override
        protected void attachField(Object propertyId, Field field) {
            if(propertyId.equals("companyName")) {
        		gridLayout.addComponent(field, 0, 1);
        	} else if (propertyId.equals("groupCargoName")) {
            	gridLayout.addComponent(field, 1, 2);
            } else if (propertyId.equals("currentYearPower")) {
            	gridLayout.addComponent(field, 1, 3);
            } else if (propertyId.equals("nextYearPower")) {
            	gridLayout.addComponent(field, 1, 4);
            } else if (propertyId.equals("year2015Power")) {
            	gridLayout.addComponent(field, 1, 5);
            } else if (propertyId.equals("year2020Power")) {
            	gridLayout.addComponent(field, 1, 6);
            } else if (propertyId.equals("year2030Power")) {
            	gridLayout.addComponent(field, 1, 7);
            }
        }

...

I need to button near companyName field and another button near groupCargoName (the dialog’s will be invoked).
Does anyone know? :smiley:

The following method does not give effect -


...
Field f;
...

            	HorizontalLayout hl = (HorizontalLayout)f;
                TextField tf = new TextField();
                Button b = new Button();
                
                tf.setCaption("Предприятие");
                tf.setRequired(true);                
                tf.setRequiredError("Поле \"Предприятие\" является обязательным для заполнения");                
                tf.setNullRepresentation("");
                tf.setNullSettingAllowed(true);
                tf.addValidator(new IntegerValidator("Мощность представляет собой целое"));
                tf.setWidth(COMMON_FIELD_WIDTH);

                hl.addComponent(tf);
                hl.addComponent(b);

...
return f;
...

Hi,

I would try two ideas in this case. First, uglier one - is to tweak the content layout of the form. I mean you create a GridLayout, specify the number of rows/columns and add a Button so it is in a proper place (make sure that the FieldFactory will not try to add any fields in that cell). The other approach that I would rely on is a

СustomField add-on

. With it’s API you can wrap the button and a textfield into one field and attach it directly in the FieldFactory.

//sasha

I welcome you, Alexander V Pchelintsev!

Many thanks for the info! :smiley:
…Whew! The second method seems more interesting to me too, I’ll try to start.:smiley:

You can also have a look at the
FormBinder add-on
and the pre-created fields pattern.
With that you can create your layout and let the form only connect the fields with your properties.

Claudio

I welcome you, Claudio Crociati !

Hmm… Great idea! :smiley:
Many thanks for the link, I will definitely try this add-on too! :smiley:

Cheers,
Thx