Results 1 to 9 of 9
  1. #1
    berlindutza is offline Member
    Join Date
    Aug 2009
    Posts
    25
    Rep Power
    0

    Default Java class StringFormat

    I'm kind of a newie, I'm using Eclipse and I'm going through some examples where they use the class StringFormat (more exactly the method isValidDate ncluded in this class). But I can't find this class. I searched on the net for it and found out it may be in the package java.lang or java.text but I couldn't find in these packages. Does someone know what I have to do to be able to use this class (download it, install it) ?
    Thanks a lot!

  2. #2
    DiamondDog is offline Member
    Join Date
    Aug 2009
    Posts
    18
    Rep Power
    0

    Default

    I'm a newbie too.

    I'm not aware of any StringFormat class, but there's a format method in the String class which allows you to create formatted strings.

    For example:

    Java Code:
    String myString = String.format("there are %d kinds of butterfly", 2145);

    Is that the sort of thing you're wanting to do?

  3. #3
    berlindutza is offline Member
    Join Date
    Aug 2009
    Posts
    25
    Rep Power
    0

    Default

    Not quite. I'd like to verify wether is a string represents a valid date by using the moethod isValidDate of the class StringFormat. But I can't use this method as I can't find the class.

  4. #4
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    This sorta works:

    Java Code:
    SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
    String date = "12/12/2121";
    
    try
    {
       Date d = df.parse(date);
       System.out.println(d);
    }
    catch(Exception e)
    {
       System.out.println("This is not a valid Date: " + date);
    }
    My Hobby Project: LegacyClone

  5. #5
    pellebye is offline Member
    Join Date
    Apr 2009
    Posts
    54
    Rep Power
    0

    Default

    The only StringFormat class I find is StringFormat which has no isValidDate.

    What example in eclipse are you talking about ... or could you qoute some text from there?
    -
    Life is not the worst thing we have ... in a few minutes my coffee is ready.

  6. #6
    berlindutza is offline Member
    Join Date
    Aug 2009
    Posts
    25
    Rep Power
    0

    Default

    This example provides methods for validating the data.
    The code is:

    package com.ora.jsp.beans.userinfo;

    import java.io.*;
    import java.text.SimpleDateFormat;
    import java.util.*;
    import com.ora.jsp.util.*;
    import com.ora.*;
    import com.ora.jsp.beans.userinfo.*;
    import com.ora.jsp.*;
    /**
    * This class contains information about a user. It's used to show
    * how a bean can be used to validate user input and format output
    * so it's suitable for HTML.

    @author Hans Bergsten, Gefion software <hans@gefionsoftware.com>
    * @version 1.0
    */
    public class UserInfoBean implements Serializable {
    // Validation constants
    private static String DATE_FORMAT_PATTERN = "yyyy-MM-dd";
    private static String[] SEX_LIST = {"male", "female"};
    private static int MIN_LUCKY_NUMBER = 0;
    private static int MAX_LUCKY_NUMBER = 100;

    // Properties
    private String birthDate;
    private String birthDateInput;
    private String emailAddr;
    private String emailAddrInput;
    private String[] interests;
    private String luckyNumber;
    private String luckyNumberInput;
    private String sex;
    private String sexInput;
    private String userName;
    private boolean isInitialized;

    /**
    * Returns the birthDate property value
    */
    public String getBirthDate() {
    return (birthDate == null ? "" : birthDate);
    }

    /**
    * Returns the birthDate property value,
    * with all HTML special characters converted
    * to HTML character entities
    */
    public String getBirthDateFormatted() {
    return StringFormat.toHTMLString(getBirthDate());
    }

    /**
    * Sets the birthDate property value, if it's
    * valid
    */
    public void setBirthDate(String birthDate) {
    isInitialized = true;
    birthDateInput = birthDate;
    if (StringFomat.isValidDate(birthDate, DATE_FORMAT_PATTERN)) {
    this.birthDate = birthDate;
    }

    ......
    The effect is that only validated values can be accessed though the getter methods

  7. #7
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Perhaps one of those com.* packages that are being imported contains a StringFomat class that has an isValidDate method. You would have to check the API docs for them.

  8. #8
    berlindutza is offline Member
    Join Date
    Aug 2009
    Posts
    25
    Rep Power
    0

    Default

    Probably the class is in the package written with red (com.ora.jsp.util.*;) I don't have this package (an error occures when compiling). Where could I find this package and how can I add it to my project?

  9. #9
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Sorry I don't know. Perhaps you can find it wherever you got the rest of the com.* packages. Perhaps you don't really need that util if you can write your own data checker.

Similar Threads

  1. Replies: 1
    Last Post: 05-31-2009, 10:57 PM
  2. Replies: 1
    Last Post: 05-31-2009, 02:17 PM
  3. Replies: 16
    Last Post: 05-28-2009, 03:41 PM
  4. Replies: 14
    Last Post: 05-28-2009, 05:44 AM
  5. class.java to class.exe
    By f_the_cook in forum New To Java
    Replies: 11
    Last Post: 07-16-2008, 02:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •