Posts

javascript - Create object from string in JavasScript ECMAScript 6 -

i want create object factory using es6 old-style syntax doesn't work new. i have next code: export class column {} export class sequence {} export class checkbox {} export class columnfactory { constructor() { this.speccolumn = { __default: 'column', __sequence: 'sequence', __checkbox: 'checkbox' }; } create(name) { let classname = this.speccolumn[name] ? this.speccolumn[name] : this.speccolumn['__default']; return new window[classname](name); // line throw error } } let factory = new columnfactory(); let column = factory.create('username'); what do wrong? don't put class names on object. put classes there, don't have rely on them being global , accessible (in browsers) through window . btw, there's no reason make factory class, instantiate once (singleton). make object: export class column {} export class sequence {} expo...

javascript - Regular expression not supporting line skipping \n -

i'm trying find right regular expression number line skip @ end ( \n ) every time it's not working. my regular expression /^\d+(\n)$/ . edit : text area contains : 22\n 33 here's code ( i'm trying validate what's in textarea , it's numbers going there \n @ end of each lines ) : function validechamp() { var rexp1 = /^\d+(\n)$/; var achamps = document.queryselector("textarea").value; if (rexp1.test(achamps.value)==true){ alert("valide") } else { alert("invalide") return false; } } if want check line containing number on it, can use: /(^|\n)\d+(\r?\n)/ if want check there's number, , newline, , nothing else: /^\d+(\r?\n)$/ (which checking for, that's odd input pattern.) if want make sure textarea has lines numbers, might simpler check string.replace(/[0-9\r\n]/g, '') == '' . confirm if contains numbers , newlines.

javascript - Why is my tag still showing? -

this what's inside controller what's wrong way pass values? tried putting inside function still didn't fixed it. removed parts of code since i'm pointing out on how show or hide div using angularjs ng-show . followed answer in link var atag = this; atag.vaanchor = false; atag.nseanchor = false; //showanchor(); // function showanchor(){ var encodedstring = 'action=' + encodeuricomponent("checklogin") + '&user=' + encodeuricomponent(dataform.datausername) + '&pw=' + encodeuricomponent(dataform.datapassword); $scope.errormsg = ""; //reset error message .success(function(data, status, headers, config) { if ( data[0]["data"] != undefined) { $scope.errormsg = "incorrect username/password"; $("#mypass...

spring - how to keep jpa session in the thread -

now use jpa in web application. , have class this: class { ... @onetomany private list<b> list; ... } when in http request, can use a.getlist() successful. in schedule thread, throws exception: org.hibernate.lazyinitializationexception: failed lazily initialize collection of role: a.list, not initialize proxy - no session can keep session in schedule thread http request thread? actually, when spring handle http request, start transaction interceptor org.springframework.orm.hibernate3.support.opensessioninviewinterceptor or filter org.springframework.orm.hibernate3.support.opensessioninviewfilter . if want keep session, can start , commit transaction our self. here code: public class backendthread { @autowired private platformtransactionmanager platformtransactionmanager; @override public void onmessage(message message, byte[] pattern) { new transactiontemplate(platformtransactionmanager).execute(new transactioncallb...

android - Layout pushing views down the screen -

Image
so, have imageview inside framelayout. need way. feel issue here image , it's size itself. layout image pushes further down other views on screen leaving considerable empty space that's supposed layout. i found hard coding height value let's me minimize issue. if height wrap_content image reach same point blank space supposed layout extends extreme lengths. so want know if image size (or resolution?) problem (which seems be) or else, , if there better solution hardcoding layout height. in advance. here code: <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <framelayout android:layout_width="match_parent" android:layout_height="700dp"> <imageview android:id="@+id/image_header" android:layout_width="match_parent" android:layout_height=...

java - Wrong number of values when importing csv file in Weka tool -

i want open csv file (saved openoffice calc) in weka. keep getting error: " wrong number of values. 120 read, 110 expected on line 4." csv fixed quotes around labels. , count 120 values on first lines. have removed possible symbols(, ; " = + -) possible. still problem persists.

java - Am I calling the other classes correctly? I feel like the SnakeBoardDisplay should only be created once -

i have 3 separate classes in java 1 logic, 1 painting, , last window. window class, class creates board display , adds window class public snakewindow() { this.settitle("snake"); this.setdefaultcloseoperation(jframe.exit_on_close); this.setsize(win_wid, win_hei); snakeboarddisplay dpanel = new snakeboarddisplay(); this.add(dpanel); inintmenu(); this.setvisible(true); setresizable(false); } public static void main(string[] args) { new snakewindow(); } board display class, class creates new board display where proper place class called , executed? public snakeboarddisplay() { game = new snakegame(); tm.start(); addkeylistener(this); setfocusable(true); setfocustraversalkeysenabled(false); } public static void main(string[] args) { new snakeboarddisplay(); } game class public snakegame() { init(); } public void init() { for(int = 0; < tokens; i++) { int q = i; ...