Posts

Showing posts from May, 2010

rest - How to catch all exceptions that could arise in Symfony2 controller action? -

i trying build rest web service returns json calls. pretty straightforward, this: return new response(json_encode($return_object)); my question is, how should intercept exceptions in global way? want this, because if exception happens anywhere in application, i'd still return json message client saying "yo dawg, heard exceptions". thinking returning json in both success , failure cases simplify work client needs implement api. so far, thing can think of write every controller action this: public function generatememeaction($arg1, $arg2) { $return_object = array(); try { // stuff generate meme here $return_object['status'] = "great success!"; } catch (exception $e) { // epic fail $return_object['status'] = "unluckybrianexception"; } return new response(json_encode($return_object)); } which great , wonderful, try-catch block same every action in app, , feel silly every time have edit around bunch of copy pasta. pro tips? rest ap...

java - Exception with surefire plugin with test phase in maven -

i need use surefire v2.12, attached stack trace every time run version. if run v2.10 not error. need version can annotate test classes @category , label them either unittests or integrationtests. here's command: mvn test -dsurefire.version=2.12 -x [error] failed execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project project: execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test failed: java.lang.reflect.invocationtargetexception; nested exception java.lang.reflect.invocationtargetexception: null: exceptionininitializererror: unexpected classnotfoundexception looking class 'org.apache.maven.cli.mavencli' -> [help 1] org.apache.maven.lifecycle.lifecycleexecutionexception: failed execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project aspen: execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test failed: java.lang.reflect.invo...

jquery - Make radio buttons avoid selection with keyboard navigation? -

is possible make can navigate through set of radio buttons arrow keys without automatically selecting them? have popup want close when user selects radio button , i'm using .click(), when navigate radiobuttons in popup arrowkeys, each navigation leads popup closing , user having reopen it. suggestions? thanks! edit: live demo: jsfiddle.net/tkwzh/4 real thing has lot more open , close function, there way combine keydown enter , mousedown one? like $("#popup2 input:radio").bind('keydown keycode == 13', 'mousedown' function () { $('#popup2').css('display', 'none'); }); something this? though realize incorrect , makes no sense. this behavior specific browsers. ie appears select radios based on arrow keys, whereas, chrome not. that said, can disable behavior preventing keydown event via jquery. recommend doing on div (or other element wraps radio buttons), doesn't apply entire document: $('div.wrap').keydown(fu...

asp.net - machine key not working - viewstate mac failed -

i keep getting viewstate validation error: system.web.httpexception (0x80004005): validation of viewstate mac failed. if application hosted web farm or cluster, ensure configuration specifies same validationkey , validation algorithm. autogenerate cannot used in cluster. ---> system.web.ui.viewstateexception: invalid viewstate... i have arr load balancing site , think when switches user 1 server (even though have affinity selected) throws this. - have machine key configured , have same encryption method, decryption method, validation key , decryption key configured on both of 2 servers in farm. missing something? one of our servers behind on windows updates , after running updates problem appears gone. i've re-run exact tests consistently invoked exception before , it's not having issues.

Proper save/restore of RNG state in boost::random behaving unexpectedly -

i have small test program attempts save , restore state of random number generator using boost::random, not behaving documentation indicates. boost docs: classes model pseudo-random number generator should model streamable concept, i.e. implement operator<< , operator>>. if so, operator<< writes current state of pseudo-random number generator given ostream operator>> can restore state @ later time. state shall written in platform-independent manner, assumed locales used writing , reading same. pseudo-random number generator restored state , original @ just-written state shall equivalent. as understand it, if rng state saved , number pulled it, state should change. if state later restored, should allow exact same number generated generator has been rolled back. made test program examines this, @ first glance seems state not restored. consider code: unsigned int s = static_cast<unsigned int>(std::time(0)); //typedef boost::minstd_rand base_generator_t...

java - Should I map cascade operations in hibernate when it's fully mapped in SGBD? -

i've defined foreign keys , cascade operations in mysql, should map in hibernate objects or leave mysql it's things alone? if going define them within db defining them on hibernate objects generate delete statements aren't necessary. personally think having cascading deletes within db can difficult work db has more of intelligence of application. prefer define these types of business rules within code rather in db because keeps of persistence information in 1 place. think it's similar argument why many people dislike db triggers.

c++ - Object Array of Derived Objects -

i have array of objects derive class basestudent. basestudent**studentlist = new basestudent*[atoi(listsize.c_str())]; that array populated either derived math, english or history objects. i'm trying print out specific data each object in array , output file. for (int j=0; j<atoi(listsize.c_str()); j++){ if(studentlist[j]->getmt() == english){ output << studentlist[j]->getfn()<<" "<<studentlist[j]->getln(); output << right << setw(42) << studentlist[j]->getfinal(); // english public function can't call this. } } i need able access derived classes private member data array of objects. here's header. can see have setter , getter every protected member data. #include <iostream> #include <string> using namespace std; #ifndef basestudent_h #define basestudent_h enum majortype {english, history, math}; // ********************************************************************* // base class. other classe...

object - Classic ASP - When to close recordset -

i know, of following examples best closing recordset object in situation? 1) this 1 closes object inside loop opens new object when moves next. if there 1000 records, opens object 1000 times , closes 1000 times. do: sql = " ... " set rs1 = conn.execute(sql) while not rs1.eof sql = " ... " set rs2 = conn.execute(sql) if not rs2.eof response.write ( ... ) end if rs2.close : set rs2 = nothing rs1.movenext wend rs1.close : set rs1 = nothing 2) this example want know about. saving object closure (rs2.close) until after loop has finished, gains or reduces performance? if there 1000 records, open 1000 objects closes once: sql = " ... " set rs1 = conn.execute(sql) while not rs1.eof sql = " ... " set rs2 = conn.execute(sql) if not rs2.eof response.write ( ... ) end if rs1.movenext wend rs1.close : set rs1 = nothing rs2.close : set rs2 = nothing i hope i've explained myself enough , it's not stupid. update to think query can modified avoi...

How to handle nulls in linq to entities -

how handle null max value in linq entities statement? int userlevelid = db.characters.where(o => o.userid == userid).max(o => o.levelid); i'm not quite sure mean when count, since aren't referring count anywhere in code. if wonding how handle null o.levelid this: max(o => o.levelid ?? -1); ?? coalesce operator in .net update try this: db.characters.where(o => o.userid == userid).max(o => o == null ? 0 : o.levelid);

birt - Using a Grid Element in a Sub-Table cell causes a page break to be added to PDF export -

Image
currently, report set child table placed in row of parent table. each row of child table has grid element allows me have more control on format of report. there several fields in child report varying field lengths field per column of report won't work. note setting data source of tables, not of grid elements. this works when rendering html, however, when rendering pdf file page break appears before row containing child page. things have tried resolve issue with: setting page breaks "avoid" setting page break interval high tested 2.6.2 , 3.7.2. 4.2 not run on machine. when using column each field in table instead of grid element in single cell, problem goes away undesirable there multiple fields varying field lengths. merging multiple cells make room different lengths work, can become unruly when need change report format. the size of grid/table not matter - happens when using couple fields data set. after more experimentation, found out if remove detail rows of...