jsf - Netbeans CRUD generator: customization and is it efficient for real applications? -


i use netbeans 7.2.1. jsf crud generated code efficient real applications? have created test database , used netbeans crud generator. uses datamodel , paginationhelper instead of lists crud operations. there entity test.java, testfacade.java , testcontroller.java. , jsf files list.xhtml, edit.xhtml, view.xhtml, create.xhtml. added nemdquery entity file:

@entity @namedquery(name = "test.findbytestcriteria", query = "select t test t t.testcriteria = true") public class test implements serializable {     private static final long serialversionuid = 1l;     @id     @generatedvalue         @column(name = "id")     private integer id;         @column(name = "title")     private string title;     @column(name = "testcrieteria")     private boolean testcrieteria;   public test() { }  //getters , setters 

and created query in testfacade.java:

@stateless public class testfacade extends abstractfacade<test> {     @persistencecontext(unitname = "testpu")     private entitymanager em;      @override     protected entitymanager getentitymanager() {     return em; }  public testfacade() {     super(test.class); }  public list<test> testcriteria(){     query q = em.createnamedquery("test.findbytestcriteria",test.class);             return q.getresultlist(); }     } 

and have added method in testcontroller.java retrieve testcriteria query:

@managedbean(name = "testcontroller") @sessionscoped public class testcontroller implements serializable {      private test current;     private datamodel items = null;     private datamodel testcriteria = null;     @ejb     private com.test.testfacade ejbfacade;     private paginationhelper pagination;     private int selecteditemindex;      public test getselected() {     if (current == null) {         current = new test();         selecteditemindex = -1;     }     return current; }  public paginationhelper getpagination() {     if (pagination == null) {         pagination = new paginationhelper(10) {             @override             public int getitemscount() {                 return getfacade().count();             }              @override             public datamodel createpagedatamodel() {                 return new listdatamodel(getfacade().findrange(new int[]{getpagefirstitem(), getpagefirstitem() + getpagesize()}));             }         };     }     return pagination; }  public datamodel getitems() {     if (items == null) {         items = getpagination().createpagedatamodel();     }     return items; } public string preparelist() {     recreatemodel();     return "list"; }  public string prepareview() {     current = (test) getitems().getrowdata();     selecteditemindex = pagination.getpagefirstitem() + getitems().getrowindex();     return "view"; } //getting testcriteria items public datamodel gettestcriteria(){                     if(items == null){         items = getpagination().createpagedatamodel();     }     testcriteria = new listdatamodel(ejbfacade.testcriteria());              return testcriteria;         } //custom view page public string viewtest(){     current = (test) getitems().getrowdata();     selecteditemindex = pagination.getpagefirstitem() + getitems().getrowindex();     return "viewtest?faces-redirect=true"; } //custom viewtestcriteria public string viewtestcriteria(){     current = (test) gettestcriteria ().getrowdata();     selecteditemindex = pagination.getpagefirstitem() + getitems().getrowindex();     return "viewtest?faces-redirect=true"; } 

and retrieving testcriteria in p:datagrid in index.xhtml:

<h:form>                         <p:datagrid value="#{testcontroller.testcriteria()}" var="item" columns="4">                                                             <p:column>                                 <h:panelgrid columns="1">                                                                                                                     <h:commandlink id="viewtestcriteria" value="#{item.title}" action="#{testcontroller.viewtestcriteria()}"/>                                 </h:panelgrid>                             </p:column>                         </p:datagrid>                     </h:form> 

with code testcriteria data there in index.xhtml when click commadnbutton view them show first item. seems in datagrid doesn't selected item. , if refresh list.xhtml contains test data, , coming index.xhtml , pressing commandlink throws norowavailable exception.

i hope have stated question , appreciate guide because new technology.

update: after googling , research 2 days , thinking thought of using <f:setpropertyactionlistener value="#{item.id}" target="#{testcontroller.selected.id}"> , <f:param name="#{testcontroller.selected.id}" value="#{item.id}"> didn't work.

update: far i'm confident no row getting selected data grid returns first row. i'm still not sure how modify viewtestcriteria() set current item , selecteditemindex correctly.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -