~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

validate is your Javascript function which performs the validation. As I previously stated, make your validation function return a boolean flag depending on the result of the validation.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Link? I didn't post any link in my previous post; maybe you are talking about IntelliTXT ads. As far as the source code is concerned, look into the installation directory of Java, you will find a src.zip, containing the entire source code.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

AFAICT, when in search for a blogging service, people normally look for the ones which provide complete freedom in terms of blog posts. They might have blog posts related to their day to day happenings or on technical topics. Since Daniweb blogs, AFAIK, don't allow non-technical content and people normally are too lazy to maintain two blogs, hence the outcome.

Also, it depends a lot on the ecosystem of the community. Daniweb is mostly frequented by school / university kids looking for homework help or people trying to solve hardware configuration issues i.e. the ratio contributors to consumers is pretty low.

Some other reasons might be a lot of things going in life to bother with blogging or just plain old laziness [like me].

My personal choice for blog posts is something related to programming or some latest development in the software scenario rather than lowdown on the next version of MS Vista; YMMV.

Dave Sinkula commented: /me nods. +17
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> How do I call the three different values entered and output them to the screen in the file
> test.jsp?

Don't process form data in JSP's which are meant for view purposes; use a servlet instead which would then delegate the responsibility to a JSP.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You need to control the form submission based on the result of the validation.

<form name="frm" id="frm" action="action.jsp" onsubmit="return validate(this);">
  <!-- form elements go here -->
</form>

where validate returns a true or false depending on the outcome of the validation.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> I doubt its that complicated, probably a few lines of code.

I doubt it is simple given that the method is Unicode aware hence would involve a lot of Unicode jargon like code points, planes etc. If you are interested, you can take a peek at the source code though without a basic understanding of the Unicode specification, it would be rather pointless.

P.S.: Yay, 7K! :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

What I was saying is that I don't understand most of that terminology, so the point alone has no impact. I hope I wasn't rude - I wasn't trying to be.

It would be difficult to explain the real use of reflection without throwing in a lot of terminology. Maybe reading this article will help you understand how reflection changes the way we think of object construction/instantiation and how the concept of reflection benefits the real world software development.

Ezzaral commented: Good reference. +15
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The thing they are doing is nothing special. To summarize it:
- User makes a selection from the primary SELECT box, MAKE in your case.
- An asynchronous request is made using the XHR [XML HTTP Request] Object i.e. an AJAX call.
- The request URI encapsulates all the information required for fetching the data for the secondary SELECT box, MODEL in your case.
- The request looks something along the lines of /models/?make=selectedMake
- Now, the representation returned by the server depends on how your application architecture is structured. Like I explained in my previous post, it can be a delimiter separated value, a JSON response or an XML response. As far as that site is concerned, I guess they are dealing with a delimiter separated response, something along the lines of: make1=qty1;make2=qty2;make3=qty3 .
- If using JSON, the above response can be structured as: {make1: qty1, make2: qty2, make3: qty3} .
- The advantage when dealing with JSON response is that it can be directly consumed by your client application by simply evaling the text returned [though eval is dangerous for real applications; use a Javascript JSON library]

var obj = eval(response);
for(var key in obj) {
  alert(key + " -> " + obj[key]); // make1 -> qty1 etc.
}

- The logic for interpreting the request and constructing a response obviously would be implemented in the server side language of your choice. A working knowledge of the same is …

OmniX commented: Thanks for the detailed breakdown! +1
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I agree with the OP there; Ruby is much more than just another web development language. It falls in the same league as Python, Perl and the other scripting languages out there. Moving it to the Software Development Category would be a good decision.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Just wondering why remember me is checked by default. I usually don't want it ticked and generally I think sites have it un-ticked. It's only 1 click of the mouse and so its definitely no bid deal, just something I notice :)

If using Firefox, just throw in a trivial GreaseMonkey script which does it for you.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Oh ok so thats the behavious by default but what if i wanted was that in 5 <options> long
> and scrollable this possible?

AFAIK, no; but then again, this question might be more suited in the HTML forum since this has got nothing to do with Javascript.

BTW, any reason you want such behavior? The default functionality seems to be good enough.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

here is the download link:

http://www.banditssoftball.org/chat.v3.zip

Please remember that this chat will not support a lot of users. Its writing to a file and once that many people are trying to read and write from it, it will start to delete messages unexpectedly. I created it to use as a customer service type deal, only2-5 users. If you are wanting more, I would have to integrate a mysql solution into it. I really suggest using a opensource chat app.

If you are trying to avoid the complexity of creating or hosting a database server, consider the possibility of using an embedded, zero configuration and transactional database. There are many databases out there which work both in server and embedded mode. Look into SQLite; it is specifically meant to replace those ad hoc data files you are managing with your chat application right now. You will surely see a noticeable difference in speed with a minimalistic effort.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It's a default behavior of drop down or SELECT elements which has considerable number of elements; just take a peek at the markup of the page by Viewing the source and you will be convinced.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The simplest way would be to use the Collections#shuffle(List<?> list) method which delivers decent performance and output.

If you have an assignment to create such a shuffling algorithm, then look at the source code of the Collections class for hints.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

This means that instead of either catching IOException and doing nothing or making the method throw IOException , introduce a custom exception hierarchy for your application. This hierarchy might contain something from two to twenty custom exceptions depending on the breadth of your application.

For e.g. in the above case, you might just create a custom Exception class which extends RuntimeException and use it to wrap the actual IOException which occurs in your code.

public void someMethod(String fileName) {
  try {
  } catch(IOException ioe) {
    throw new SystemException("File not found: " + fileName, ioe);
  }
}

Since the exception is unchecked type, it gives you the flexibility to completely ignore the possibility of an exception occurring when reading a given file or handle it in case you feel like it and process it accordingly. Just make sure you specify the cause when creating a new Exception instance so that it can be used for logging or other debugging purposes.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Happy B'Day Dani girl, may you live long and prosper! :)

I hope you had a great time with your loved ones. ;-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Google for createElement and insertBefore.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Use the Error Console feature of Firefox to track down Javascript errors. Use the Firebug extension of Firefox for debugging Javascript application. Also don't search for parent elements of node, just use the parentNode property of the Node.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Now I wish to cut out the middle man (xml) and refer straight to the database.

You can't, that's the entire point in choosing a data interchange format for the interface exposed. You can cut down the fat by choosing alternate formats like the very primitive comma separated values or a lightweight format most suited for Javascript clients called JSON.

If what I assumed here isn't the case with your application, post a sample request / response along with a bit of background on what you *actually* are trying to achieve.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> In a few years that won't be a joke.

And we would have a band of outlaws who would be completely against this. Good setting for an anime, can't wait for this one... ;-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

s.o.s, no offense, but sifting through a ton of material to *maybe* answer my question doesn't sound too appealing. If reflection is indeed useful, there have to be some practical, simple explanations of why this is the case.

It seems as though you missed my entire post. The first two paragraphs of my previous post mention the most widely used implementations of the reflection API. Another use of the reflection API is to implement the Webservice client for SOAP type web services wherein the XML response from the server is converted to an object tree using the schema definitions.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

As far as I know, exceptions that are not subclasses of runtime exception or error should be caught (handled).

When a file exception occurs, it should be caught because its a subclass of exception class, but how can it be recovered? If file is not found,it sounds silly to recover it when the program has to read file to run,I think the program should be terminated.

} catch (IOException e) {
            e.printStackTrace();
            System.exit(0);
} finally {
        if(in != null)
           in.close();
}

I preferred to exit in catch block,what should be done in such a situation?

Making IOException and SQLException as checked exceptions is regarded as one of the blunders of the Java standard library design. Many might argue that having checked exceptions in itself is a big PITA but that's a story for some other day.

Anyways, just make sure you don't propagate error codes anywhere in your application design; it's one of the worst design decisions to make esp when using a language like Java which has exceptions built in.

You have two options here:
- Either let the method throw the same IOException which occurs and let the invoking method handle the case. This seems to be a bad choice since the calling method now has to handle an exception it shouldn't have been bothered with in the first place.
- Create your own RuntimeException class which fits ecosystem of your application and wraps around the IOException thrown. This exception should be thrown when an …

jasimp commented: well said +9
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Think of all the frameworks which let you specify your custom class in their configuration file and load those classes at runtime. The servlet specification for instance has a deployment descriptor which allows the developer to configure servlets, filters for his application. All the developer has to do is to specify the class name and the required processing is done at runtime by the container.

Also look into Spring or Guice which are IOC/Dependency Injection frameworks.

That being said, there *are* a lot of uses of reflection; it's just that they aren't that obvious.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> I get an error message every so often with this code.
> 'document.getElementById(...)' is null or not an object.

Because there exists no element with the given ID. It looks as though the ID for your form elements are dynamically generated and hence the intermittent problem. A better way for setting the default drop down option would be to grab hold of all the SELECT items and set their selectedIndex property to zero (except for the SELECT element under consideration)

var sels = document.getElementsByTagName("SELECT");
for(var i = 0, maxI = sels.length; i < maxI; ++i) {
  var sel = sels[i];
  if(sel == slctFild)
    continue;  // exclude the current select element
  sel.selectedIndex = 0;
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

As per the specification, in a HTML document, the ID attribute must be unique. Assign a different ID and NAME to each INPUT element. Don't use GET, use POST for sending your form data.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Apache Tomcat is the most mature and stable servlet container out there used in a lot of production deployments. There are a lot of Tomcat resources out there and all Servlet / JSP books out there use Tomcat to showcase their examples.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> If anyone can do this I will spam +rep on your for the remainder of your DaniWeb life

Pity, you haven't got any left.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> It just lets me know about certain properties of an Object, such as its classname

It does much more than that.

> The concept of a Map is somewhat familiar, but it doesn't help avoid the work, does it?

It provides a solution to your problem. IMO, what you are looking for is not a solution but a syntactic sugary way of doing things. Like previously mentioned, either use an array, a map or a JVM targeted scripting language like maybe Groovy, Scala, Rhino etc.

> I guess this isn't possible in Java though.

Yes, in the same way it isn't possible to create classes in C.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> For example, if I have an Animal named germanShephard, is there some way I could say
> String gerSh = "germanShephard"; and then treat gerSh as if it was the equivalent of
> saying germanShephard in my program?

You can't because gerSh is now a String. The closest you can come to this kind of name to Object mapping is by using a Map or by using the reflection API, which again doesn't work for `private' members.

The behavior you speak of can be seen in all ECMAScript implementations. Something of the sort:

var obj = {dog: {name: "poo boy", type: "poodle"},
                cat: {name: "neko san", type: "siamese"}};
var key = "dog";
alert(obj.dog.type); // poodle
alert(obj[key].type); // poodle
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Attach a war file of your project so someone can try it out.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Don't override service ; just override the method which you want to support and accordingly override the doGet() or doPost() method.

The `action' attribute of the FORM tag is mandatory. You don't need to use Javascript, just use the action attribute of FORM tag with a normal submit button.

Also there is no reason for a service method to run twice unless there actually were requests made; print out the request.getRequestURL() inside your request handling method to see which URL was requested by the client. In case your page references other resources like images or Javascript files present on the server and your web.xml maps each request to your servlet, the multiple invocations might just be explained.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

return in looping constructs is considered conditional and hence the given compiler error. The compiler acts pretty much as a pessimist here and assumes the loop will never be entered unless the condition includes only literals.

// Won't work
public int doIt() {
  final int min = 0;
  final int max = 10;
  int i = min;
  while(i < max) {
    // something
    return something;
  }
}

// But this will
public int doIt() {
  while(0 < 10) {
    // something
    return something;
  }
}

To get around this, keep a boolean flag which would be updated when a condition is true inside the loop and break out of the loop. Check the boolean flag outside the loop and process accordingly.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Is it possible to establish a jdbc connection within the jar.
> The jar I will be using has the database file.

Just reference the file inside your jar [in your case required for a standalone database like SQLite] like any other resource. Read this.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> and the meaning of this is that in this case we must call the base constructor with super()
> but my question is how in th first class CounterDemo extends Counteexample we do not
> need super();

In case you don't provide a constructor for your class, the compiler automatically inserts one with the same access modifier as that of the class for you. It is called a *default* constructor. A default constructor is a no-arg constructor but an explicitly provided no-arg constructor isn't a default one. A few examples:

// original code
public class A {}

// generated code
public class A {

  // default constructor
  public A() {
    super();
  }

}
// original code
class B {}

// generated code
class B {
  
  // default constructor
  public B() {
    super();
  }

}
// Original code
public class C {
  
  // An explicitly created no-arg constructor
  public C() {
  }

  public C(int i) {  
  }

}

// Generated code
public class C {
  
  public C() {
    super();
  }

  public C(int i) {
    super();
  }

}

Of course, things start getting hairy when Serialization is involved, but that's a story for some other day...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Let's hope this poll retains the voters' privacy!

Eh, which poll was compromised? I definitely wouldn't want people to know I voted for 'other'... ;-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Hello, I'd like to create a function
_______________________^^^^^

Method would be the correct terminology here.

> that accepts two objects and compares properties between them.

That largely depends on the type of those properties. If they are primitives, the comparison operator will do the job. If they are reference types, comparing their references doesn't serve much of a purpose. Then again it depends on whether you are in need of a deep or a shallow comparison.

If you are in need to comparing two objects of the same run-time type, consider overriding the equals() method of the Object class for your custom class. If you are in need of selective comparison of properties, look into the Comparator interface.

Also, explaining the real scenario rather than the end objective would fetch more helpful answers.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> How do you know what format the OP saved his file in?

Because he is using DataInputStream. So either the file is in modified UTF-8 or the OP is doing it wrong.

> What? My point was that if you read in data from a file and get unexpected results
> (such as Asian characters, in this case) then you are trying to read in data with the
> wrong encoding.

Generally speaking, yes, but given the current scenario, it has to be modified UTF-8.

> What's your point?

My point being that readXXX method of DataInputStream will always returns XXX, so there should be no surprises that readChar returns a char and not an int like the read() method of other Streams.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> I'm trying to read in a text file character by character. However, when I try to read it in it
> using the readChar method in DataInputStream it gives me a IOException. Heres what I
> have so far

You are using a wrong approach IMO. Even though you have found a solution which makes your problem *seem* to go away, it fails to address the actual issue: Why use DataInputStream ?

From the API docs:

The DataInput interface provides for reading bytes from a binary stream and reconstructing from them data in any of the Java primitive types.

Because of this, you end up encountering an EOFException even though your file contains valid character data. The approach of reading in bytes using DataInputStream would fail miserably for multi-lingual character data since you would have to convert from bytes to actual characters. Use a Reader for reading character data since you get to specify an encoding which you want to use [which luckily also takes care of reading in bytes and converting them to character data of the given encoding].

Also reading in data character by character is pretty inefficient even though your program logic demands character by character processing. Read in a sizable chunk of characters and process them in memory to avoid a lot of disk reads.

> if you didn't specifically do this, it's probably UTF-8

No it isn't; it's modified UTF-8.

> you're clearly trying to read …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Is it acceptable coding practice to place my tax calculation coding within my first function

It would be better if you have two functions: one which is invoked onclick of a button and which reads the values from various form fields and the second which is purely involved with the calculation of tax. This way you separate out the data retrieval/validation part from the actual logic, in your case, tax calculation.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You have a few options:
- Creating hidden fields which hold your temporary results.
- Saving the state in a global variable which can be used across function invocations.
- Creating your own custom object which maintains the state.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Mizu

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The script in case of a SCRIPT element may be defined inside the contents of the SCRIPT element or in an external file. The only difference here is that an additional request is made in the case of an external script file. Hence you can treat your script as though it was embedded in the document even when it comes from an external source.

You have a few options; either pass in the `id' / `name' of the form elements whose values you need to access to the Javascript function or just access them directly from your function assuming that the form elements with the given `name' / `id' are always present.

<input type="text" name="txtOne" id="txtOne">
<input type="text" name="txtTwo" id="txtTwo">
<input type="button" value="Calculate" onclick="getIncomeTax('txtOne', 'txtTwo');">

<!-- OR -->

<input type="text" name="txtOne" id="txtOne">
<input type="text" name="txtTwo" id="txtTwo">
<input type="button" value="Calculate" onclick="getIncomeTax(this.form);">

function getIncomeTax(frm) {
  var e1 = frm.elements['txtOne'];
  var e2 = frm.elements['txtTwo'];
  var iTax = doSomething(e1.value, e2.value);
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Why doesn't the hashCode() method of URL suffice your needs?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> You cant. Its not opensource.

Yes it is.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> This should be an easy project

You have seriously got to be joking...

> Also executing packaged-classes might be a bit tricky.

Take a look at how Ant handles such things.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> The above post is all in one class and not in different classes like I had wanted.

Of course, otherwise I would have ended up giving you the entire solution.

public void in(InputStream in)
	{
		class2 class3Obj = new class3();
	
		x=((class3)class3Obj).get_x();
		y=((class3)class3Obj).get_y();

		for(int i=0;i<arr.length;i++)
		{
			String[] tmp = arr[i];
			for (int j=0;j<tmp.length;j++)		
			{	
					tmp[j]=" X ";
					arr[x][y]=" O ";
			}
		}
	}

Again a lot of problems with your code.
- Don't create a `public' Scanner instance; use the `in' passed in the `in' method of class1 to create a Scanner , that's the entire point of passing in an InputStream .
- If you need to set something at the position x,y of your array, do it once, not in a loop. It is because of this loop that the previous values are getting wiped off. Also check the values of `x' and `y' to avoid ArrayIndexOutOfBoundsException .

Any reason why `class3' extends `class2' and `class3' has a reference to `class1'? Your design has a lot of coupling and almost no cohesion. Like I mentioned previously, reconsider your design choices, discuss with your peers and professors about this assignment and read some good tutorials/books.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

@stephen84s

To exclude a piece of text as being interpreted as BBCode, use the noparse tag. With the use of noparse, you can write something along the lines of [noparse][code=java]your code here[/code][/noparse] and be sure it won't be interpreted by the BBCode parser of vBulletin.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Two reasons come to mind:
- A rogue implementation which manifests itself as the number of documents to be transferred increases. Profile the application thoroughly looking for memory leaks and unintentional object retention.
- The default heap size doesn't suit well for your current processing needs. Tune your JVM by setting an appropriate heap size and garbage collection strategy to suit your needs.

Read this.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Enough of this name calling already, please. It has been observed that many of the Geek's Lounge threads on debatable topics like Politics are taking a nasty turn which comes in the form of name calling, giving out negative reputation etc.

Let's keep this discussion a healthy one which everyone can enjoy reading; any more fights and this thread is a goner.

Ezzaral commented: Good call. +13
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Either pass the array reference declared in main() to your methods or just make sure that the display() method prints out the instance variable 'arr' instead of passing it an array declared in the main() method.

// Untested: Error handling omitted for brevity
class ArrayTest {

  private String[][] twoDimArr;

  public ArrayTest(int x, int y) {
    // handle invalid input
    twoDimArr = new String[x][y];
  }

  public void populateArray(InputStream in) {
    // loop over the array, accept input from the source (here `in')
    // and populate it.
  }

  public void displayArray() {
    // loop over the array and display each element.  
  }

  public static void main(final String[] args) {
    ArrayTest t = new ArrayTest(3, 3);
    t.populateArray(System.in);
    t.display();
  }

}