Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by spoonraker

  1. You will learn to love the ability to write plain HTML that is conditional on PHP. These examples are all very simple and when you look at them the echo statments don't seem to make the code any different, but imagine on a larger scale.What if you have an entire huge section of page that is only set to display if a PHP variable is true? would you want echo, echo, echo, echo, echo, echo, echo, echo... for a bazillion lines? Or would you rather just have<? if(something){ ?><table><tr><td><font><whatever><blah>....etc<? } ?>
  2. problem solved! thanks for all the input
  3. Ok well it turns out my script works just fine, I'm just getting strange errors with select boxes not having properties and stuff.I'm using this DynamicOptionList javascript function to handle my dynamic lists. http://www.mattkruse.com/javascript/dynamicoptionlist/When I reference a select box that I manually create and add options to, both the getIndexOfValue() and changeSelect() functions work fine, but when I pass it a select box handled by that script, it always tells me that "selectBox has no properties" even though I can see all the options on my screen.
  4. YepSo nobody knows why it's not working and/or has another way to do it?
  5. I have narrowed my problem down to the getIndexOfValue() method.If I just call changeSelection(whatever, 2), it works just fine.Thanks for any help.*update* I noticed in this line for (i = 1; i < selectBox.options.length; i++) { that I forgot the "var" in the for loop, I changed it to for (var i = 1; i < selectBox.options.length; i++) { It still doesn't work.Oh and I get zero javascript errors.
  6. I'll make this simple...this web page I'm working on is incredibly huge and complicated (I'm well over 2,000 lines of Java) and trying to post the "big picture" would just confuse the ###### out of everybody...so here is exactly what I need.I have a select box like so...<select id="filter"><option value="blah">blah</option><option value="bleh">bleh</option><option value="bluh">bluh</option></select>The ONLY data I have to work with is the "value" of the option selected, "blah", "bleh", or "bluh".So how would I use javascript to select the correct option?The method I'm currently trying uses a reverse lookup. It loops through the options one at a time, and when the value matches the value I pass in, it returns the index of that option. Then I use document.getElementById("filter").options.selectedIndex = X to set the selectbox to the correct option.The code for that is posted in the OP, but it's not working.
  7. Ok, this is a little complicated so bear with me and try and understand my problem.I have a website with 3 dropdown menus. The first one is a filter, things like name, rank, etc. The second one is an operator for that filter, either =, >, or <. The third one is a list of options for a particular filter, for example if you select rank as the filter you get options like Affiliate, executive, etc.Now... in case you didn't figure this out on your own, the first dropdown is static, and the other two are dynamic based on what you chose in the first. I have absolutely no trouble generating these menus, that has been in place for a while.What my problem is, is that when the form is submitted, I need the refreshed page to pre-populate those forums with the saved data.The data for the three drop downs (Dropdown IDs in order : "filterby", filterbysize", "filterbyvalue") is stored in Java/JSP.So...I created a javascript function which was supposed to run on page load using the body onLoad tag.Well the first problem is that my javascript function doesn't work. What I planned on doing was doing a reverse looking up the select option indexes by value, and then passing that index to a function which sets that select to that option. Here is my code, now I know that it's a little bit different than I described, this is because there is another set of filters, the first one has a text field as the last option, and the second one is the one I described with three select menus. function getIndexOfValue(selectBox, lookupValue){ var index = 1; for (i = 1; i < selectBox.options.length; i++) { if (selectBox.options[i].value == lookupValue) { index = i; } } return index; } function changeSelection_(selectBox, index){ selectBox.options.selectedIndex = index; } function populateFilters(){ var filterbysize = document.getElementById("filterbysize"); var filterbysizevalue = "<%=genealogy.getFilterbysize()%>"; var filterbysizetwo = document.getElementById("filterbysizetwo"); var filterbysizetwovalue = "<%=genealogy.getFilterbysizetwo()%>"; var filterbyvaluetwo = document.getElementById("filterbyvaluetwo"); var filterbyvaluetwovalue = "<%=genealogy.getFilterbyvaluetwo()%>"; changeSelection(filterbysize, getIndexOfValue(filterbysize, filterbysizevalue)); changeSelection(filterbysizetwo, getIndexOfValue(filterbysizetwo, filterbysizetwovalue)); changeSelection(filterbyvaluetwo, getIndexOfValue(filterbyvaluetwo, filterbyvaluetwovalue)); } The function be to run at page load is populateFilters(). Using alerts I have determined that the code stops executing once it hits the last three changeSelection(... commands. If I comment those out and place an alert after all the variable declarations it works fine. Also, the jsp <%= %> statements aren't the problem, they work fine, i can print out the values using a JS alert.So that's my first problem, my reverse lookup and option changing scripts dont work. Any ideas?No my second problem is pretty simple. The body onLoad tag doesn't work. If I do body onLoad="populateFilters()", nothing happens. Even if I do body onLoad="alert('hello')" I never see the alert. But when I take my populateFilters() function and execute it in an onClick event, it executes fine (except the errors talked about above obviously)Any help is appreciated
  8. First of all, this is a linux question and not in any way related to Java programming.Now, to answer your question. When you compile something with the -classpath parameter, it's not permanent. As you said, every time you type the command in you will have to type the classpath again. What we use here is "ant" which is a build tool that automates the compiling of the entire directory. Why don't you just use a batch file or something like ant? Even with our huge codebase it only takes at most 20 seconds for a complete compile.
  9. Answer given on another forum, worked great, just thought others might want this info in case they have a similar problem.Steps :1) Create a TreeMap and store values in it.2) Create a List with values from TreeMap.entrySet().3) Implement Comparator interface and apply your camparison constriants.4) Sort the list.So just do as follows:Create 1 class with name : sortValues.javaimport java.util.ArrayList;import java.util.Collections;import java.util.Iterator;import java.util.List;import java.util.TreeMap;public class sortValues{public static void main(String args[]){TreeMap hm= new TreeMap();hm.put(new Integer(100),new Integer(1000));hm.put(new Integer(200),new Integer(900));hm.put(new Integer(300),new Integer(800));hm.put(new Integer(400),new Integer(700));hm.put(new Integer(500),new Integer(600));hm.put(new Integer(600),new Integer(500));hm.put(new Integer(700),new Integer(400));hm.put(new Integer(800),new Integer(300));hm.put(new Integer(900),new Integer(200));hm.put(new Integer(1000),new Integer(100));hm.put(new Integer(1100),new Integer(100));hm.put(new Integer(10),new Integer(10));List entrylist = new ArrayList(hm.entrySet());Collections.sort(entrylist,new ValueComparator());Iterator i = entrylist.iterator();while(i.hasNext()){System.out.println(i.next());}}}Another class : ValueComparator.javaimport java.util.Comparator;import java.util.Iterator;import java.util.Map;class ValueComparator implements Comparator {public int compare(Object o1, Object o2) {Map.Entry e1 = (Map.Entry) o1;Map.Entry e2 = (Map.Entry) o2;Comparable c1 = (Comparable)e1.getValue();Comparable c2 = (Comparable)e2.getValue();return c1.compareTo(c2);}}***Note*** : Your ending list will be of the type Map.Entry. To get a listing of just the ID values you will have to cast them properly. If you are iterating through the list, it would be like this ((Integer)((Map.Entry)iterataor.next()).getKey()).intValue()
  10. http://www.mattkruse.com/javascript/dynamicoptionlist/
  11. the best thing I can come up with is to create a hashtable which uses a simple ascending integer list as keys, and the ID as the values, then make a vector of the data to be sorted, using the same indexes as the hash table. Copy that vector and sort it, then iterate through the sorted vector and perform a reverse lookup (pull the index) on the non-sorted vector, then use that index to reference the hashtable and finally pull out the SFIID.This will work I'm sure of it, but this can't possibly be that complicated. I know I'm not that first person that has needed to sort a map by the value rather than the key.
  12. Now, I'm not completely stupid, I know how to just straight up sort a list of integers, but this is more complicated.What I need to do, is take a list of IDs (not the integers being sorted), iterate through that list and pull out the number associated with each ID from a MySQL database, sort the numbers, and then output a list of just the IDs, sorted by the number previously pulled out.I had this same problem before, only the data being sorted was a string. So what I did was create a hashtable. I made the String to be sorted (with the ID appended on the end) the key, and I made the ID the value. I created a vector from the key set, sorted it, and then iterated through it to pull all the values out of the hashtable (IDs) into a new sorted vector, it worked great.However now that I'm dealing with numbers, things are complicated. Hashtables can not have duplicate keys, and before I just appened the ID onto the string to be sorted, but if I do that with an integer it will create a new number and throw off the sort. I can not handle it as a string and them remove the appended part when I go to sort either, because then I lose my original key to look up the IDs after the sort. Also, I can not switch my hashtable data (make the ID the key and the sorted data the value) because Hashtables don't have any reverse lookup methods. i.e. I can't send in a value and return the key.Somebody recommended that I try a LinkedList, which sounded good after a bit of reading, but it didn't work either. I need to keep the IDs linked to the numbers, so when I try to use the ID (which is an int btw) as the index and the number as the value, I got IndexOutOfBounds exception. The IDs are 6 or 7 digit numbers, so I don't think just allocating a ton of space to it would be a good idea, when probably no more than a few hundred indexs will be assigned values.So.....any ideas?I need something that will link an ID (can be String or int) to an integer value, allow me to pull the numbers out and sort them, and then reference the IDs using the values from the sorted list as the lookup criteria.
  13. spoonraker


    If it is homework, I don't mind helping, but I'm not going to just do it for him.A basic idea of what needs to be done :Create a page with the proper formWhen the form is submitted, capture the variables from the request. request.getParameter()Calculate stuff. If you can't do this part without any help, you're in over your head with this project
  14. spoonraker


    Is this a homework assignment? lolAnyway, I'm not sure how you could do that with just Javascript and HTML, maybe you can, but as far as I know (other than ajax) JavaScript is just a browser scripting language.If you have a JSP page it wouldn't be hard at all. Just submit the page to its self and collect the variables from the request using request.getParameter("NAME"). Check each one to make sure it's greater than zero, and then do your computation if it passes the check.
  15. spoonraker


    sorry to take so long to reply, forgot about this thread, my badLook at my example, notice how I put the print command inside an if statement that checks for null data. You're going to have to do something like that for each piece of data.
  16. For those of you who were doubting my method, I've finally got it into a testing phase, and it's 1000000x faster than it was before.I made a few tweaks to greatly improve performance. Instead of creating a huge list of objects, I just made a huge hashtable of IDs and sort values. Whatever data was being sorted by was the key, and the ID was the value. Then I made a vector of keys, and sorted that, and created an Iterator for that vector to loop through my hashtable and pull out a sorted list of IDs. Then, instead of creating all the objects at once, I made it so it only does 50 at a time, since that's all that will be displayed on a single page. The controller object persists in the session so when they change pages I just had to make a simple function which iterates page*50 through the sorted list and then generateds 50 more objects.
  17. spoonraker


    Make your form's action the URL to the page you're on. So if you are on whatever.com/whatever.jsp, your form tag would be <form method="post" action="/whatever.jsp">Then below your form on that page you're going to want to use request.getParameter(String) method to pull the data from the submitted form(for this example, you're having the user enter their name) <form method="post" action="/whatever.jsp"> <!-- Form submits to the same page it's located -->Name : <input type="text" value="" name="name"/></form><%if(request.getParameter("name") != null && !request.getParameter("name").equals("")){ String name = request.getParameter("name"); out.print("Welcome, " + name);}%>
  18. Well nevermind, I got it figured out.In case you're wondering I used a Hashtable to store the original ID/Name combo. I actually used the Name as the key and the ID as the value. Then I created a Vector of the keySet from the Hashtable using the .keySet() method, which I sorted using Collections.sort(). Then I created an Interator from the vector, and used that to loop through the original hashtable, using the values of my sorted vector as keys for the hashtable. <%@ page import="java.util.*" %><%String[] array1 = {"Bob","Alex","Chris","Dale","Elizabeth"};String[] array2 = {"243","3342","38294","8429","482929399"}; Hashtable h = new Hashtable(); for(int x=0;x<array1.length;x++){ h.put(array1[x].toLowerCase(), array2[x]); } // unsorted keys output out.println("Unsorted <br><br>"); Iterator it = h.keySet().iterator(); while (it.hasNext()) { String element = (String)it.next(); out.println(element + " " + (String)h.get(element) + "<br>"); } out.println("<br>Sorted by name <br><br>"); // sorted keys output thanks to T. GUIRADO for the tip! Vector v = new Vector(h.keySet()); Collections.sort(v); it = v.iterator(); while (it.hasNext()) { String element = (String)it.next(); out.println( element + " " + (String)h.get(element) + "<br>"); } out.println("<br>ID sorted by name<br><br>"); Iterator test = v.iterator(); while(test.hasNext()){ String element = (String)test.next(); out.println((String)h.get(element) + "<br>"); }%> Unsortedelizabeth 482929399bob 243alex 3342chris 38294dale 8429Sorted by namealex 3342bob 243chris 38294dale 8429elizabeth 482929399ID sorted by name3342243382948429482929399
  19. What I have to start with is a list of IDs and Strings, we'll say name for example. The IDs are unique to the name, and not in any particular orderex.ID Name--------------123 Bob3902 George392 Paul99833 AlexWhat I need to do is sort the list by Name, and then generate a list of IDs from this sorted list.In the example above, the final list I need would be : 99833, 123, 3902, 392Also, the final list needs to be indexed numerically so I can loop through it, so something like an array where array[0] = 99833, array[1] = 123, etc.It doesn't have to be a basic array, you can use any type of list, as long as it's loopable. So even something like an ArrayList would work. (int)arrayList.get(Integer.toString(0)) should be 99833, etc.Any ideas?
  20. What do you mean you want it to register your page?Do you mean you want a login script?
  21. Databases are designed for storing and retrieving data, not sorting it. They can retrieve a sorted list of data, but they can't sort data without retrieving it all again. This is why the program was so slow before. In order to do a simple sort or filter, you had to pull ALL the data out again.How can any of you even attempt to argue that pulling the data once and sorting it with Java is slower than running a 30+ second query every time you change anything on the page.
  22. I think you guys are missing the point. I have absolutely no problem with pulling the rank using only SQL queries. The reason I originally asked if I could pull the rank in an SQL query was so I could implement that in the original method.The reason that I'm fundamentally changing the program isn't because I couldn't figure out how to pull rank out of the database, but because the way the program worked before was incredibly inefficient.There was going to have to be over twenty joins on the query, each of those tables having at minimum hundreds of thousands of rows, some even with millions. Not only that, but each time you changed a filter or sort, it would have to rebuild the query with different WHERE clauses and ORDER BY criteria, which is convenient for the programmer since all that logic is built in to SQL, but it makes the program terribly slow. The query took over 10 full seconds to run originally, and I was doing well more than tripling the amount of data with my modifications. The SQL tables are all properly indexed and made to run as efficiently as possible, so please don't try to tell me that I just don't know how to run SQL queries. There simply is no way to query that much data quickly.Did you guys not see this? This is what the SQL query looked like BEFORE I added anything. There would be 15+ more joins. By the time I added 2 or 3 more it was taking an ugodly amount of time to run, which is why I knew I had a problem. I posted the thing about the rank before I realized this. select t1.*, t2.generation ,t5.currsvp as a_currsvp ,t5.prevsvp as a_prevsvp ,t5.ss_completed,t5.ssdate,t6.weight,t6.referralstl,t6.referrals3 ,t7.ea, t7.tl, t7.tlrank as rank ,t8.focus_id, t9.lastlogin ,t10.creationdate from affiliate_index t2, affiliates t1 left join affilaux t5 on t1.sfiid=t5.sfiid left join matrix.matrix_weight t6 on t1.sfiid=t6.sfiid left join sfi.tnet_rank t7 on t1.sfiid = t7.sfiid left join focus_map t8 on t1.sfiid = t8.sfiid left join lastlogin t9 on t1.sfiid = t9.sfiid left join affiliate_profile t10 on t1.sfiid = t10.sfiid where t2.refby=21505 and class in ('A','M','P') and t1.sfiid = t2.sfiid and t2.generation = 1 order by sfiid ASC The way I'm solving this problem is quite simple. I'm creating an object that pulls the data from the DB using a bunch of small queries instead of one massive one, this is MUCH faster, and then I'm simply creating some kind of list (probably ArrayList) of those objects. All sorting and filtering will be done by the java server without having to query the database again.Sure, it's going to be harder for me to work with the data this way for sorting and filtering, but the end result should be a much faster operating page with far fewer errors.
  23. the point is, even if it is possible to do it, the query would ludicrously slow. It's already incredibly slow just from the shear amount of data that it's sorting through, I don't even want to imagine how bad it would be with 10 more joins and a bunch of comparison
  • Create New...