Skip to main content

Posts

Showing posts from January 31, 2012

Does storing large sessions slow down response time and server

I am in the process of creating a Facebook App for my website which includes functionality that requires the users friends list. Retrieving the friends is no problem, what I am struggling to decide, is how to store them. Option 1 - Store the users in my MySQL database, I have opted not to go for this as my database will become very heavy, very quickly. In addition, I will need to create a table for each individual Facebook user! Option 2 - Store the Facebook friends array in a session which is updated every half an hour to ensure new friends are included. Ignore the fact that the session updates every half an hour, is it a bad idea to store, what can be a very large array, within a session? The website is likely to be receiving high volumes of traffic, and will therefore be storing a lot of these sessions. Although I am an experienced developer, I am not overly experienced with sessions in these circumstances. I would simply like to know whether or not this i

what this error is due to session_start

My hosting sent me email saying I have set the session.save_path = /home/users/web/b1475/moo.youraccount/cgi-bin/tmp for your account then i found my website is giving me this error Warning: session_start() [function.session-start]: open(/home/users/web/b1475/moo.youraccount/cgi-bin/tmp/sess_718a8cd346244df6916f016eb315f19f, O_RDWR) failed: No such file or directory (2) in /hermes/waloraweb006/b1475/moo.youraccount/db.php on line 4 and the db.php code is (it is database connection file) <?PHP $conn = mysql_connect($host, $user, $pass); if ($conn) mysql_select_db($db, $conn); session_start(); ?> what can i do then to fix this error :(

process PHP on hitting URL & configuring PHP

For my website, I want one of my PHP script to be executed on entering on URL before loading the page(before entering into my site, on hitting enter first this has to be executed), could you suggest me how. Secondly, I've configured PHP ini in localhost in order to include URL & fopen but how can I do changes on the server, am using filezilla on windows.

PHP cURL timeout is not working

I'm having a server issue. I'm running a local server (for developing) and I've changed my local server from MAMP to XAMPP. However, on XAMPP, the cURL option CURLOPT_TIMEOUT_MS or CURLOPT_CONNECTTIMEOUT_MS gives me the next error: Warning: curl_setopt() expects parameter 2 to be long, string given Is this because of the PHP or cURL version? Maybe a configuration setting? curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT_MS, 2500); Additional information: OSX 10.6.8 PHP 5.3.1 cURL 7.19.7 Thanks in advance. Edit: There seems to be some confusion about the error and the variable to set. The error states that parameter 2 is invalid. Not parameter 3 . So the CURLOPT_CONNECTTIMEOUT_MS seems to be the issue. curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT_MS, 2500); ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ parameter: #1 #2 #3 Fun fact: var_dump(CURLOPT_CONNECTTIMEOUT_MS); displays string(25) &

Backup MySql Database?

I have asked this question before but I haven't got an answer, so I'm rephrasing it. I want to back up a db using either: system("mysqldump -h DB_HOST -u DB_USER -p DB_PASS logindb > $location/$backup"); or: sql="BACKUP my_db TO DISK my_backup_folder WITH FORMAT #"; if ($stmt = $this->connect->prepare($sql)) { $stmt->execute(); $stmt->close(); } else { $error = true; $message['error'] = true; $message['message'] = CANNOT_PREPARE_DATABASE_CONNECTION_MESSAGE; return json_encode($message); } But the first gives me an empty sql file and the second gives me nothing. Why is that, and if there is a way to find out what error occurred how would I do it ? Also which method is better ?

Multi-Dimensional array count in PHP

I have a multi-dimentional array set up as follows array() { ["type1"] => array() { ["ticket1"] => array(9) { // ticket details here } ["ticket2"] => array(10) { // ticket details here } ["ticket3"] => array(9) { // ticket details here } } ["type2"] => array() { ["ticket1"] => array(9) { // ticket details here } ["ticket2"] => array(10) { // ticket details here } ["ticket3"] => array(9) { // ticket details here } } } etc. I am trying to get a count of the total number of tickets in the array (number of second level items), but the number of types is variable as are the number of fields that each ticket has, so I cannot use COUNT_RECURSIVE and maths

YAML internationalization

I'm working in a big project.I'm thinking of a new idea to create the best way of internacianalization to many languages. Solutions: 1.Store data as arrays - tree file system.. It's not a good way because i need to modify files "on air". 2.I18n table.All translations have a common table or relative tables.(Queries to database + database cache) 3.YAML(it's new for me) I am reading about YAMl documentation and I like this structure..I suggest the 3rd solution. I would like to hear your opinions/suggestions. Thank you in advance.

ActionScript BEncoded XML file. Decoding same way as Flash:URLLoader in PHP

Hope topic is relevant :) I have a class in Action script that loads and interpretes an XML File. What I want to do is to be able to decode this file using PHP (Probably some kind of Binary Decoding) private static function interpreteXML(j:Event):void { ....... some var defined here..... var event:Event = j; var loader:URLLoader = (event.target as URLLoader); try { xml = new cXML(); xml.SetXMLString(String(loader.data)); } I'm looking for a function/class that would be able to decode XML in same way as URLLoader From what I saw in Flash AS3 Docs, URLLoader have abbility to load Binary encoded data and decode it. That's why I look for a PHP version of this method to be able to interprete files on PHP level.

Having issue with substr function in PHP

I have a string like this: $geometry = "POINT (1.5041909054501184 0.39827301781943014)" I have to split the two decimal values 1.5041909054501184 and 0.39827301781943014 based on space, into an array. For that, as expected, I have to chop-off 'POINT (' and ')' from the $geometry . I tried the following lines: $temp = substr($geometry , strpos($geometry, "(")+1, strlen($geometry)-2); and $temp = substr($geometry , strpos($geometry, "(")+1, strpos($geometry, ")")-1); Echoing $temp in both the cases displays string as: "1.5041909054501184 0.39827301781943014)" How can I remove the ')' from the string $geometry ? UPDATE How can I generalize it to strings like these? $geometry = "POINT (1.5041909054501184 0.39827301781943014)"; and $geometry = "POLYGON ((1.5049088554391572 0.39805485932781448, 1.5049135685638309 0.39805660717232405, 1.5049147247575003 0.39805462248168044, 1.504

AS3 to PHP - mail() function

When I click on send the textbox displays 'sending....' with no change. I'm very sure that this was working before, but the client has noticed it not working recently. I can't find the problem, please help. I have a swf with this AS3 var var_load:URLLoader = new URLLoader; var URL_request:URLRequest = new URLRequest( "http://www.blah.com/send_email_auto_response.php" ); URL_request.method = URLRequestMethod.POST; function submit(e:MouseEvent):void { if( contact_name.text == "" || contact_email.text == "" || contact_subject.text == "" || contact_message.text == "" ) { message_status.text = "Please fill up all text fields."; } else if( !validate_email(contact_email.text) ) { message_status.text = "Please enter the valid email address."; } else { message_status.text = "sending..."; var email_data:String

PHP read file error

I need to get an end result which loads a txt file counts how many times each word has been used and echos the results. The code is used is given below.Looking forward for valuable suggestions... <?php $text = fopen("words.txt", "r"); $textarray = explode(" ",$text); foreach($textarray as $numbers) { if(isset($str_count[$numbers])) $str_count[$numbers]++; else $str_count[$numbers]=1; } foreach($str_count as $words => $numbers) echo $words.": ".$numbers."<br>"; ?>

Multi entry form not passing info to mysql data base

I am trying create a form for my club which takes info from a database to enable a sub selection of trainees from the database. Then additionally select a from a list of events and INSERT both back into a database. It writes to the database OK and loops through the correct number of times but doesnt pass $trainee value to the database I think what is failing is the passing of the info from print ' <input type="hidden" name="Trainee" value= ' . $trainee . ' /> to the $query in the if(isset($_POST['formSubmit'])) loop. Anyone tell me where I am going wrong? Code listed below <?php //Retrieve trainees of specified grade $data = mysql_query('SELECT * FROM membership WHERE grade = "Trainee" ') or die(mysql_error()); // select works // Writes to database OK, including Trainee if manual value entered into form like done in instrucot $query = "INSERT INTO testtraining ( trainee_no, activity, instructor, entered_b

Cannot see loaded modules in hosted account

I am wanting to move my website online and my website is not working on my shared hosting account, only to find out that module mod_rewrite was not loaded. I ran phpinfo ( http://imranbukhsh.com/f/fcrawl/tmp/phpinfo.php ) and I cannot see the whole section on 'loaded modules' which I can see on my personal computer after I installed XAMPP: its a huge section on my pc ( in phpinfo ) and totally missing on my shared hosting server. My hosting company is Valcato Thanking you

DOM Manipulation in Wordpress (and elsewhere) using php

I'm quite new to the DOM manipulation world and I would like to get a head start in order to avoid common errors. I am looking for the most efficient way to manipulate content generated by wordpress using php. At the moment I am using Simple HTML Dom which seems to work just fine. However I recently found DOMDocument and a few others and it would be very helpfull if someone cleared out which one is faster, better or at least will generate less errors in case of really bad markup. Also on the side can someone explain what is this syntax (instead of $html this @$html) Thank you very much

Can we set a cookie in php according to client"s time?

I have following requirements: create a cookie for server domain that cookie will expire in x seconds say in 200 or 500 seconds. Problem is, that clients can lag as much as many minutes behind server. On server side I am setting cookie as setcookie($cooName,$cooVal,time()+500,"/"); but now if client computer is 500 seconds behind server, above code will effect into a cookie which will expire in 1000 seconds not 500 seconds. I was thinking to send client's time stamp to server and set cookie on that time. something like this: setcookie($cooName,$cooVal,$_GET['clientTS']+500,"/"); But if client is 500 seconds behind, and if I set such a cookie which is backdated it does not get set. How to achieve a time sync between client and server in case of cookie expiry?

Korean characters not displaying when pulled from MS Access database using php

I have an Access DB which contains a load of people with Korean names. I hava a classic asp site (which i inherited) that reads data from the DB quite happily and displays it properly. I am now developing a different site in php, but it is unable to display korean characters at all. I have written two very simple scripts, one in asp and one in php to work out why. ASP: <% Response.CodePage = 65001 Set objLoginConn = Server.CreateObject("ADODB.Connection") objLoginConn.Provider = "Microsoft.Jet.OLEDB.4.0" objLoginConn.Open "C:\wwwroot\mydb.mdb" Set rs = Server.CreateObject("ADODB.Recordset") SQL = "SELECT firstname FROM mytable" rs.Open SQL, objLoginConn, 3, 3 while not rs.EOF response.write("<p>"& rs.fields("firstname").value &"</p>") rs.movenext wend %> PHP: <?php $con = new COM("ADODB.Connection") or die("Cannot start ADO"); $con->Open(&quo

Sugar CRM New Module

I am using sugarCRM open source for my own purpose. I want to develop the new module with the existing code and i have downloaded the zip files from the internet for this. I want to know, Is there any possible to put the downloaded code directly in the folder? I did this,using "module loader" but i need to achieve through the direct path. And one more thing is, when i put the new files into the existing files, what are all the folders will affect?

Updating array in java

I'm facing a problem with this code,please anyone can help me? import java.util.Scanner; class A{ int p[]; int m,i; A(){ p=new int[][10,20,30,40,50]; } int sum(int p,int m){ p+=m; return p; } } class B{ int i,m; public static void main(String args[]){ A object=new A(); Scanner input=new input(System.in); m=input nextInt(); for(i=o;i<object.p.length;i++){ if(m==object.p[i]){ n=object.sum(object.p[i],m); object.p[i]=n; } } for(i=0;i<object.p.length;i++){ System.out.println(p[i]);} } When i am taking 10 as input then it matches with the first array value and then adds and becomes 20....But my problem is that when next time i will run the program again,the value will not be changed(with adding results)....... how can i update the value of p array after the method for further calculation:? ``

How to modify XML w/o DOMDocument / SimpleXML / libxml?

<?xml version="1.0" encoding="ISO-8859-15"?> <!DOCTYPE Finvoice SYSTEM "Finvoice.dtd"> <Finvoice Version="1.2"> <BuyerPartyDetails> <BuyerOrganisationName>Example Name</BuyerOrganisationName> <BuyerPostalAddressDetails> <BuyerStreetName>Street Name</BuyerStreetName> <BuyerTownName>Town Name</BuyerTownName> <CountryCode>FI</CountryCode> <CountryName>Finland</CountryName> </BuyerPostalAddressDetails> </BuyerPartyDetails> <InvoiceDetails> <InvoiceDate Format="CCYYMMDD">20120130</InvoiceDate> </InvoiceDetails> </Finvoice> I need to make a script to update this kind of XML file with either PHP or Javascript. I made something with PHP DOMXPath , but it turned out that it's not an option - the server doesnt have the support for it. All of these elements that

Seam Solder @MessageBundle generating the implementation classes Maven Error

I followed the documentation to use @MessageBundle with Seam Solder 3.1.0 here : http://docs.jboss.org/seam/3/3.1.0.Final/reference/en-US/html/solder-logging.html#typed-message-bundles but a get en error at compile time when Maven try to compile generated annotation : [ERROR] error: Cannot read com.apps.web.messages package files, cause : java.io.FileNotFoundException: com.apps.web.messages/WebMessages When I check in target directory the file is generated correctly : target/generated-sources/annotations/com/apps/web/messages/WebMessages_$bundle.java It seems that the maven plugins or the compiler can not find the interface WebMessages localized in src/main/java/com/apps/web/messages/ when he try to compile WebMessages_$bundle generated file. Environnement: Seam Solder 3.1.0.Final / Maven 3.0.3 / JDK 1.7 / JBoss AS 6.1.0

SharedPreferences: History saved but why not Favourite?

I use the following code to save words to History in my dictionary app: @Override public void onPause() { super.onPause(); saveHistoryToPreferences(); } public void saveHistoryToPreferences() { if (prefs.getBoolean("saveHistory", true) && mWordHistory != null && mWordHistory.size() >= 1) { StringBuilder sbHistory = new StringBuilder(); for (String item : mWordHistory) { sbHistory.append(item); sbHistory.append(","); } String strHistory = sbHistory.substring(0, sbHistory.length()-1); SharedPreferences.Editor editor = prefs.edit(); editor.putString("history", strHistory); editor.commit(); //Log.i(CONTENT_TAG,"history = " + strHistory); Log.i(CONTENT_TAG,"History saved!"); } } public void loadHistoryFromPreferences() { if (prefs.getBoolean("saveHistory", true)) {

Unjaring a .jar file in Objective-C

I was wondering if it was possible to extract the contents of a .jar file into a different directory, then add some files to that directory, and then compress the directory back into a .jar file, with the additions. A way of extracting the jar file i found was to use NSTask to execute the terminal command of jar xf (location of jar file) . This worked, but it halted the UI of the program permanently (without crashing it), and unarchived the contents into the directory that the application was stored in, which was a slight mess to clean up. Is there another way of doing this, or am I using NSTask incorrectly? Here is the code I am using: //Unarchive the jar [self runCommandWithBase:@"/usr/bin/jar" arguments:[NSArray arrayWithObjects:@"xf", jarLocation, nil]]; and - (NSString *)runCommandWithBase:(NSString *)base arguments:(NSArray *)arguments { //Create the task NSTask *task = [[NSTask alloc] init]; //Setup the task [task setLaunchPath:base]; [task setArgument

Spring 2.5 + quartz java.lang.NoClassDefFoundError: org/quartz/JobDetail

I have an issue with quartz library. I'm using it with spring 2.5: <bean id="reminderBean" class="com.mail.timexis.ReminderBean"> <property name="mailSender"> <ref local="timexisMailSender" /> </property> </bean> <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="reminderBean" /> <property name="targetMethod" value="execute" /> </bean> <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="jobDetail" /> <!-- run every morning at 6 AM --> <property name="cronExpression" value="* * * * * ?" /> </bean>

UnsupportedOperationException when using Apache Jakarta Digester to parse an XML in Android

I am getting the error below when parsing an xml file in Android using Apache Commons Digester. However, when just using plain Java, I am not getting the error below. Help! Thanks in advance. 01-30 16:30:07.892: E/Digester(304): **java.lang.UnsupportedOperationException: This parser does not support specification "Unknown" version "0.0"** 01-30 16:30:07.892: E/Digester(304): at **javax.xml.parsers.SAXParserFactory.setXIncludeAware(SAXParserFactory.java:347)** 01-30 16:30:07.892: E/Digester(304): at org.apache.commons.digester3.Digester.getFactory(Digester.java:439) 01-30 16:30:07.892: E/Digester(304): at org.apache.commons.digester3.Digester.getParser(Digester.java:652) 01-30 16:30:07.892: E/Digester(304): at org.apache.commons.digester3.Digester.getXMLReader(Digester.java:799) 01-30 16:30:07.892: E/Digester(304): at org.apache.commons.digester3.Digester.parse(Digester.java:1642) 01-30 16:30:07.892: E/Digester(304): at org.apache.commons.digest

KeyListener does not respond if there is any input in JTextField

I develop a simple MVC Calculator app. I decided to add some functionality by implementing KeyListener in CalculatorView. But this KeyListener only responds when there is no input in JTextField (before any input was made by pushing GUI buttons) or it responds when I press "ESC". I know some people here advice to use KeyBindings instead of KeyListener, but then I need to have 12 KeyBindings in my code (10 for numbers, 1 for ESC and 1 for "." character). Is there any way to make KeyListener to work properly in my app? And here is the code: /** * * @author Kate Nezdoly */ public class CalculatorView implements ActionListener, KeyListener { private JButton[] operButtons = new JButton[13]; private JButton[] numberButtons = new JButton[12]; private String[] operators = {"C", "(", ")", "+", "-", "*", "/", "^", "cos", "sin", "tan", "sqrt"}; pr

Android ICMP ping

Is there a way to ping a host (standard Android or via NDK implementation), and get detailed info on the response? (time, ttl, lost packages, etc..) I was thinking of some open source app that has this feature but can't find any... Thanks

How to allow user to enter only the letters, no numbers and other characters

I want to implement TexBox where user can input only letters. When user enter numbers or invalid characters, near TextBox must appear Error message. Like this:

<ToggleButton> onClickListener - changing drawable back to default

I've got this ToggleButton which is supposed to change the drawables (and functions) of some other buttons upon toggling on/off. So far i've only managed to make it work one way, by using this code. @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); toggle = (ToggleButton) findViewById(R.id.bRedGreen); toggle.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub minuskugle = (Button) findViewById(R.id.bBallhole); minuskugle.setBackgroundResource(R.drawable.redballinhole); } }); } How do you make it change the drawable back to default upon another click? _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __

Ajax call response in struts. Response not reflected in jsp.

I am calling a struts action on using an ajax call. In it i am changing the values of some properties of the action class. The values are set properly but i am not able to reflect the changes in the jsp. The jsp code is as follows. <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ taglib prefix="s" uri="/struts-tags"%> <html> <head> function findindex1() { var temp=document.getElementById("country").value; if(window.ActiveXObject){ request = new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest){ request = new XMLHttpRequest(); } request.onreadystatechange = showResult; request.open("POST",'temp.action?index='+temp,true); request.

Gui generator re-generate my maze if I change the current window dimensions(Java)

Given the following code : class Game() { private Shell shell; public Game(Display display,int level) { shell.addPaintListener(new ExmaplePaintListener()); shell.setText("Basic shapes"); shell.setSize(900,900); shell.setLocation(45, 45); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } } The listener : private class ExmaplePaintListener implements PaintListener { public void paintControl(PaintEvent e) { drawMaze(e); placeTreasuresInMaze2(e); e.gc.dispose(); } } and the method that draw the maze private void drawMaze(PaintEvent e) { // this method creates a new maze and draw it using GUI Java } My problem is that after the window of the maze is created , if I use the mouse to change the dimensions of the window , then the method drawMaze creates a new m

Error while working with List<? extends DefaultMutableTreeNodel>

public void findClassNodesMatching(String lowerCaseSearchText, List<? extends DefaultMutableTreeNode> foundNodes) { findClassNodesMatching(lowerCaseSearchText, (DefaultMutableTreeNode) getRoot(), foundNodes); } private void findClassNodesMatching(String lowerCaseSearchText, DefaultMutableTreeNode node, List<? extends DefaultMutableTreeNode> foundNodes) { String nodeLabel = node.toString().toLowerCase(); if (nodeLabel.indexOf(lowerCaseSearchText) >= 0) { foundNodes.add(node); } } Why does this code give an error The method add(capture#2-of ? extends DefaultMutableTreeNode) in the type List is not applicable for the arguments (DefaultMutableTreeNode) The error is at the line of foundNodes.add(node);

client side design using struts, jsp, html, css, java script, tiles, dojo, json, jquery etc [closed]

I need some help to design one front end system (client side ) for my new project. As per my project lead I should be using struts, jsp, html, css, java script, tiles, dojo, json, jquery etc.. The requirement is number of GUI pages like interactive graph, menu, etc.. The data will be fetched by back end code ( i am not worried much but ejb , jpa may be used). So my question is how should I progress on to this ? Can you please suggest any good design like which technology should be used where... Many Thanks

Concatenating RowFilter orFilters with andFilter in Java

All the questions pertaining this don't seem to answer the particular question I have. My problem is this. I have a list of search terms, and for each term I find the edit distance to find possible misspelling of a word. So for each word separated by a space, I have possible words each word could be. For example: searching for green chilli might give us "fuzzy" words "green, greene and grain" and "chilli, chill and chilly". Now I want the RowFilter to search for: "green OR greene OR grain" AND "chilli OR chill OR chilly". I can't seem to find a way to do this in Java. I've looked all over the place but nothing talks about concatenating the OR and AND filters together in one RowFilter. Would I have to roll my own solution based on the model? I suppose I can do this, but my method would most probably be naive at first and slow. Any pointers as to how to roll my own solution for this or better yet, what's th

retrieve serialized java.util.Arraylist in asp.net client (SUID doesn"t match)

I am trying to send persisted objects from a java webservice to the ASP.Net client. Both sides have the object-classes, with the same SerialUID's. Classes without (Array)Lists pose no problem, but when I want to send objects including ArrayLists, the expected SUID is incorrect: [java.io.InvalidClassException] = {"the class does not match the class of the persisted object for cl = java.util.ArrayList : __SUID = 8683452581122892189, getSUID(cl) = 9195509126275115639"} Serialization is implemented using binary formatting, not XML because with XML we have circular references between the persisted objects. Using J# at client side, by expecting a java.util.ArrayList instead of an IList or a System.collections.ArrayList doesn't change anything. Any help would be greatly appreciated!

Is there a better way to combine two string sets in java?

I need to combine two string sets while filtering out redundant information, this is the solution I came up with, is there a better way that anyone can suggest? Perhaps something built in that I overlooked? Didn't have any luck with google. Set<String> oldStringSet = getOldStringSet(); Set<String> newStringSet = getNewStringSet(); for(String currentString : oldStringSet) { if (!newStringSet.contains(currentString)) { newStringSet.add(currentString); } }

Generating hashCode() and equals() when creating Java classes using Mojo Jaxb2 maven plugin

The code I'm working on is using jaxb2-maven-plugin from org.codehaus.mojo to generate Java classes from XSD schema. I'm looking for a way to automatically implement equals() and hashCode() methods for those classes, but it seems there is not a way. I know that there are other JAXB2 Maven plugins that do that (http://confluence.highsource.org/display/J2B/Home for example), but I was wondering if anyone of you encountered this issue before and if there's a way for fixing it. I'm generating the classes using the xjc goal.

Writing CSV file. myPackage.MyClass cannot be cast to java.lang.CharSequence

I need to write List<MyClass> myList into CSV file. In particular I need to write values . MyClass has the following implementation: public class MyClass { private Object[] values; //... @Override public String toString() { String line = ""; for (int i=0; i<this.getSize(); i++) { //if (this.values[i] != null) { line = line + this.values[i] + " "; //} } return line; } } The code is the following: private void saveSolutionToCSV(List<MyClass> solution) { int columnSize = solution.get(0).getSize(); try { FileWriter writer = new FileWriter("test.csv"); Iterator result = solution.iterator(); while(result.hasNext()) { for(int i = 0; i < columnSize; i++) { CharSequence element = (CharSequence)result.next(); writer.append(element); if(i < columnSize - 1) writer.a

How can i make an event to a JComboBox which triggers AFTER selection?

I want to make an event which will be triggered after i make the selection to the JComboBox. the problem I'm now facing is that when i added an ActionListener, it was triggered when the user clicked on the box but BEFORE he actually chose the new item, thus the action listener was activated all the time on the previous value which was selected in the box. what i want to do is simply changing the title of an JTextArea according to the selection. I tried doing something like this: jBox.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { String alt = GetAlgoAreaTitleByChoice(); panel.remove(jArea); currentBest = setArea("",alt); currentBest.setBounds(50, 350, 1000, 290); panel.add(jArea); } }); and the method inside: private String GetArgsAreaTitleByChoice(){ String chi = jBox.getSelectedItem().toString(); if(chi.equals(generalChoice)){ return "Hello"; } else if

how get Image icon in JTable

i have created JTable. i get the value from DB to JTable . i am having problem while click on row it show the image icon path. cannot show the image. how i can set the image. one more thing i am having two images 1. Pointer image 2. Blank Image At the run time Pointer image in a first row by defaulty, After that i clicked in the 5th row, the first row should set with Blank Image, and the 5th rows should be set pointer image. and i don't know its possible in DefaultCellRender. package ex10012012; import java.awt.*; import javax.swing.*; import javax.swing.table.*; import java.sql.*; public class frame10012012 extends javax.swing.JFrame { private DefaultTableModel TmpFlxMdl; private TableColumn TmpFlxColumn; private int TmpRow,TmpFlxDRow; private TableColumn TmpFlxCol; private Statement TmpFlxSt=null; private ResultSet TmpFlxDRs=null; GENLMODL TmpGenModl= new GENLMODL(); FrmM01011 TmpFrmM0101 = new FrmM01011(); public frame10012012() { initCompo

crypt(3) $6$ password hash algorythm (based on SHA-512) in Java?

I'm looking for a Java function to generate/verify password hashes that were encoded in the way crypt(3) does when storing them in the Linux /etc/shadow file if sha512 is activated in /etc/pam.d/common-password. E.g. the plaintext string "geheim" will translate to: "$6$WoC532HB$LagBJ00vAGNGu8p9oeYDOSNZo9vTNTzOgPA.K0bJoiXfbcpj3jBuTkNwdzCrSNadRi8LanH1tH6tGGPPp/Lp3." From http://www.akkadia.org/drepper/SHA-crypt.txt I understand that, like with MD5, it's not just a SHA hash like DigestUtils or the Java MessageDigest classes produces but an algorithm that does a bit more magic.

Target Unreachable, identifier "demoBean" resolved to null

I am developing a web application using JSF on Netbeans 7.0. I have created 2 pages: one for entering persons name and other to display that name. I am using a java bean with get and set methods. I get an error when I submit my form on first page the code. This is my first page index.xhtml to accept name: <h:form> Enter your Name : <h:inputText value="#{demoBean.name}" required="true"/> <br/> <h:commandButton value="Submit" action="welcome.xhtml"/> </h:form> This is the other page welcome.xhtml to display the name: <h:body> Hello #{demoBean.name} </h:body> This is the managed bean demoBean.java : import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @ManagedBean() @SessionScoped public class demoBean { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }

Hibernate interceptors

I am trying to implement method described here , but can't make it work. There are no errors during compilation, but the interceptor never fired. DAO: public class GeneralInvoicesDAO { @Autowired private SessionFactory sessionFactory; @Autowired private Interceptor entityInterceptor; @Transactional public void update(GeneralInvoice object) { Session session = SessionFactoryUtils.getSession(sessionFactory, entityInterceptor, null); session.saveOrUpdate(object); } } The intercepter class: public class NewEntityInterceptor extends EmptyInterceptor implements Interceptor { /** * */ private static final long serialVersionUID = 2914362528125673753L; @Override public Boolean isTransient(Object n) { Logger logger = Logger.getLogger(getClass().getName()); try { logger.warn("test"); Boolean result = Boolean.FALSE; BaseEntity entity = (BaseEntity) n; if (enti

Why isn"t spring using my constructor to init this bean (Map parameter)

I have a spring beans configuration file where I define the following jackson classes as spring beans. For some reason on run-time the filterProvider bean is instantiated without the map argument. You can see from the docs that the SimpleFilterProvider does have such a constructor and that SimpleBeanPropertyFilter implements BeanPropertyFilter . <bean id="productAttributesAndAdvertiserNameFilter" class="org.codehaus.jackson.map.ser.impl.SimpleBeanPropertyFilter" factory-method="filterOutAllExcept"> <constructor-arg value="name"/> </bean> <bean id="offerIdFilter" class="org.codehaus.jackson.map.ser.impl.SimpleBeanPropertyFilter" factory-method="filterOutAllExcept"> <constructor-arg value="id"/> </bean> <bean id="filterProvider" class="org.codehaus.jackson.map.ser.impl.SimpleFilterProvider"> <

Open popupMenu only on mouse-click Swing

I have a question related with JPopupMenu that maybe someone can help me. As far as I can see, a JPopupMenu opens when you press a JMenu (is this is in a JMenuBar) or when you hover over a JMenu (if this is in a JPopupMenu). So, I have a JMenuBar containing a JMenu (let's call it 'File'). When I press 'File', a JPopupMenu open, which contains a JMenuItem and another JMenu (let's call it 'Properties'). Is there any way I can apply the same behaviour to the Properties JMenu as I have in the File JMenu: only opens the JPopup when the user click it and not hover over it? I know this is trying to avoid the normal behavior for the JMenu, but any of you have an idea if this is possible?

java output missing for cgi

In apache server,I want to use java to output something to the client,here's the java code public class Compile { public static void main(String[] args) { System.out.println("Hello world"); } } it just simply output a hello world,then I compiled it an copy Compile.class to server's root.there is also a cmd file there(the OS is windows),the compile.cmd @echo off echo Content-Type: application/x-javascript echo. echo start java Compile it has been good so far,if I execute it in command line the "hello world" will be shown. in apache's config file ExecCGI has been on and AddHandler cgi-script .cmd also been added. however,by visit [http://localhost/compile.cmd,only "start" displyed,the java's output "Hello world" disappeard.I can't find why the same problem can be fond here http://www.gossamer-threads.com/lists/apache/users/189828