Re: Question for Java people on this list: Converting a CF app to JS P
I am sure you could write your own taglib to help with this, here is a tutorial for you http://www.orionserver.com/tutorials/taglibs/4.html Regards Mark Drew On Wed, 29 Dec 2004 15:19:16 -, Nick de Voil <[EMAIL PROTECTED]> wrote: > > It seems to be kind of poor not to be able to use switch on a string. If > I > > use the dept number say (0305) instead of the name would this work or > would > > Java freak on the 0 (zero). Our database treats these fields as varchar > since > > the zero in front has meaning to the accounting people. > > Yes, it's a pain. The department number would work except that you are > right, Java would take the initial 0 to mean it's an octal number. > > Nick > > ~| Special thanks to the CF Community Suite Silver Sponsor - CFDynamics http://www.cfdynamics.com Message: http://www.houseoffusion.com/lists.cfm/link=i:4:188934 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
Re: Question for Java people on this list: Converting a CF app to JS P
> It seems to be kind of poor not to be able to use switch on a string. If I > use the dept number say (0305) instead of the name would this work or would > Java freak on the 0 (zero). Our database treats these fields as varchar since > the zero in front has meaning to the accounting people. Yes, it's a pain. The department number would work except that you are right, Java would take the initial 0 to mean it's an octal number. Nick ~| Special thanks to the CF Community Suite Silver Sponsor - CFDynamics http://www.cfdynamics.com Message: http://www.houseoffusion.com/lists.cfm/link=i:4:188930 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
RE: Question for Java people on this list: Converting a CF app to JS P
It seems to be kind of poor not to be able to use switch on a string. If I use the dept number say (0305) instead of the name would this work or would Java freak on the 0 (zero). Our database treats these fields as varchar since the zero in front has meaning to the accounting people. Mario -Original Message- From: Nick de Voil [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 29, 2004 10:05 AM To: CF-Talk Subject: Re: Question for Java people on this list: Converting a CF app to JS P Mario > Does anyone know if this can be done with the SWITCh statement in JSP. Can > switch be used on strings --- I have been told yes and no by different people No, afaik the switch statement in Java needs a simple scalar type such as int or char. I suggest you use if...else if. Nick ~| Special thanks to the CF Community Suite Gold Sponsor - CFHosting.net http://www.cfhosting.net Message: http://www.houseoffusion.com/lists.cfm/link=i:4:188929 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
RE: Question for Java people on this list: Converting a CF app to JS P
Java doesn't allow you to use anything other than integer (or castable to integer) values for switch statements, so strings can't be sued. With a switch that small, I recommend a series of if statements String s=department.trim().toUpperCase(); if (s.equals("FAO")) rate=0.09; else if (s.equals("CAO")) rate=0.19; else if (s.equals("RES")) rate=0.39; else rate=0.09; This will do at most 3 string comparisons, which isn't all that bad. Assuming you are just mapping values to values, you might want to use a map/hashtable/properties object... Example: // scope this in the application scope java.util.Hashtable values=new java.util.Hashtable(); values.put("CAO",new Double(0.19)); values.put("RES",new Double(0.39)); values.put("DEFAULT",new Double(0.09)); Then you can do Double d=(Double) values.get(department.trim().toUpperCase()) to get the value. This is usually better for larger cases, where lots of if statements would take longer than a single hash lookup Then there's an alternative way to use switches if you have more code than just an assignment to make. First convert all your string values to integers via a map, and switch on the integers I would do this (so it's easy to read, like this) Static final int FAO=1, CAO=2, RES=3; Hashtable table=new Hashtable(); Table.put("FAO",new Integer(FAO)); Table.put("CAO",new Integer(CAO)); Table.put("RES",new Integer(RES)); int switchValue=-1; Integer d=(Integer ) table.get(department.trim().toUpperCase()) if (d!=null) swtichValue=d.intValue(); switch(switchValue){ case FAO: ... break; ... etc... } -Original Message- From: Ciliotta, Mario [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 29, 2004 9:55 AM To: CF-Talk Subject: Question for Java people on this list: Converting a CF app to JS P Hi, I was wondering if someone on this might have experience using the SWITCH statement in JSP. I am in the process of converting a CF app to JSP (Do not ask why -- company standards for the future) and in the CF page I make use of the and I looked into JSP/Java and there is also a switch statement but I cannot get it to work correctly. Here is a CF example: Does anyone know if this can be done with the SWITCh statement in JSP. Can switch be used on strings --- I have been told yes and no by different people but I cannot get past the problem. Thanks Mario ~| Special thanks to the CF Community Suite Gold Sponsor - CFHosting.net http://www.cfhosting.net Message: http://www.houseoffusion.com/lists.cfm/link=i:4:188928 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
RE: Question for Java people on this list: Converting a CF app to JS P
I forgot to paste it in: String dept = rset.getString("DEPARTMENT"); from my Oracle Query switch(dept) { case "FAO": out.println("It\'s FAO."); break; case "CAO": out.println("It\'s CAO."); break; case RES: out.println("It\'s RES."); break; default: out.println("It is a different one."); } This is my first try at Java/JSP so this is only an example that I am trying to get working before I add the real logic to it. I figured out the query and the result set and looping over the result set -- sorry nothing beats CFQUERY but this SWITCH statement is confusing me. Thanks Mario -Original Message- From: Matthew Small [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 29, 2004 9:59 AM To: CF-Talk Subject: RE: Question for Java people on this list: Converting a CF app to JS P Show the JSP example also. Matthew Small Web Developer American City Business Journals 704-973-1045 [EMAIL PROTECTED] -Original Message- From: Ciliotta, Mario [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 29, 2004 9:55 AM To: CF-Talk Subject: Question for Java people on this list: Converting a CF app to JS P Hi, I was wondering if someone on this might have experience using the SWITCH statement in JSP. I am in the process of converting a CF app to JSP (Do not ask why -- company standards for the future) and in the CF page I make use of the and I looked into JSP/Java and there is also a switch statement but I cannot get it to work correctly. Here is a CF example: Does anyone know if this can be done with the SWITCh statement in JSP. Can switch be used on strings --- I have been told yes and no by different people but I cannot get past the problem. Thanks Mario ~| Special thanks to the CF Community Suite Gold Sponsor - CFHosting.net http://www.cfhosting.net Message: http://www.houseoffusion.com/lists.cfm/link=i:4:188927 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
Re: Question for Java people on this list: Converting a CF app to JS P
Mario > Does anyone know if this can be done with the SWITCh statement in JSP. Can > switch be used on strings --- I have been told yes and no by different people No, afaik the switch statement in Java needs a simple scalar type such as int or char. I suggest you use if...else if. Nick ~| Special thanks to the CF Community Suite Silver Sponsor - New Atlanta http://www.newatlanta.com Message: http://www.houseoffusion.com/lists.cfm/link=i:4:188926 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
RE: Question for Java people on this list: Converting a CF app to JS P
Show the JSP example also. Matthew Small Web Developer American City Business Journals 704-973-1045 [EMAIL PROTECTED] -Original Message- From: Ciliotta, Mario [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 29, 2004 9:55 AM To: CF-Talk Subject: Question for Java people on this list: Converting a CF app to JS P Hi, I was wondering if someone on this might have experience using the SWITCH statement in JSP. I am in the process of converting a CF app to JSP (Do not ask why -- company standards for the future) and in the CF page I make use of the and I looked into JSP/Java and there is also a switch statement but I cannot get it to work correctly. Here is a CF example: Does anyone know if this can be done with the SWITCh statement in JSP. Can switch be used on strings --- I have been told yes and no by different people but I cannot get past the problem. Thanks Mario ~| Special thanks to the CF Community Suite Gold Sponsor - CFHosting.net http://www.cfhosting.net Message: http://www.houseoffusion.com/lists.cfm/link=i:4:188923 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54