java - How to pass parameter on jpa query generated by netbeans -
following code generated netbeans while binding jtable netbeans gui editor.
serverdetailsquery = java.beans.beans.isdesigntime() ? null : f1softsmscpuentitymanager.createquery("select s serverdetails s ");
and changed query using editing
select s serverdetails s order id desc
this working fine. want pass parameter on query filter record shortcode :
select s serverdetails s s.shortcode : filtershortcode order id desc
short code text field , there button filter record if user types shortcode , clicks button.
relevant code
@suppresswarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="generated code"> private void initcomponents() { bindinggroup = new org.jdesktop.beansbinding.bindinggroup(); f1softsmscpuentitymanager = java.beans.beans.isdesigntime() ? null : javax.persistence.persistence.createentitymanagerfactory("f1softsmscpu").createentitymanager(); serverdetailsquery = java.beans.beans.isdesigntime() ? null : f1softsmscpuentitymanager.createquery("select s serverdetails s order id desc"); serverdetailslist = java.beans.beans.isdesigntime() ? java.util.collections.emptylist() : serverdetailsquery.getresultlist(); jpanel1 = new javax.swing.jpanel(); serverdetailspanel = new javax.swing.jpanel(); bindbutton = new javax.swing.jbutton(); jscrollpane1 = new javax.swing.jscrollpane(); bindingdetailstable = new javax.swing.jtable(); blockbuttontobindingdetails = new javax.swing.jbutton(); smscbindingdetailsfilterpanel = new javax.swing.jpanel(); filterbyshortcodetextfield = new javax.swing.jtextfield(); jlabel1 = new javax.swing.jlabel(); smscbindingfilterbutton = new javax.swing.jbutton(); }// variables declaration - not modify private javax.persistence.entitymanager f1softsmscpuentitymanager; private javax.swing.jbutton bindbutton; private javax.swing.jtable bindingdetailstable; private javax.swing.jbutton blockbuttontobindingdetails; private javax.swing.jtextfield filterbyshortcodetextfield; private javax.swing.jlabel jlabel1; private javax.swing.jpanel jpanel1; private javax.swing.jscrollpane jscrollpane1; private java.util.list<com.f1soft.smsc.entities.serverdetails> serverdetailslist; private javax.swing.jpanel serverdetailspanel; private javax.persistence.query serverdetailsquery; private javax.swing.jpanel smscbindingdetailsfilterpanel; private javax.swing.jbutton smscbindingfilterbutton; private org.jdesktop.beansbinding.bindinggroup bindinggroup; // end of variables declaration
thanks , willing response possible experts.
here's how pass parameter query:
query q = em.createquery(jpql); q.setparameter("filtershortcode", theparametervalue);
edit:
the above code should placed in listener method, invoked when button clicked. should not placed in initcomponents()
since obviously, when initcomponents()
called, user has not filled text , clicked on button yet:
smscbindingfilterbutton.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent e) { string theparametervalue = filterbyshortcodetextfield.gettext(); // todo create , execute query } }
given question, assume you're not familiar @ swing , events in general. advise forget netbeans wysiwyg editor, , practice, simple examples not involving bindings , jpa. follow swing tutorial, , espacially the part events.
Comments
Post a Comment