Violet_82 89 Posting Whiz in Training

OK, so I've done a bit of thinking and started coding. As you might know, when you start a maven project you get automatically a UI class, which I leave on the side for now, but I reckon that class will have the labels and all the GUI fields.
To start with, I created a ConverterModel class, which should contain the conversion logic.
So far it contains setters and getters, but I run into a problem:

package com.vaadin.project.converterRedone;

import com.vaadin.ui.CustomComponent;

public class ConverterModel extends CustomComponent {

    private double unitToConvert;
    private double multiplier;
    public void setUnitToConvert(double unitToConvert){
        this.unitToConvert = unitToConvert;     
    }
    public void setMultiplier(double multiplier){
        this.multiplier = multiplier;
    }
    private void doConversion(){
        //TODO:do the conversion
    }
}

So the problem is that to do the conversion I don't have to multiply all the time, but occasionally divide. So, say, to convert miles to km I multiply miles by 1.6, to convert km to miles I multiply km by 0.62 etc. If it was always a multiplication I could easily do it in the doConversion method, but to convert metres to yards I will have to divide metres by 0.9144: what I'm trying to say is that it's difficult to keep this doConversion a general method because I have to perform divisions and multiplications depending on what I want to convert to. So I will have to have a mechanism in place to decide whether it's going to be a multiplication or division. Does it make sense?

Violet_82 89 Posting Whiz in Training

OK, sorry, I replied too quickly, let me update my app and see where I get to

Violet_82 89 Posting Whiz in Training

all done, I'm on java 8.

Violet_82 89 Posting Whiz in Training

jkon, I'm already doing both these things but the value of the accept attribute is not reflected inside the dropdown box. The image attached above was just a demonstration, but the gist of it is that, my accept attribute has something like ".jpeg,.png" but inside the dropdown when I try to upload a file in my own application I don't get
.jpeg
.png
I only get all files and custom (or something along those lines, I don't have the application here with me right now)

Violet_82 89 Posting Whiz in Training

OK I will give it a go, hopefully I don't break anything :-)!

Violet_82 89 Posting Whiz in Training

thanks, I will look at reorganising my code in the first few classes first, and make sure that they work. About the conversion methods then, yes I will be using setters and getters pretty much like I did in my own class. I looked at your code as well of course, but I'm not sure how do you make the application scalable when it comes to converting values? You can get/set the values of the fields but you still need to make the actual conversion, so, for example, in the case of km to miles, you still need the formula, or are you thinking to have one general method taking, for example, the km and the value it needs to be multiplied for in order to get the miles?

Violet_82 89 Posting Whiz in Training

Hi, I'm thinking to upgrade from java sdk 7 to 8 (JamesCherrill will be pleased,lol!) and I was just wondering if there is anything I need to be careful with, especially in eclipse. I will start first with Windows, and then do the same thing in Ubuntu.
My eclipse seems to be configured to use Java 7, so presumably I will have to change the options in there too, does anybody know exactly what needs to be changed?
Generally speaking I suppose it's just a matter of downloading the sdk 8 and installing it and changing a few options in Eclipse, right?

Violet_82 89 Posting Whiz in Training

thanks, I will start with the coding then.
About Java 7 vs 8, you're absolutely right, but the company I work for is still using 7, and it will move to 8 apparently at the end of the year. The think is, at home, since they use java 7 I decided to use java 7 too, but maybe I should upgrade to 8 (I think I have the jdk7 installed and not 8)

Violet_82 89 Posting Whiz in Training

Hi guys, I have an application which allows users to upload a file. I managed to limit the types of files they can upload (the accept property helped) but I also want to do something else: when you upload a file and you click the browse button, as we know, an OS window with your local file system opens up and you can select your file from there. On this window, on the bottom right there is usually a drop down list of files, which shows which files you can upload as default selection. But you can open that menu and upload any file. Now, is there any way to change the list in that drop down list and have only the allowed files rather than all the possible file types? I know it's possible with jquery plugins, but can it be done without plugins and just with jquery or pure javascript?
In case you're not sure what I'm talking about, here is an image which has that list displayed, I want to be able to change the options in there
fileSelection.jpg

Violet_82 89 Posting Whiz in Training

Thanks for the code, unfortunately I have hava 7 so it won't run, but nevermind, the main thing is the code and how it is arranged.
So, maybe we should devise a plan then to give a better structure to my converter.
Should I follow your example and do it in steps, like, creating a class that just make the conversion and then test it in the console?

These are the classes I think I can have, let me know if this is reasonable
1)a class doing the conversions, containing the actual conversion plus all the other methods like, clearing the inputs, setters and getters : is the approach I took in my code OK, meaning a kmToMiles method, a MilesToKm one and any other I need?
2)a class with the various components like radio buttons, input fields etc
3)a UI class - which comes as default for each maven project - and which will attach the components above to the UI
4)validation class

Violet_82 89 Posting Whiz in Training

Thanks, sorry I thought that separation (GUI and component class) was enough.
I've never been lucky enough to have Java homework!
Yes, I would very much appreciate some examples, so I can refactor the converter. Before that though, what do you mean by architecture and structure?

separation of user interface from logic

Right, so you're basically saying that buttons and input fields should be in a class and click handlers and validation in another one?
thanks

Violet_82 89 Posting Whiz in Training

Right chaps, it took me a little longer as I didn't have much time, but the converter, version 1.0, is built and it's working. Before we look at the code, a couple of things. I'm not sure the way I built is the best way though. Basically, for each type of conversion (I have only two at the moment but I will add more) I have a static final variable, like private static final String conversion1 = "Km to miles"; etc. The disadvantage is that whatever new conversion I want to add, I have to add another variable here, another statement within the switch statement to figure out what conversion I'm trying to make etc. Of course I'm not a seasoned java developer so there is an awful lot I don't know, and I might have taken the wrong approach. I tried to keep in mind your suggestions as well, but I eventually decided I will go with a button that, when click, kicks things started - that's perhaps because I'm old school and I like the user to have control.
When the application starts you only get the options (in my case 2), when you click on one of the radio buttons you get an input field, a submit button and a reset button. When you type your value to convert in the input field (assuming it's a number) when you click submit you get a result input field with the conversion result. If you don't input anything …

Violet_82 89 Posting Whiz in Training

thanks, I will try and I will post back in this thread when I have a bit of code, so I leave this open

Violet_82 89 Posting Whiz in Training

That's interesting stultuske. I think I start with different packages now, but the idea of separating things with projects is nice. I will ask at work what they do, if they use more the packages approach or the project one
thanks

Violet_82 89 Posting Whiz in Training

Ah, I see what you mean, but I presume that's more applicable to large scale projects, to save time and resources. In any case the answer to your question is no, I wouldn't necessarily want to create a new release of the whole thing. How do you link different projects then?

Violet_82 89 Posting Whiz in Training

Yep I understand now, and I will give that turorial a good read too, thanks for clarifying things.

Violet_82 89 Posting Whiz in Training

I've been monitoring everything closely, and the number of successful new signups per day has not been affected as a result of requiring a match profile.

Fair enough, you have the stats I don't, mine is just a feeling.

users don't know what they want until they're presented with it

Partly true, but my point is that it doesn't feel good to impose something on it, rather than giving them the choice to bypass it. Then again, mine are just suggestions, that's what I think

Violet_82 89 Posting Whiz in Training

Google does not, and advertisers do not, and it's just not a profitable business model moving forward

I appreciate that but if that puts off posting it's not profitable for you too

In the not-so-distant future, there will be a strong incentive to filling it in correctly as your responses will heavily modify DaniWeb's behavior.

Have you thought about a poll to see what users think about it? If the majority agrees then it will be more of an incentive for you to steer things towards that direction, if not, then you know that doing so won't make everybody happy

Violet_82 89 Posting Whiz in Training

that's what I usually do with vaadin, meaning I implement the UI in vaddin, like layout (vertical, horizontal etc), components (in the case of the converter application the various text fields, and the possible options) and then in a separate class I'd implement the logic. Is that what you meant stultuske? Of course open to other suggestions, at the end of the day I'm only learning
cheers

Violet_82 89 Posting Whiz in Training

I see, thanks. I think i might have had the wrong idea about the try/catch statement, that's why I didn't consider that option AssertNull.

You put code that potentially throws an exception in the try block

I took that literally, meaning that I'd put in there only the code that would trrow an exception, in this case divisionResult = ( Integer.parseInt(getDividend()) / Integer.parseInt(getDivisor())); and nothing else. Since result.setValue(parseInt(divisionResult)); doesn't throw an exception but it's a direct consequence of not having an exception, I wouldn't have ever considered to put it there, and I guess that's where I was stuck

Violet_82 89 Posting Whiz in Training

In a way it's all good to keep up with the times, but still you're essentially forcing users to fill that "matching profile". I reckon that if it wasn't mandatory I might even fill it in...properly I mean. What I'm saying is that users should really be able to bypass it rather than being forced to fill it in. Luckily on my home computer I'm still logged in, so I can still get on the forum, but when for one reason or another I will log out and have to fill the profile in I will probably give the most random and silly answers I could think of. I'm not trying to be annoying, I just really hate the idea of having to do something I don't want to in order to access the forum. And I reckon this is the kind of thing that put people off...well certainly me: if I log in onto a website and there is anything that prevents me from doing what I came in to do, that's tough, I'll leave the website. Not trying to be harsh, but I suspect that's the case for quite a few people.

Itsdigger commented: I hear ya, I was messing with a Linux distro yesterday and tried logging in and lied my way through the whole process. +0
Violet_82 89 Posting Whiz in Training

thanks guys. Now, regardless of the way I do it, I still need a mechanism to determine whether the inputs are valid or not, that's where I think I got stuck, sorry maybe I didn't explain the issue correctly. So, for example, where I have the try/catch statement:

try{
                divisionResult = ( Integer.parseInt(getDividend()) / Integer.parseInt(getDivisor()));
            }
            catch(ArithmeticException arithmeticException){
                System.err.println("Zero is an invalid denominator!");
                createError("Divisor can't be 0!! Please enter a number  > 0!");
            }       
            catch(NumberFormatException numberFormatException){
                System.err.println("The dividend or divisor are not a number! Please enter a valid number!");
                createError("The dividend or divisor are not a number! Please enter a valid number!");
                }

say that the inputs are valid, my divisionResultgets the result and now it's just a matter of filling the text field with the value in divisionResult so I can just write something like result.setValue(parseInt(divisionResult));; trouble is though, wherever I do it, I still need a way to say "if the result is valid, then do result.setValue(parseInt(divisionResult));". So perhaps I can assign the result a value of 'null' inside the catch statements so I know that everytime the result is null it means that either the dividend or divisor, or both, are not valid and that gives me the condition I need, so I can write
if result !null then display the result

Violet_82 89 Posting Whiz in Training

That's what I meant, you just can't get in unless you fill all that in. In fact, when I was trying this morning, I simply gave up.

Violet_82 89 Posting Whiz in Training

No hijack at all AssertNull, quite the contrary, you raised some good valid points. Personally, I agree with you, I'd rather have a button than not because it makes me feel more in control and if the button is big enough it will be OK in touch devices like phones etc (not that I plan to make that application available to anyone as it's just an exercise).
As for tht silly Vaadin, I personally hate it, but alas, that's what it seems I have to do

Violet_82 89 Posting Whiz in Training

while you guys are 100% right, unfortunately I have to use that framework, wheter I want it or not, because that's what they use at work and I have to get more and more familiar with it, and pretty quickly. And so I thought that a converter wouldn't be too difficult to implement.
As you probably know, I also need to practice Java and I thought I'd combine the two things together.

Violet_82 89 Posting Whiz in Training

HI, I was trying to log in onto my account from another machine and I got to a page asking me to fill my Match Profile, with no way to cancel it. That doesn't seem right, what if I don't want to do that? Not sure why you guys are forcing that on users?!

rproffitt commented: Fine question. Good thing you asked as I was just about to travel. +0
Violet_82 89 Posting Whiz in Training

Hi guys, I have a question about error handling. Still working on the addition application and now that I've learned what are the correct exceptions to handle I'm not sure what to do when I've established that the my inputs are all valid and print my result. Let's have a look at the calculator class again:

package my.vaadin.project.exceptionTest;    
import java.awt.Component;
import java.util.InputMismatchException;    
import com.vaadin.server.Page;
import com.vaadin.shared.Position;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Notification;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.event.Action;

public class Calculation extends CustomComponent{
    final VerticalLayout vl = new VerticalLayout();
    final TextField dividend = new TextField();
    final TextField divisor = new TextField();

    final TextField result = new TextField();
    final Button resetButton = new Button("Reset");
    private int divisionResult = 0;
    Button button = new Button("Click Me");

    public Calculation(){
        dividend.setCaption("Enter the dividend:");
        divisor.setCaption("Enter the divisor:");

        result.setCaption("Result");
        result.setReadOnly(true); 
        button.addClickListener( new Button.ClickListener(){
            @Override
            public void buttonClick(ClickEvent event) {
                System.out.println("this is a test");   
                validateInputs();
            }            
        });
        resetButton.addClickListener(new Button.ClickListener(){            
            @Override
            public void buttonClick(ClickEvent event) {
                setDividend("");
                setDivisor("");             
                setResult("");
            }
        });
        vl.setMargin(true);
        vl.setSpacing(true);
        vl.addComponents(dividend, divisor, button, result );

    }//end of constructor
    public void validateInputs(){
        System.out.println("theDivisor is " + getDivisor() + " theDividend " + getDividend());
        try{
            divisionResult = ( Integer.parseInt(getDividend()) / Integer.parseInt(getDivisor()));
        }
        catch(ArithmeticException arithmeticException){
            System.err.println("Zero is an invalid denominator!");
            createError("Divisor can't be 0!! Please enter a number  > 0!");
        }
        /*catch(InputMismatchException inputMismatchException){
            System.err.println("The dividend or divisor are not a number! Please enter a valid number!");
            createError("The dividend or divisor are not a number! Please enter a valid number!");
        }*/
        catch(NumberFormatException numberFormatException){
            System.err.println("The dividend or divisor …
Violet_82 89 Posting Whiz in Training

HI guys, as my next application I thought I'd build a simple converter, something that allows me to convert from, say, Km to miles and so on. The framework I will use is vaadin (unfortunately) but it will still be java anyway :-).
So, I just thought I'd see if anybody has some good suggestions really. This is how I think I could go about it.
The UI class will obviously hold the GUI stuff, so no need to talk about it. I will have another class, converter.java which will have a list of options as radio button selection, something like
-From Km to miles
-From miles to Km
-From F to C
etc
Then when you make your selection you get some text fields to input data, a click button to confirm and process your selection and then another text field for displaying the results.
The text fields to input data will probably be always the same 2 for all the options rather than having to create two for each options and they will be displayed/hidden as necessary
How does that sound?

Violet_82 89 Posting Whiz in Training

Sorry for the late reply, I haven't logged in for quite a while, thanks for that, I will have a good look at it

Violet_82 89 Posting Whiz in Training

Ah, thanks, I got the wrong exception!

Violet_82 89 Posting Whiz in Training

Hi guys,
I have a simple application which allows users to input a divisor, a divident and then calculates the quotient.
I'm using vaadin as framework but I don't think that matters.
So I've been thinking about the exceptions that can occurr and these are the ones i have identified:
-Division by 0: ArithmeticException;
-Users typing a string rather than a number: InputMismatchException
Here is the class that creates the form and deals with the exceptions (I'm not including the UI class as it's not needed):

package my.vaadin.project.exceptionTest;

import java.awt.Component;
import java.util.InputMismatchException;

import com.vaadin.server.Page;
import com.vaadin.shared.Position;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Notification;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.event.Action;

public class Calculation extends CustomComponent{
    final VerticalLayout vl = new VerticalLayout();
    final TextField dividend = new TextField();
    final TextField divisor = new TextField();

    final TextField result = new TextField();
    final Button resetButton = new Button("Reset");
    private int divisionResult = 0;
    Button button = new Button("Click Me");

    public Calculation(){
        dividend.setCaption("Enter the dividend:");
        divisor.setCaption("Enter the divisor:");

        result.setCaption("Result");
        result.setReadOnly(true); 
        button.addClickListener( new Button.ClickListener(){
            @Override
            public void buttonClick(ClickEvent event) {
                System.out.println("this is a test");   
                validateInputs();
            }            
        });
        resetButton.addClickListener(new Button.ClickListener(){            
            @Override
            public void buttonClick(ClickEvent event) {
                setDividend("");
                setDivisor("");             
                setResult("");
            }
        });
        vl.setMargin(true);
        vl.setSpacing(true);
        vl.addComponents(dividend, divisor, button, result );

    }//end of constructor
    public void validateInputs(){
        System.out.println("theDivisor is " + getDivisor() + " theDividend " + getDividend());
        try{
            divisionResult = ( Integer.parseInt(getDividend()) / Integer.parseInt(getDivisor()));
        }
        catch(ArithmeticException arithmeticException){
            System.err.println("Zero is an invalid denominator!");
            createError("Divisor can't be 0!! Please enter a number  > 0!"); …
Violet_82 89 Posting Whiz in Training

Sorry I should have said, I have already installed the subversion plug in in Eclipse. I think my question is more about where do I go from there, and if, in addition to that, there is more. In any case, it seems like I've been able to import the project from my working folder. This is what I did, just for clarity and sanity check:
1) I have my original project open in eclipse, let's call it my_project (this has been set up before doing any svn operation, it's my original project)
2)I created a repository folder called svn_repos
3)on my workspace I imported the my_project folder into the repository using the tortoise command import
4)created a folder Projects/my_project where I checked out a version of my project with the SVN checkout command
5)In eclipse, I removed the original project my_project and deleted it from the workspace as well
6)Still in eclipse I added a new repository location pointing it to file:///c:/svn_repos, then navigated to trunk and found a folder called my_project 2 (not entirely sure why it says 2 but hey), checked that out as a project with the name specified and I have a fresh copy of my project set up in eclipse, I compiled it and it works OK.

Now the questions:
1)is the above right?
2)If I want to make some changes to the files, how do I commit those changes through eclipse? SHould it be done …

Violet_82 89 Posting Whiz in Training

HI guys, I'm really new to SVN and today I've installed tortoise as I'm working in windows at the moment and I'm following this tutorial https://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-qs-guide.html. So, I have a java project in Eclipse: I have created a local repository folder on my machine and imported a project in it. I've also created another folder where I've checked out the working copy of my project. Now, in Eclipse don't forget I still have open the original version of the project, what should I do with it? Should I just delete it and load instead the hecked out one?
thanks

Violet_82 89 Posting Whiz in Training

thanks, I knew detach() kept the data somehow as opposed to remove(), but in the thread there is a nice example http://jsfiddle.net/L6CEA/ which is in fact self explanatory and helpful and clearly shows how one keeps the jquery data and the other one discards it. That's good to know!

Violet_82 89 Posting Whiz in Training

Here is something interesting about detach() vs remove() in jquery that happened to me.
As we know, remove() removed an element from the DOM wherease thedetach() does the same thing but it keeps all the jquery events bound to the element to which the method is applied to.
I have an application which allows users to upload and validate some files. The form sits in a popup which is triggered by a normal button on the page. When the popup is open users can upload a file (only one) using a input of type file and send it via ajax to the server when they submit the form.
The popup has a close button and when it is pressed the popup was detached using detach() from the DOM and the input field cleared. What happened was that every time I reopened the popup and upload a new file, somehow I ended up with more than one file, the one uploaded plus the other ones I uploaded before (one for each session), unless I ctrl + f5. Specifically, when I pressed the browse button, selected a file from the file system and pressed open, I would get the same file system window again, once, twice, three times, depending on home many times I had so far uploaded a file.
I replaced detach() with remove() and so not only I remove the popup from the DOM when the close button is pressed, but I also remove the associated …

Violet_82 89 Posting Whiz in Training

I'd like to start from the basics if I may please. I've read a few tutorial here and there and I've just created a test application with probably the simplest RPC calls you can possibly have (basically I want to use the RPC call to call a method to print a string). I'm using Eclipse and I've created a maven project, loosely based on this tutorial and the following ones but things are not working very well (forgive me but I'm new to vaadin and still learning java). This is the structure of my project, including packages (the structure is just the one of a normal maven project):

src/main/java        
    -test_proj.rpc_1
        -MyComponent.java
        -MyUI.java
    -test_proj.rpc_1.client
        -MyComponentClientRpc.java
        -MyComponentServerRpc.java
        -MyComponentConnector.java
        -MyComponentWidget.java
src/main/resources
    -test_proj    
        -rpc_1    
            -MyAppWidgetset.gwt.xml

Right, so here is the content of the classes. MyComponent.java: implements and registers the RPC interface

package test_proj.rpc_1;
import test_proj.rpc_1.client.MyComponentServerRpc;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.TextField;
public class MyComponent extends AbstractComponent
{
    public String text = "";
    private MyComponentServerRpc rpc = new MyComponentServerRpc()
    {
        @Override
        public void setString(String myString)
        {
            System.out.println("setString() called. myString is " + myString);
        }
    };
    public MyComponent() {
        registerRpc(rpc);
        System.out.println("MyComponent called");
        final TextField name = new TextField();
        name.setCaption("another label.");
    }
}

MyComponentClientRpc.java: still empty at the moment as I'm not sure what goes in it

package test_proj.rpc_1.client;
import com.vaadin.shared.communication.ClientRpc;
public interface MyComponentClientRpc extends ClientRpc
{
}

MyComponentServerRpc.java: contains the abstract method I want the RPC call to use:

package test_proj.rpc_1.client;
import com.vaadin.shared.communication.ServerRpc;
public interface MyComponentServerRpc extends ServerRpc
{
    public void setString(String string);
}
Violet_82 89 Posting Whiz in Training

It's certainly an idea, but I'm not sure if I'm actually capable of doing that, I'll give it some thought

Violet_82 89 Posting Whiz in Training

Hi guys, I wonder if you can help.
As I've started as a programmer, I've been told I have to practice OO a bit more. I've done the theory, but I think I will have to take another look at it. , Above all though, I have to do exercises.
What I'm looking for is for suggestions: things I have to practice are:
-Inheritance
-Interfaces
-Polymorphism
-And in general anything to do with OO.
Ideally I don't really need to do any complicated exercise, even simple scenarios would do as long as I can put into practice the theory, printing some user input strings might be enough as long as I can implement 00 principles, so things like, an emplyoee hierarchy or something along these lines.
Also I know Im a bit weak when it comes to linking different classes together, and things like composition.
So, can anybody suggest simple situation/s I could use to practice?
I have installed the Spring Tool Suite but if I'm not mistaken I can use it to create ordinary java projects.
Any idea?

Violet_82 89 Posting Whiz in Training

Right, I've made some changes to the code.
The form action tag is empty: I don't have any PHP file to handle that because there will be some libraries that I'll use to validate the actual string sent to the server and, like I said, since this is an application I can't even post to the page itself, as I wouldn't have a clue how to do that, so the action is an empty string.
+"<form action=\"\" id=\"fileForm\">"
I'm now preventing the submission of the form and I've added the ajax functionality, here is the code:

+"/*ON CLICK SUBMISSION BUTTON*/"
    +"var $submitBtn = $HTMLpopup.find('.submitBtn');"
    +"$submitBtn.click(function(e){"
        +"e.preventDefault();/*prevent submission*/"
        +"if(isFileUploadEmpty()){/*IF FIELD EMPTY*/"
            +"/*alert('submit clicked');*/"
            +"removeError();"
            +"showError('empty');"
            +"/*return false;*/"
        + "}"
        +"else{/*IF NOT EMPTY*/"    
            +"/*AJAX OPS*/"
            +"if (window.XMLHttpRequest){/*XMLHttpRequest SUPPORT?*/"
                +"console.log('XMLHttpRequest supported!');"
                +"var postData = 'text';"
                +"/*var action = $HTMLpopup.find('form#fileForm').attr('action');*/"
                +"$.ajax({"
                    +"type:'post',"
                    +"url:'url',"
                    +"dara:'postData',"
                    +"contentType: 'application/x-www-form-urlencoded',"
                    +"success: function(responseData, textStatus, jqXHR){"
                        +"alert('data saved');"
                    + "},"
                    +"error: function(jqXHR, textStatus, errorThrown){"
                        + "console.log(errorThrown);"
                    + "}"   
                + "});"
            + "}"
        +"}"
    + "});"

So, here, providing you select a file (if not you get a clientside error), when you click submit (again note I'm preventing the submission of the form with e.preventDefault()) I reckon I'm sending something to the server because then I get the alert., but what is it that I'm sending? Have I managed to send the string contained in the textarea? How do I find out?
thanks

Violet_82 89 Posting Whiz in Training

Hi guys, I have a form which contains a file upload input field. When I select a file, mainly text files, the actual content of the file is displayed in a textarea field. Now, what I need to do, is to send that information - the data contained in the file - as a string to the server using ajax. one of the reasons for doing it that way, rather than sending the actual file, is that users must be able to edit the file information (even copying and pasting into the text displayed in the textarea). Now, I'm not really good with ajax I'm afraid, as I only used it a few times, so I'm trying to get this done but I'm having some difficulty.
Here is the current javascript code as i described above, without the ajax part (the javascript is part of a spring application that's why it's all inside quotes):
This is the popup with the relevant info (input field and textarea as described above.)

JavaScript.getCurrent().execute(""
    +"var $HTMLpopup = $('<div class=\"popupContainer\">"
        +"<span class=\"cancelBtn big\"></span>"
        +"<div class=\"wrapper\">"
            +"<form>"
                +"<div class=\"mask\">"
                    +"<input type=\"file\" title=\" \"name=\"uploadFile\" class=\"uploadFile\" accept=\".mol,.sdf\">/*filters files to upload*/"
                    +"<span class=\"pseudoBtn\">Browse</span>"
                    +"<input type=\"text\" name=\"displayFile\" class=\"displayFile\" placeholder=\"no file loaded\">"
                    +"<span class=\"cancelBtn small\"></span>"
                +"</div>"
                +"<textarea class=\"fileResult\"></textarea>"
                +"<button type=\"submit\" class=\"submitBtn\">Upload</button>"
                +"<div class=\"clear\"></div>"
            +"</form>"
        +"</div>"
    +"</div>');"
    +"$('.popupTriggerBtn').click(function(){"
        +"/*console.log('button clicked!');*/"
        +"var $body = $('body');"
        +"$HTMLpopup.appendTo($body);"
    +"});"

The popup then gets added to the page and here is the code that, if there is no file attached, prevents the submission …

Violet_82 89 Posting Whiz in Training

well, well, lo and behold...It seems like I cracked it in the end, but alas I have no idea why. So, this is what I've done, something very simple in fact. As you can see I used $('this'), as I would normally do:
+"var fileName = $('this').val();"
except that it doesn't need the darn quotes around it,
+"var fileName = $(this).val();"
too many quotes in that script, I got confused.

Violet_82 89 Posting Whiz in Training

HI guys,
I run into a problem. I have a input of type file and I'd like to grab the file name of the uploaded file and assign it to a variable, but I don't seem to be able to do that.
I'm hiding hte input with opacity 0 and hiding it behind a span which is styled to look like a button, common techinque as we all know, that shouldn't have any inpact on what I'm doing whatsoever. Anyway, here is the script (it's part of a Spring application by the way), here is the fll code:

 JavaScript.getCurrent().execute(""
            +"var $HTMLpopup = $('<div class=\"popupContainer\">"
                +"<div class=\"wrapper\">"
                    +"<div class=\"mask\">"
                        +"<input type=\"file\" title=\" \"name=\"uploadFile\" class=\"uploadFile\">"
                        +"<span class=\"pseudoBtn\">Browse</span>"
                        +"<input type=\"text\" name=\"displayFile\" class=\"displayFile\" placeholder=\"no file loaded\">"
                    +"</div>"                                           
                +"</div>"
            +"</div>');"
            +"$('.popupTriggerBtn').click(function(){"
                +"/*alert('button clicked!');*/"                                                 
                +"var $body = $('body');"
                +"$HTMLpopup.appendTo($body);"
            +"});"
            +"var $browse = $HTMLpopup.find('.pseudoBtn');/*find pseudo button*/"                                       
            +"$browse.click(function(){"
                +"console.log($browse.attr('class') + 'clicked');"
                +"$('input.uploadFile').trigger('click');"
            +"});"
            +"var $uploadFile = $HTMLpopup.find('.uploadFile');/*find real upload button*/"
            +"$uploadFile.change(function(e){"
                +"console.log('button pressed');"
                +"var fileName = $('this').attr('src', e.target.result);"
                +"console.log(fileName);"          
            +"});"
        +"");

Now, this generates a popup and there you have the file upload button, the pseudo button hiding it and an input field which I will use to display the file name:

+"<input type=\"file\" title=\" \"name=\"uploadFile\" class=\"uploadFile\">"
 +"<span class=\"pseudoBtn\">Browse</span>"
 +"<input type=\"text\" name=\"displayFile\" class=\"displayFile\" placeholder=\"no file loaded\">"   

So I click the pseudo button, the file system window opens, I select the file and press OK and that's when I want to get that file name.
I tried in a few different ways, …

Violet_82 89 Posting Whiz in Training

Cool, thanks guys, that's really helpful. I have plenty to get on with now!
Cheers

Violet_82 89 Posting Whiz in Training

Right, thanks. OK so I had a look at all of them, let's go in order.
@hericles, I looked at your suggestion, especially the first site which contains an awful lot of useful books, but it seems to me they're quite specific, so I reckon I could make use of it later on. In any case I'll sign up for the second one, hoping I could get some free book :-).
@pritaeas, I had a good look at the content of the books you suggested, and the fact that they're language independent is quite good because those are principles that apply across the board. Apparently in the first one most of the examples are in java and C++ (I've done a bit of C++ in the past so I don't thik it will be too much of a problem). Now, what order do you think I should start with? The first book seems the most "complete" on, so do you reckon I should start with that?
thanks

Violet_82 89 Posting Whiz in Training

Thanks guys, sorry maybe I didn't make it clear, but my language of choice is Java, so of course I'd like my studies to focus on that if possible, not sure if this affect the above lists, but will definitely have a look at what you posted, thanks

Violet_82 89 Posting Whiz in Training

Hi guys,
I wonder if you can help me at all. As some of you will know I do a bit of java development here and there but unfortunately I don't really have any programming background, like, I haven't studied computer science - I just learned (well, that's an overstatement) let's say that I'm still learning java and I'll learn still for a long while but my knowledge of software development is obviously very basic. What I'm trying to get to here is, I'd like to take the software development career further and, in addition to learn java, I'd like to get a good graps of the theory behind it, say, algorithms etc etc, let's say the foundations of software development that I don't have. Now, before suggesting to go back to uni and perhaps do a computer science course which I would absolutely love, but that realistically will not happen for lack of time, I wonder if you guys could recommend any book/s that will help me. I'm very well aware of the fact that one or more books can't replace a degree, but still I'm sure they will help a great deal.
A while ago I remember reading bits of quite an interesting book called computer systems, but that was geared towards assembly so probably not for me.
Anyway, as usual, any help is appreciated

thanks

Violet_82 89 Posting Whiz in Training

cool, thanks. I've implemented it on my site and it works pretty well, and no jerky effect in IE (I<E10 has no effect but I's happy with that)

Violet_82 89 Posting Whiz in Training

I must admit I didn't know you could do that bouncy animations with CSS3, so I didn't even explore that avenue.
The Jquery UI bundle is pretty small, about 600kb as I downloaded only what I needed for that (I don't really need it for anything else). Having said that, if something can be done with CSS, that's even better, so I'll have a good look at this CSS3 animation (I've seen your demo, and that's exactly what I need).
So basically, at 0%, 20%, 50%, 80%, 100% (of the animation) the arrow doesn't move, but at 40% you move it 30px downward and at 60% 15px downward. Is that the way it works?

Violet_82 89 Posting Whiz in Training

I mean the problem doesn't seem to be with the HTML or CSS but with the actual bounce function, because everytime that's called the page shots back up. In fact if I change the js from this

$(document).ready(function(){
    //animateArrow();
    bounce();
    var $banner = $(".contentWrapper");
    ...
    });//end of doc ready
function bounce(){
    $(".arrow").effect( "bounce", 3500, bounce);
}   

to this

$(document).ready(function(){
    //animateArrow();
    bounce();
    var $banner = $(".contentWrapper");
    ...
    });//end of doc ready
function bounce(){
    $(".arrow").effect( "bounce", 3500);
}   

so that the counce is called only once, then no problem occurs

Violet_82 89 Posting Whiz in Training

Hi AleMonteiro,
I tried your suggestion but it won't work. Here is the HTML and CSS as requested (the js is in the previous post):

<div class="mainWrapper">
    <div class="bannerWrapper">
        <div class="contentWrapper">
            <div class="photoBanner">
                <img src="image/banner.jpg" alt="">  

            </div>               
            <span class="arrow"></span>
        </div><!-- end of wrapper -->

    </div>




.bannerWrapper{
    overflow:hidden;
}
.contentWrapper{
    /* width:1920px; */
    margin:0 auto;

}
.photoBanner {
    position: relative;
}
.photoBanner img{
    display: block;
    left: 50%;
    margin-left: -960px;
    position: absolute;
    top: 0;
    width: 1920px;
    height:1280px;  
}
span.arrow{
    display:block;
    width:124px;
    height:62px;
    background:url("images/arrow.png") no-repeat 0 0;
    left:50%;
    margin-left:-62px;
    position: absolute;
    bottom:15px;
    cursor:pointer; 
}

Bear in mind that jquery UI adds an extra div around the arrow:

<div class="ui-effects-wrapper" style="font-size: 100%; background: transparent none repeat scroll 0% 0%; border: medium none; margin: 0px; padding: 0px; width: 62px; height: 62px; float: none; position: absolute; z-index: auto; top: 801px; left: 951.5px; bottom: 15px; right: 889.5px;">

@rproffitt: I have to admit I'm not terribly familiar with that website, so it tells you if something works on any browser. So what is that "arrow" search criterium you used? How does it know that it's done by using jquery ui?
thanks