Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

Form with imageFile field messes up character encoding

$
0
0
SmartClient Version: v10.0p_2015-07-14/Pro Deployment (built 2015-07-14)

I have a problem similar to the one described in this thread: http://forums.smartclient.com/showthread.php?t=18959

I have a form with the following datasource:
Code:

<DataSource 
        ID="user_userPref"
        serverConstructor="it.forecast.server.servlets.user.UserPrefServlet">
        <fields> 
                <field name="id"                type="sequence"                hidden="true"                        align="left"                        primaryKey="true"        />
                <field name="email"                type="text"                title="Email"                        align="left"        length="255"        required="true"                />
                <field name="initials"                type="text"                title="Initials / Short Name"        align="left"        length="5"        required="true"                />
                <field name="firstName"                type="text"                title="First Name"                align="left"        length="255"        required="true"                />
                <field name="lastName"                type="text"                title="Last Name"                align="left"        length="255"        required="true"                />
                <field name="startPage"                type="radio"                title="Start Page"                align="left"                        required="true"                />
                <field name="profilePicture"        type="imageFile"        title="Profile Picture"                align="left"                                                />
                <field name="oldPassword"        type="text"                title="Old Password"                align="left"        length="255"        required="true"                />
                <field name="password1"                type="text"                title="New Password"                align="left"        length="255"                                />
                <field name="password2"                type="text"                title="Repeat New Password"        align="left"        length="255"                                />
        </fields>
</DataSource>

My problem is that when I try to save local characters (in this case danish æøåÆØÅ) in for example the first or last name field, then when it reaches the servlet the encoding is wrong and it tries to save a Replacement character (\xEF\xBF\xBD) in the database instead.

If I remove the imageFile field from the form it works fine and I can save special characters in my database.

Form is created as follows:
Code:

                Map userPrefCriteria = new HashMap();
                userPrefCriteria.put("id", sessionManager.user.getUserId());
               
                DataSource userPrefDS = DataSource.get("user_userPref");
                userPrefDS.setDefaultParams(sessionManager.extendParams(userPrefCriteria));
               
                newForm = new DynamicForm();
                newForm.setDataSource(userPrefDS);
                newForm.setTitleOrientation(TitleOrientation.TOP);
                newForm.setNumCols(1);
                newForm.setWidth(FIELD_WIDTH);
                newForm.setAutoFetchData(true);
                newForm.setHeight(240);
                newForm.setCellPadding(4);
                newForm.setAlign(Alignment.CENTER);
                newForm.setLayoutAlign(Alignment.CENTER);
                newForm.setWrapItemTitles(false);
                newForm.setErrorOrientation(FormErrorOrientation.TOP);
                newForm.setShowErrorText(true);
               
                userName = new TextItem("email", sessionManager.getText("PREF_USER_NAME"));
                RegExpValidator emailValidator = new RegExpValidator();
                emailValidator.setExpression(EMAIL_REGEXP);
                emailValidator.setErrorMessage(sessionManager.getText("PREF_VALID_EMAIL"));
                userName.setValidators(emailValidator);
                userName.setDisabled(true);
                userName.setWidth("*");
               
                TextItem initials = new TextItem("initials","Initials / Short Name");
                initials.setRequired(true);
                initials.setWidth("*");

                TextItem firstName = new TextItem("firstName", sessionManager.getText("PREF_USER_FNAME"));
                firstName.setRequired(true);
                firstName.setWidth("*");

                TextItem lastName = new TextItem("lastName", sessionManager.getText("PREF_USER_LNAME"));
                lastName.setRequired(true);
                lastName.setWidth("*");
               
                LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>();
                valueMap.put("Dashboard", "Home");
                valueMap.put("Projects", "All Projects");
               
                RadioGroupItem radioGroupItem = new RadioGroupItem("startPage"); 
                radioGroupItem.setTitle("Login Start Page");
                radioGroupItem.setValueMap(valueMap);
               
                FileItem imageItem = new FileItem("profilePicture");
                imageItem.setWidth("*");
               
                oldPassword = new PasswordItem();
                oldPassword.setName("oldPassword");
                oldPassword.setTitle(sessionManager.getText("PREF_USER_OPASS"));
                oldPassword.setRequired(true);
                oldPassword.setLength(20);
                oldPassword.setWidth("*");
               
                passwordItem = new PasswordItem();
                passwordItem.setName("password");
                passwordItem.setTitle(sessionManager.getText("PREF_USER_NPASS1"));
                if (fromNewUser) {
                        passwordItem.setRequired(true);
                } else {
                        passwordItem.setRequired(false);
                }
                       
                passwordItem.setLength(20);
                passwordItem.setWidth("*");

                passwordItem2 = new PasswordItem();
                passwordItem2.setName("password2");
                passwordItem2.setTitle(sessionManager.getText("PREF_USER_NPASS2"));
                if (fromNewUser) {
                        passwordItem2.setRequired(true);
                } else {
                        passwordItem2.setRequired(false);
                }
                passwordItem2.setLength(20);
                passwordItem2.setWidth("*");

                MatchesFieldValidator matchesValidator = new MatchesFieldValidator();
                matchesValidator.setOtherField("password");

                matchesValidator.setErrorMessage(sessionManager.getText("PREF_USER_PASS_VALID"));       
                passwordItem2.setValidators(matchesValidator);
               
                final ForecastButton saveAndCloseButton = new ForecastButton(ButtonStyle.GREEN, sessionManager.getText("SAVE_AND_CLOSE_BUTTON"));
                saveAndCloseButton.addClickHandler(new ClickHandler() {
                        public void onClick(ClickEvent event) {

                                newForm.saveData(new DSCallback() {

                                        @Override
                                        public void execute(DSResponse response, Object rawData,
                                                        DSRequest request) {
                                                Record data = response.getData()[0];
                                                int result = data.getAttributeAsInt("result");
                                                final String userInitials = response.getData()[0].getAttributeAsString("initials");
                                                final String startPage = response.getData()[0].getAttributeAsString("startPage");
                                                oldPassword.setValue("");
                                                if (result == 0) {
                                                        SC.say("Error", "Old password is incorrect!");
                                                } else if (result == 1) {
                                                        // If we have just uploaded a new profile picture
                                                        if(data.getAttribute("profilePicture_date_created") != null && sessionManager.pMenuWidget != null)
                                                        {
                                                                sessionManager.profilePictures.remove(sessionManager.user.getUserId());
                                                                sessionManager.pMenuWidget.refreshProfilePicture();
                                                        }
                                                       
                                                        SC.say("Success",
                                                                        "User preferences succesfully updated.",
                                                                        new BooleanCallback() {
                                                                                public void execute(Boolean value) {
//                                                                                        System.out.println("Press OK");
                                                                                        reportWindow.clear();
                                                                                        if (fromNewUser) {
                                                                                                if(loginWidget != null)
                                                                                                        loginWidget.processSignIn(sessionManager.user.userName, passwordItem2.getValueAsString());
                                                                                               
                                                                                               
                                                                                        } else {
//                                                                                                System.out.println("From new user FALSE");
                                                                                                sessionManager.user.setInitials(userInitials);
                                                                                                sessionManager.user.setStartPage(startPage);
                                                                                        }
                                                                                }
                                                                        });
                                                }
                                        }
                                });
                        }
                });

                newForm.setFields(userName, initials, firstName, lastName, radioGroupItem, imageItem, oldPassword, passwordItem, passwordItem2);
               
               
                HLayout b = new HLayout();
                b.addMember(saveAndCloseButton);
                b.setAlign(Alignment.CENTER);
                b.setLayoutAlign(Alignment.CENTER);
               
                HLayout f = new HLayout();
                f.addMember(newForm);
                f.setHeight(240);
                f.setAlign(Alignment.CENTER);
                f.setLayoutAlign(Alignment.CENTER);
               
                Label projectLabel = new Label();
                projectLabel.setContents("Preferences");
                projectLabel.setStyleName("pageSubTitle");
                projectLabel.setTop(75);
                projectLabel.setValign(VerticalAlignment.BOTTOM);
                projectLabel.setAlign(Alignment.LEFT);
                projectLabel.setLayoutAlign(VerticalAlignment.CENTER);
                projectLabel.setHeight(30);
                projectLabel.setWidth(FIELD_WIDTH);


                //Create layout of the widget
                VLayout parentLayout = new VLayout(10);
                parentLayout.setDefaultLayoutAlign(VerticalAlignment.TOP);
                parentLayout.addMember(f);
                parentLayout.addMember(b);
                parentLayout.setMargin(15);
                parentLayout.setWidth100(); // get the entire width
                parentLayout.setHeight(280); // get the entire height


                reportWindow = new Window();
                reportWindow.setWidth(360);
                reportWindow.setHeight("95%");
                reportWindow.setTitle("Preferences");
                reportWindow.setAlign(Alignment.CENTER);
                reportWindow.setLayoutAlign(Alignment.CENTER);
                reportWindow.setShowMinimizeButton(false);
                reportWindow.setIsModal(true);
                reportWindow.setShowModalMask(true);
                reportWindow.centerInPage();
                reportWindow.setCanDragReposition(false);
                reportWindow.addItem(projectLabel);
                reportWindow.addItem(parentLayout);
                reportWindow.draw();


Viewing all articles
Browse latest Browse all 4756

Trending Articles