Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: problem with accepting int!

  1. #1
    Member
    Join Date
    Mar 2011
    Posts
    84
    My Mood
    Daring
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default problem with accepting int!

    i'm creating web app and there i need users to register in order to use services.
    while registering an int field Phone Number is required, i want to have phone numbers as int only. also o'm using action bean to retrive data.
    my problem is that field is not returning any data if the length of integer is more then 8 digits???
    here is the bean
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package formbeans;
     
    import javax.servlet.http.HttpServletRequest;
     
    import model.ObjectNotFoundException;
    import model.user;
    import model.userDAO;
    import org.apache.struts.action.ActionErrors;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.action.ActionMessage;
     
    /**
     *
     * @author Arvind
     */
    public class register extends org.apache.struts.action.ActionForm {
     
        private String name, username, password, cpassword, address;
        private int number;
        userDAO userDB = new userDAO();
        user user = new user();
     
        /**
         * @return
         */
        public String getName() {
            return name;
        }
     
        /**
         * @param string
         */
        public void setName(String string) {
            name = string;
        }
     
        /**
         * @return
         */
        public int getNumber() {
            return number;
        }
     
        /**
         * @param i
         */
        public void setNumber(int i) {
            number = i;
        }
     
        /**
         *
         */
        public register() {
            super();
            // TODO Auto-generated constructor stub
        }
     
        /**
         * This is the action called from the Struts framework.
         * @param mapping The ActionMapping used to select this instance.
         * @param request The HTTP Request we are processing.
         * @return
         */
        public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
            ActionErrors errors = new ActionErrors();
            if (getUsername() == null || getUsername().length() < 1) {
                errors.add("name", new ActionMessage("error.user.required"));
            }
            if (getPassword() == null || getPassword().length() < 1) {
                errors.add("name", new ActionMessage("error.password.required"));
            }
            if (!getCpassword().equals(getPassword())) {
                errors.add("name", new ActionMessage("error.mis-match.required"));
            }
            if (getName() == null || getName().length() < 1) {
                errors.add("name", new ActionMessage("error.name.required"));
            }
            if (getAddress() == null || getAddress().length() < 1) {
                errors.add("name", new ActionMessage("error.address.required"));
            }
            phonelength();
     
     
            try {
     
                if(searchmember())
                    errors.add("already", new ActionMessage("error.alredy.required"));
     
     
            } catch (ObjectNotFoundException ex) {
                errors.add("unexpected", new ActionMessage("error.runtime"));
            }catch(NumberFormatException e){
                errors.add("unexpected", new ActionMessage("error.numbers"));
            }
            return errors;
        }
     
        private boolean searchmember() throws ObjectNotFoundException {
            int i = userDB.search(getUsername());
            System.out.println(i);
            if ((i>0)) {
     
                return true;
            }
            return false;
        }
        private void phonelength(){
     
     
                System.out.println("Phone is\t"+getNumber());
     
     
     
        }
     
        /**
         * @return the username
         */
        public String getUsername() {
            return username;
        }
     
        /**
         * @param username the username to set
         */
        public void setUsername(String username) {
            this.username = username;
        }
     
        /**
         * @return the password
         */
        public String getPassword() {
            return password;
        }
     
        /**
         * @param password the password to set
         */
        public void setPassword(String password) {
            this.password = password;
        }
     
        /**
         * @return the cpassword
         */
        public String getCpassword() {
            return cpassword;
        }
     
        /**
         * @param cpassword the cpassword to set
         */
        public void setCpassword(String cpassword) {
            this.cpassword = cpassword;
        }
     
        /**
         * @return the address
         */
        public String getAddress() {
            return address;
        }
     
        /**
         * @param address the address to set
         */
        public void setAddress(String address) {
            this.address = address;
        }
     
        /**
         * @return the phone
         */
     
    }
    please help!


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: problem with accepting int!

    Make a quick draft console program with the following main method, and study the results, hopefully that should tell you where you're going wrong.
    	public static void main(String[] args) {
    		// Highest possible int value
    		System.out.println(Integer.MAX_VALUE);
     
    		// Highest possible long value
    		System.out.println(Long.MAX_VALUE);
    	}
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. The Following User Says Thank You to newbie For This Useful Post:

    arvindbis (October 9th, 2011)

  4. #3
    Member
    Join Date
    Mar 2011
    Posts
    84
    My Mood
    Daring
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default Re: problem with accepting int!

    that was really helpful!! thank you