Friday, 24 July 2015

Setting JAVA environment variable in local machine?

This tutorial to explain how to set the java home (JAVA_HOME) in local machine;

1.RightClick Mycomputer in that click Properties

2. After click properties will open new window in that click Advanced settings




















3.On Click on Advanced system settings it will open new window In system properties window click Environment Variables






4.In System Properties window click New  under system variables


5. Add Variable name and value in the text box and click ok.


6.finally in system variable double click path and add the path. 

7.Finally click apply and close the window.

8. By check open a command prompt and type java -version   it will should show the version.





Tuesday, 21 July 2015

Display error messages directly in Vaadin framework 7

In vaadin framework when a validation error occurred, it was not clear what the problem was. None of them thought about hovering their mouse over the error indicator (if they even noticed the indicator) to get the precise error message.I read in the Book of Vaadin that the placement of the error indicator is managed by the layout in which the component is contained. However, it doesn't seem to say anything about directly showing the error message.So i decided to do that.

For example here i am taking as simple example user object to validate

Model:

public class User extends BaseIsisEntity {

    private Integer id;
    private String territoryCode;
    private boolean disabled;
    private String title;
    private String firstName;
    private String middleName;
    private String lastName;
    private String homeTelephone;
    private String workTelephone;
    private String mobile1;
    private String mobile2;
    private String fax;
    private String emailAddress;
    private String website;
//Getter and setter

View:

public class EditUserView extends View{

private BeanFieldGroup<User> userBeanFieldGroup;

private Label errorLbl;



        VerticalLayout userFormLayout=new VerticalLayout();
        errorLbl = new Label("", ContentMode.HTML);
        userFormLayout.addComponent(errorLbl);
        TextField territoryCode = new TextField("Territory Code");
        territoryCode.setRequired(true);
        territoryCode.setRequiredError("Territory Code Required");
        userBeanFieldGroup.bind(territoryCode, "territoryCode");

        TextField firstnameField = new TextField("First Name");
        firstnameField.setRequired(true);
        firstnameField.setRequiredError("First Name Required");
        userBeanFieldGroup.bind(firstnameField, "firstName");
        userFormLayout.addComponent(firstnameField);

       TextField lastNameTxt = new TextField("Last Name");
        lastNameTxt.setRequired(true);
        lastNameTxt.setRequiredError("Last Name Required");
        userBeanFieldGroup.bind(lastNameTxt, "lastName");
        userFormLayout.addComponent(lastNameTxt);

       TextField middleNameTxt = new TextField("Middle Name");
        userBeanFieldGroup.bind(middleNameTxt, "middleName");
        userFormLayout.addComponent(middleNameTxt);

        TextField homeTelephoneText = new TextField("Home Telephone");
        homeTelephoneText.setRequired(true);
        homeTelephoneText.setRequiredError("Home Telephone is required");
        userBeanFieldGroup.bind(homeTelephoneText, "homeTelephone");
        userFormLayout.addComponent(homeTelephoneText);

       TextField workTelePhoneTxt = newTextField("Work Telephone");
        workTelePhoneTxt.setRequired(true);
        workTelePhoneTxt.setRequiredError("Work Telephone is required");
        userBeanFieldGroup.bind(workTelePhoneTxt, "workTelephone");
        userFormLayout.addComponent(workTelePhoneTxt);

        TextField mobile1Txt = new TextField("Mobile1");
        mobile1Txt.setRequired(true);
        mobile1Txt.setRequiredError("Mobile1 is required");
        userBeanFieldGroup.bind(mobile1Txt, "mobile1");
        userFormLayout.addComponent(mobile1Txt);

        TextField mobile2Txt = new TextField("Mobile2");
        mobile2Txt.setRequired(true);
        mobile2Txt.setRequiredError("Mobile2 is required");
        userBeanFieldGroup.bind(mobile2Txt, "mobile2");
        userFormLayout.addComponent(mobile2Txt);


        TextField emailAddressTxt = new TextField("Email Address");
        emailAddressTxt.setRequired(true);
        emailAddressTxt.setRequiredError("Email Address is required");
        userBeanFieldGroup.bind(emailAddressTxt, "emailAddress");
        userFormLayout.addComponent(emailAddressTxt);
         HorizontalLayout   buttonLayout=new HorizontalLayout();
        buttonLayout.addComponent(new Button("Save", new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {

                try {
                    userBeanFieldGroup.setBuffered(true);
                    userBeanFieldGroup.commit();
                    if (editObj.getId() == null) {
                       userService.add(editObj);

                    }
                } catch (FieldGroup.CommitException e) {
//This line is very important
                                                   errorLbl.setValue(ErrorUtils.showComponentErrors(userBeanFieldGroup.getFields()));
                }

            }
        }));
}

Util class:

public class ErrorUtils {

public static String showComponentErrors(final AbstractComponent[] componentArray) {
        List<String> errorList = ErrorUtils.getComponentError(componentArray);
        String error = StringUtils.join(errorList, "\n");
        return error;
    }

    public static String showComponentErrors(
            final Collection<?> componentCollection) {
        AbstractComponent[] componentArray = componentCollection
                .toArray(new AbstractComponent[] {});

        return ErrorUtils.showComponentErrors(componentArray);
    }
}

Thanks guys,

If you have any issue please don't hesitate to contact me. I am always happy to help....



Intellij IDEA: Error javac: source release 1.7 requires target release 1.7

In IntelliJ 13 and 14, check the Settings > Compiler > Java Compiler UI to ensure you're not targeting a different bytecode version in your module.
enter image description here                                                                          
To change the Target byte version to 1.7 .click apply to save the setting will resolve the issue.

Monday, 20 July 2015

Vaadin framework remove null in textfield when adding new object?

In Vaadin Framework whenever  we try to create a new record the object will show null value in Textfield and Textarea to avoid this  we should try like below .

TextField firstNameField=new TextField ("firstName");
firstNameField setNullRepresentation(" ");