Links

   Quran Explorer - Interactive Audio Recitations & Translations

Wednesday, September 10, 2014

Programatically creating/initializing Primefaces Datatable with components

Ahoy,

This is for you Mike, and any other interested

This is very raw... (it works by the way).. i will clean it up for public use in a while...

Only look at the relevant part of the entire code...

This method should be part of a utility class (for creating datatables, schedules, gridforms, etc)...





1:   public static DataTable createDataTable(XMLElement pg, DataSource d, int _userId, int _orgId, boolean _superUser) {  
2:            setDs(d);  
3:            FacesContext fc = FacesContext.getCurrentInstance();  
4:            Application application = fc.getApplication();  
5:            ExpressionFactory ef = application.getExpressionFactory();  
6:            ELContext elc = fc.getELContext();  
7:            //Model  
8:            //if its not nested continue  
9:            //LazyModel model = new LazyModel(pg, _userId, _orgId, _superUser);          //original.. works but needs refactoring  
10:            LazyModel model = new LazyModel(getDs(), pg, _userId, _orgId, _superUser);  
11:            //model.setSuperUser(_superUser);  
12:            //if nested  
13:            //LazyModel model = new LazyModel(pg, _userId,);     //update the where in the xml dynamicaly  
14:            //Table  
15:            DataTable table = (DataTable) application.createComponent(DataTable.COMPONENT_TYPE);  
16:            table.setId("dt" + pg.getAttribute("key","x") + pg.getAttribute("keyfield","kf").replace("_",""));  
17:            //log.info("TABLE id = " + table.getId());  
18:            //table.setPrependId(false);  
19:            table.setValue(model);  
20:            table.setVar("item");  
21:            //if nopages is true or if rows is not defined.....  
22:            if(pg.getAttribute("nopages","false").equals("true") || pg.getAttribute("rows","").equals("")){  
23:              table.setPaginator(false);  
24:              }  
25:            else{  
26:              table.setPaginator(true);  
27:              table.setPaginatorPosition("bottom");  
28:              table.setRowsPerPageTemplate("5,10,15");  
29:              table.setPaginatorTemplate("{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}");  
30:              }  
31:            table.setRows(Integer.parseInt(pg.getAttribute("rows","10")));  
32:            table.setLazy(true);  
33:            table.setResizableColumns(true);  
34:            table.setDraggableColumns(true);  
35:            table.setScrollable(false);  
36:            table.setLiveScroll(false);  
37:            //if no editor and toggler.. (USED TO disable rowselection)  
38:            if(pg.getAttribute("updatetable","").equals("") && pg.getAttribute("toggler","false").equals("false") && pg.getAttribute("noselection","false").equals("false")){  
39:              table.setSelectionMode(pg.getAttribute("selectionmode","single"));  
40:              table.setEditable(false);  
41:              }  
42:            //else if (pg.getAttribute("roweditor","false").equals("true")){  
43:            else if(!pg.getAttribute("updatetable","").equals("")){  
44:              table.setSelectionMode(pg.getAttribute("selectionmode","single"));     //testing edit + delete co-existance  
45:              table.setEditable(true);  
46:              }  
47:  //           else if(!pg.getAttribute("contextmenu","").equals("")){  
48:  //            table.setSelectionMode(pg.getAttribute("selectionmode","single"));     //testing edit + delete co-existance  
49:  //            table.setEditable(true);  
50:  //            }  
51:            table.setSelection(model.getSelectedRow());  
52:            table.setTableStyle(pg.getAttribute("tablestyle","font-size:11px;text-align:left;padding-top:0px;padding-bottom:0px;padding-left:0px"));  
53:            table.setRowStyleClass(pg.getAttribute("rowstyleclass","padding:0px 0px 0px 0px;"));  
54:            table.setEmptyMessage(pg.getAttribute("emptymessage","NO DATA TO DISPLAY"));  
55:            LazyModel parentModel = null;  
56:            String link = pg.getAttribute("link","");  
57:            boolean isChild = false;  
58:            if(!link.equals("")){     //if this is a child  
59:               DataTable parent = (DataTable)FacesAccessor.getUIComponent("mainForm:dt" + link.split(":")[0] + (link.split(":")[1]).replace("_",""));  
60:               parentModel = (LazyModel)parent.getValue();  
61:               boolean added = parentModel.addChild(model,parent,table.getId());          //no need to pass the parent  
62:               //boolean added = parentModel.addChild(model, parent.getId());  
63:               isChild = true;  
64:               }  
65:            //if(pg.getAttribute("roweditor","false").equals("false")){  
66:            if(pg.getAttribute("updatetable","").equals("")){     //if no updatetable  
67:              //log.info("NORMAL (un-editable) DATATABLE");  
68:              AjaxBehavior ajaxSelect = new AjaxBehavior();  
69:              MethodExpression se = FacesAccessor.createMethodExpression("#{eventManager.onRowSelect}",Void.class, new Class[0]);  
70:              ajaxSelect.addAjaxBehaviorListener(new AjaxBehaviorListenerImpl(se));  
71:              ajaxSelect.setUpdate("@form");  
72:              table.addClientBehavior("rowSelect", ajaxSelect);  
73:             //table.addClientBehavior("rowSelect", EventsManager.createAjaxBehaviour("onRowSelect","@this")); use this  
74:              }  
75:             //else if(pg.getAttribute("roweditor","false").equals("true")){  
76:            else if(!pg.getAttribute("updatetable","").equals("") && pg.getAttribute("contextmenu","").equals("") ){     //if there is updatetable and no contextmenu  
77:              //log.info("updatetable WITHOUT contextmenu");  
78:               AjaxBehavior ajaxEdit = new AjaxBehavior();  
79:               MethodExpression ee = FacesAccessor.createMethodExpression("#{eventManager.onRowEdit}",Void.class, new Class[0]);  
80:               ajaxEdit.addAjaxBehaviorListener(new AjaxBehaviorListenerImpl(ee));  
81:               ajaxEdit.setUpdate("@this");          //  
82:               table.addClientBehavior("rowEdit", ajaxEdit);  
83:              //table.addClientBehavior("rowEdit", EventsManager.createAjaxBehaviour("onRowEdit","@this")); use this  
84:               }  
85:             //if both updatetable and contextmenu  
86:            else if(!pg.getAttribute("updatetable","").equals("") && !pg.getAttribute("contextmenu","").equals("")){     //if there is both contextmenu and updatetable  
87:              //log.info("BOTH updatetable and contextmenu PRESENT.....");  
88:               AjaxBehavior ajaxEdit = new AjaxBehavior();  
89:               MethodExpression ee = FacesAccessor.createMethodExpression("#{eventManager.onRowEdit}",Void.class, new Class[0]);  
90:               ajaxEdit.addAjaxBehaviorListener(new AjaxBehaviorListenerImpl(ee));  
91:              ajaxEdit.setUpdate("@none");  
92:               table.addClientBehavior("rowEdit", ajaxEdit);//rowEditInit  
93:              AjaxBehavior ajaxSelect = new AjaxBehavior();  
94:              MethodExpression se = FacesAccessor.createMethodExpression("#{eventManager.onRowSelect}",Void.class, new Class[0]);  
95:              ajaxSelect.addAjaxBehaviorListener(new AjaxBehaviorListenerImpl(se));  
96:              //ajaxSelect.setUpdate("@form");          //should be children only  
97:              ajaxSelect.setUpdate("@none");  
98:              //ajaxSelect.setUpdate(model.getChildrenId().toString());          //.. problem is.. by this time the children are not yet created  
99:              //log.info("ajaxSelect update = " + model.getChildrenId().toString());  
100:              //table.handleAttribute("dblClickSelect", new Boolean(true));  
101:              //table.setDblClickSelect(true);          //just to get around this race condition  
102:              table.addClientBehavior("rowSelect", ajaxSelect);  
103:               }  
104:            //this is actualy a summary row implementation  
105:            boolean group = false;  
106:            if(!pg.getAttribute("group","").equals("")){  
107:              group = true;  
108:              //table.setSortBy(parentModel.getDataIndex(pg.getAttribute("groupby")));  
109:              //if(isChild)  
110:              //table.setValueExpression("sortBy",FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + model.getDataIndex(pg.getAttribute("group").split(":")[0]) + "]}", Object.class));  
111:              //table.setSortBy(model.getSelectedRow()[0]);  
112:              table.setValueExpression("sortBy", FacesAccessor.createValueExpression(elc, "#{item[" + model.getDataIndex(model.getGroupCol()) +"]}", Object.class));  
113:              table.setSortOrder("ascending");  
114:              table.addClientBehavior("sort", EventsManager.createAjaxBehaviour("onSort","@none"));  
115:              }  
116:            //Global Search (still in alpha testing)  
117:            if(pg.getAttribute("search","").equals("all")){  
118:              //table.setStyleClass(".ui-datatable .ui-datatable-header-search");  
119:              OutputPanel outPanel = new OutputPanel();  
120:              outPanel.setId("searchpanel_" + pg.getAttribute("table","no_table"));  
121:              //HtmlOutputText oText = new HtmlOutputText();  
122:              //oText.setValue("Search All Fields: ");  
123:              InputText sText = new InputText();  
124:              sText.setId("filterText");  
125:              sText.setStyle("width:150px");  
126:              //we may need p:defaultcommand instead of using the blur event..  
127:              //...or a search button that receives the table model search text and table id  
128:              sText.addClientBehavior("blur", EventsManager.createAjaxBehaviour("updateFTSSearchQuery",table.getId()));  
129:              //sText.addClientBehavior("keyup", EventsManager.createAjaxBehaviour("updateFTSSearchQuery",table.getId()));  
130:              CommandButton btnDTSearch = new CommandButton();  
131:              btnDTSearch.setId("search_" + pg.getAttribute("table","no_table"));  
132:              btnDTSearch.setValue("Search");  
133:              btnDTSearch.setAjax(true);  
134:              //btnDTSearch.setAsync(true);  
135:              btnDTSearch.setUpdate(table.getId());  
136:              btnDTSearch.addActionListener(new ButtonActionListener(model));          //search text, model  
137:              DefaultCommand dfCommand = new DefaultCommand();  
138:              dfCommand.setId("dfCommand_" + pg.getAttribute("table","no_table"));  
139:              dfCommand.setTarget(btnDTSearch.getId());  
140:              //dfCommand.setContext(outPanel.getId());          //id of parent  
141:              //outPanel.getChildren().add(oText);  
142:              outPanel.getChildren().add(sText);  
143:              outPanel.getChildren().add(btnDTSearch);  
144:              table.getFacets().put("header", outPanel);  
145:              }  
146:            if(!pg.getAttribute("header","").equals("")){  
147:              UIOutput tableTitle = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);  
148:              //tableTitle.setValue("Table Title");  
149:              tableTitle.setValue(pg.getAttribute("header"));  
150:              table.getFacets().put("header", tableTitle);  
151:              }  
152:            else if(isChild){     //it means we want a header here  
153:              try{  
154:                 UIOutput tableTitle = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);  
155:                 tableTitle.setValueExpression("value",FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + parentModel.getDataIndex(link.split(":")[2]) + "]}", String.class));  
156:                 //tableTitle.setStyle("font-color:blue");  
157:                 table.getFacets().put("header", tableTitle);  
158:                 }  
159:              catch(ArrayIndexOutOfBoundsException e){  
160:                 log.severe("Unable to set Child Header " + e.getMessage());  
161:                 }  
162:              }  
163:            //TABLE FOOTER  
164:            if(!pg.getAttribute("footer","").equals("")){  
165:               UIOutput tableFooter = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);  
166:               tableFooter.setValue(pg.getAttribute("footer"));  
167:               table.getFacets().put("footer", tableFooter);  
168:               }  
169:            if(pg.getAttribute("toggler","false").equals("true")){  
170:                 Column tcol = (Column) application.createComponent(Column.COMPONENT_TYPE);  
171:                 tcol.setId("t_col_" + pg.getAttribute("key"));  
172:                 RowToggler rt = new RowToggler();  
173:                 rt.setId("rt_id_" + pg.getAttribute("key"));  
174:                 rt.setRendered(true);  
175:                 tcol.getChildren().add(rt);  
176:                 table.getChildren().add(tcol);  
177:               }  
178:            int colIndex = 0;  
179:            for(XMLElement el : pg.getElements()) {  
180:              Column col = (Column) application.createComponent(Column.COMPONENT_TYPE);  
181:              //need to set id based on type of element.. especialy to facilitate report facility  
182:              if(el.getName().equals("JASPER"))  
183:                 col.setId("col_report" + colIndex + "_" + pg.getAttribute("key"));  
184:              else  
185:                 col.setId("col_" + el.getValue() + "_" + pg.getAttribute("key"));  
186:              if(!el.getAttribute("style","").equals("")){  
187:               col.setStyle(el.getAttribute("style"));  
188:               }  
189:               //buttons need to be added to the parent panel not to the datatable itself  
190:                if(el.getName().equals("ACTIONS")){  
191:                   //log.info("FOUND ACTIONS");  
192:                   col.setSelectionMode(pg.getAttribute("selectionmode","single"));  
193:                  table.setSelectionMode(null);  
194:                   table.getChildren().add(col);  
195:                 AjaxBehavior ajaxSelect = new AjaxBehavior();  
196:                 MethodExpression se = FacesAccessor.createMethodExpression("#{eventManager.onRowSelect}",Void.class, new Class[0]);  
197:                 ajaxSelect.addAjaxBehaviorListener(new AjaxBehaviorListenerImpl(se));  
198:                 ajaxSelect.setUpdate("@none");  
199:                 table.addClientBehavior("rowSelectRadio", ajaxSelect);  
200:                   continue;          //TO NEXT ITERATION  
201:                   }  
202:               if(el.getAttribute("selectionmode","").equals("multiple")){  
203:                   //log.info("FOUND ACTIONS");  
204:                   col.setSelectionMode("multiple");  
205:                  table.setSelectionMode(null);  
206:                 table.setSelection(model.getSelectedRows());  
207:                   table.getChildren().add(col);  
208:                  AjaxBehavior ajaxSelect = new AjaxBehavior();  
209:                  MethodExpression se = FacesAccessor.createMethodExpression("#{eventManager.onMultipleSelect}",Void.class, new Class[0]);  
210:                  ajaxSelect.addAjaxBehaviorListener(new AjaxBehaviorListenerImpl(se));  
211:                  ajaxSelect.setUpdate("@none");  
212:                  table.addClientBehavior("rowSelectCheckbox", ajaxSelect);  
213:  //                AjaxBehavior ajaxUnSelect = new AjaxBehavior();  
214:  //                MethodExpression ume = FacesAccessor.createMethodExpression("#{eventManager.onRowUnSelect}",Void.class, new Class[0]);  
215:  //                ajaxUnSelect.addAjaxBehaviorListener(new AjaxBehaviorListenerImpl(ume));  
216:  //                ajaxUnSelect.setUpdate("@none");  
217:  //                table.addClientBehavior("rowUnSelectCheckbox", ajaxUnSelect);  
218:                 //rowUnselectcheckbox  
219:                   //continue;          //TO NEXT ITERATION  
220:                   }  
221:              col.setValueExpression("sortBy", FacesAccessor.createValueExpression(elc, "#{item[" + colIndex + "]}", Object.class));  
222:              UIOutput colTitle = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);  
223:              colTitle.setValue(el.getAttribute("title","No Title"));  
224:              col.getFacets().put("header", colTitle);  
225:              //if footer present  
226:              if(!el.getAttribute("footer","").equals("")){  
227:                 UIOutput colFooter = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);  
228:                 colFooter.setValue(el.getAttribute("footer"));  
229:                 col.getFacets().put("footer", colFooter);  
230:                 }  
231:              //search  
232:              if(!el.getAttribute("filtermode","").equals("")){  
233:                  col.setValueExpression("filterBy", FacesAccessor.createValueExpression(elc, "#{item[" + colIndex + "]}", Object.class));  
234:                  col.setFilterMatchMode(el.getAttribute("filtermode","contains"));  
235:                 }  
236:              //col.getFacets().put("footer", colTitle);  
237:              if(pg.getAttribute("subtables","").equals("")){  
238:                 table.getChildren().add(col);  
239:                 }  
240:  /*  
241:              else{  
242:                 log.info("SUBTABLE FOUND");  
243:                 SubTable stable = new SubTable();  
244:                 UIOutput subTitle = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);  
245:                 //subTitle.setValueExpression("value",FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + parentModel.getDataIndex(pg.getAttribute("subtables")) + "]}", String.class));  
246:                 subTitle.setValue("Sub Header");  
247:                 stable.getFacets().put("header", subTitle);  
248:                 stable.setVar(table.getVar());  
249:                 stable.setValue(table.getValue());  
250:                 stable.getChildren().add(col);  
251:                 table.getChildren().add(stable);  
252:                 }*/  
253:              // Create <h:outputText value="#{dataItem.id}"> for the body of the column.  
254:              if(el.getName().equals("TEXTFIELD")){  
255:                 if(el.getAttribute("edit","false").equals("true")){  
256:                      //log.info("Found EDITABLE field: " + el.getAttribute("title"));  
257:                      CellEditor ce = new CellEditor();  
258:                      ValueExpression colValueExp = FacesAccessor.createValueExpression(elc, "#{item[" + colIndex + "]}", Object.class);  
259:                      HtmlOutputText colOutput = new HtmlOutputText();//(HtmlOutputText)application.createComponent( HtmlOutputText.COMPONENT_TYPE );  
260:                      InputText colInput = new InputText();//(InputText)application.createComponent(InputText.COMPONENT_TYPE);  
261:                      //colInput.setSize(Integer.parseInt(el.getAttribute("w","20")));  
262:                      if(!el.getAttribute("style","").equals("")){  
263:                           colInput.setStyle(el.getAttribute("style"));  
264:                           colOutput.setStyle(el.getAttribute("style"));  
265:                           }  
266:                      colInput.setValueExpression("value", colValueExp);  
267:                      colOutput.setValueExpression("value", colValueExp);  
268:                      ce.getFacets().put("output", colOutput);  
269:                      ce.getFacets().put("input", colInput);  
270:                      col.getChildren().add(ce);  
271:                      }  
272:                 else{          //normal processing  
273:                    ValueExpression colValueExp = FacesAccessor.createValueExpression(elc, "#{item[" + colIndex + "]}", Object.class);  
274:                    HtmlOutputText colOutput = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);  
275:                    colOutput.setValueExpression("value", colValueExp);  
276:                    //colOutput.setSize(Integer.parseInt(el.getAttribute("w","20")));  
277:                    if(!el.getAttribute("style","").equals(""))  
278:                           colOutput.setStyle(el.getAttribute("style"));  
279:                    col.getChildren().add(colOutput);  
280:                    }  
281:                 }  
282:              else if(el.getName().equals("TEXTDECIMAL")){  
283:                 col.setStyle(el.getAttribute("style","text-align:right"));  
284:                 if(el.getAttribute("edit","false").equals("true")){  
285:                      CellEditor ce = new CellEditor();  
286:                      ValueExpression colValueExp = FacesAccessor.createValueExpression(elc, "#{item[" + colIndex + "]}", Object.class);  
287:                      HtmlOutputText colOutput = new HtmlOutputText();//(HtmlOutputText)application.createComponent( HtmlOutputText.COMPONENT_TYPE );  
288:                      InputText colInput = new InputText();//(InputText)application.createComponent(InputText.COMPONENT_TYPE);  
289:                      if(!el.getAttribute("style","").equals(""))  
290:                           colInput.setStyle(el.getAttribute("style"));  
291:                      colInput.setValueExpression("value", colValueExp);  
292:                      colOutput.setValueExpression("value", colValueExp);  
293:                      ce.getFacets().put("output", colOutput);  
294:                      ce.getFacets().put("input", colInput);  
295:                      col.getChildren().add(ce);  
296:                      }  
297:                   else{  
298:                      ValueExpression colValueExp = FacesAccessor.createValueExpression(elc, "#{item[" + colIndex + "]}", Object.class);  
299:                      HtmlOutputText colOutput = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);  
300:                      colOutput.setValueExpression("value", colValueExp);  
301:                      //thousands separator using regex (make sure there are no more than two(2) decimal places  
302:                      //x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");  
303:                      col.getChildren().add(colOutput);  
304:                      }  
305:                   }  
306:                 else if(el.getName().equals("TEXTDATE")){  
307:                    if(el.getAttribute("edit","false").equals("true")){  
308:                         CellEditor ce = new CellEditor();  
309:                         ValueExpression colValueExp = FacesAccessor.createValueExpression(elc, "#{item[" + colIndex + "]}", Object.class);  
310:                         HtmlOutputText colOutput = new HtmlOutputText();//(HtmlOutputText)application.createComponent( HtmlOutputText.COMPONENT_TYPE );  
311:                         Calendar colInput = new Calendar();  
312:                         colInput.setPattern("yyyy MMM dd");  
313:                         colInput.setShowButtonPanel(true);  
314:                         colInput.setNavigator(true);  
315:                         if(!el.getAttribute("style","").equals("")){  
316:                            colInput.setStyle(el.getAttribute("style"));  
317:                            colOutput.setStyle(el.getAttribute("style"));  
318:                            }  
319:                         colInput.setValueExpression("value", colValueExp);  
320:                         colOutput.setValueExpression("value", colValueExp);  
321:                         ce.getFacets().put("output", colOutput);  
322:                         ce.getFacets().put("input", colInput);  
323:                         col.getChildren().add(ce);  
324:                         }  
325:                      else{  
326:                         ValueExpression colValueExp = FacesAccessor.createValueExpression(elc, "#{item[" + colIndex + "]}", Object.class);  
327:                         HtmlOutputText colOutput = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);  
328:                         colOutput.setValueExpression("value", colValueExp);  
329:                         if(!el.getAttribute("style","").equals("")){  
330:                            colOutput.setStyle(el.getAttribute("style"));  
331:                            }  
332:                         col.getChildren().add(colOutput);  
333:                         }  
334:                   }  
335:               else if(el.getName().equals("COMBOBOX")){  
336:                      //A COMBOBOX in a DataTable is always editable (otherwise just use TEXTFIELD)  
337:                      //log.info("Found EDITABLE field: " + el.getAttribute("title"));  
338:                      CellEditor ce = new CellEditor();  
339:                      SelectOneMenu cmbbox = new SelectOneMenu();  
340:                      cmbbox.setId("cmbbox" + "_" + el.getValue());  
341:                      String wheresql = el.getAttribute("wheresql");  
342:                      List<Object[]> cdata = IOService.getListFromResultSet(getDs(), "SELECT " + (el.getAttribute("lpkey",el.getValue())) + "," + el.getAttribute("lpfield") + " FROM " + el.getAttribute("lptable") + (wheresql==null?"":" WHERE " + wheresql));  
343:                      List<SelectItem> items = new ArrayList<SelectItem>();  
344:                      for(Object[] dt : cdata) {  
345:                           items.add(new SelectItem(dt[0], (String)dt[1]));  
346:                             }  
347:                      UISelectItems selectItems = new UISelectItems();  
348:                      selectItems.setValue(items);  
349:                      selectItems.setId("si" + "_" + el.getValue());  
350:                      cmbbox.getChildren().add(selectItems);  
351:                      ValueExpression colValueExp = FacesAccessor.createValueExpression(elc, "#{item[" + colIndex + "]}", Object.class);  
352:                      HtmlOutputText colOutput = new HtmlOutputText();//(HtmlOutputText)application.createComponent( HtmlOutputText.COMPONENT_TYPE );  
353:                      SelectOneMenu colInput = cmbbox;  
354:                      if(!el.getAttribute("style","").equals("")){  
355:                           colInput.setStyle(el.getAttribute("style"));  
356:                           colOutput.setStyle(el.getAttribute("style"));  
357:                           }  
358:                      colInput.setValueExpression("value", colValueExp);  
359:                      colOutput.setValueExpression("value", colValueExp);  
360:                      ce.getFacets().put("output", colOutput);  
361:                      ce.getFacets().put("input", colInput);  
362:                      col.getChildren().add(ce);  
363:                      }  
364:               else if(el.getName().equals("COMBOLIST")){  
365:                   if(el.getAttribute("edit","false").equals("true")){  
366:                      //log.info("Found EDITABLE field: " + el.getAttribute("title"));  
367:                      CellEditor ce = new CellEditor();  
368:                      //combolist test  
369:                      SelectOneMenu cmblist = new SelectOneMenu();  
370:                      cmblist.setId("cmblist" + "_" + el.getValue());  
371:                      List<XMLElement> data = el.getElements();  
372:                      List<SelectItem> items = new ArrayList<SelectItem>();  
373:                      for(XMLElement dt : data) {  
374:                             if(dt.getName().equals("DATA")){     //HAS TO BE A DATA  
375:                                items.add(new SelectItem(dt.getAttribute("key","-1"), dt.getValue()));  
376:                               }//end if DATA  
377:                             }  
378:                      UISelectItems selectItems = new UISelectItems();  
379:                      selectItems.setValue(items);  
380:                      selectItems.setId("si" + "_" + el.getValue());  
381:                      cmblist.getChildren().add(selectItems);  
382:                      //end test  
383:                      ValueExpression colValueExp = FacesAccessor.createValueExpression(elc, "#{item[" + colIndex + "]}", Object.class);  
384:                      HtmlOutputText colOutput = new HtmlOutputText();//(HtmlOutputText)application.createComponent( HtmlOutputText.COMPONENT_TYPE );  
385:                      //InputText colInput = new InputText();//(InputText)application.createComponent(InputText.COMPONENT_TYPE);  
386:                      SelectOneMenu colInput = cmblist;  
387:                      colInput.setValueExpression("value", colValueExp);  
388:                      colOutput.setValueExpression("value", colValueExp);  
389:                      //log.info("colInput value=" + colInput.getValue());  
390:                      //log.info("colOutput value=" + colOutput.getValue());  
391:                      ce.getFacets().put("output", colOutput);  
392:                      ce.getFacets().put("input", colInput);  
393:                      col.getChildren().add(ce);  
394:                      }  
395:                 else{          //normal processing  
396:                    ValueExpression colValueExp = FacesAccessor.createValueExpression(elc, "#{item[" + colIndex + "]}", Object.class);  
397:                    HtmlOutputText colOutput = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);  
398:                    colOutput.setValueExpression("value", colValueExp);  
399:                    col.getChildren().add(colOutput);  
400:                    }  
401:                   }  
402:               else if(el.getName().equals("GRIDFORM")){  
403:                   childgrid = el;  
404:                   }  
405:               else if(el.getName().equals("JASPER")){  
406:                   Button jreport = new Button();  
407:                   jreport.setValue("Download");  
408:                    ValueExpression hrefValueExp = FacesAccessor.createValueExpression(elc, "report?jasper=" + el.getAttribute("jasper","jasper") + "&pdfname=" + el.getAttribute("pdfname","Report") + "&filterid=#{item[0]}", String.class);  
409:                   jreport.setValueExpression("href", hrefValueExp);  
410:                   jreport.setTitle(el.getAttribute("tooltip","Click to view"));  
411:                   col.getChildren().add(jreport);  
412:                   }  
413:               else if(el.getName().equals("CHECKBOX")){  
414:                 if(el.getAttribute("edit","false").equals("true")){  
415:                      CellEditor ce = new CellEditor();  
416:                      ValueExpression colValueExp = FacesAccessor.createValueExpression(elc, "#{item[" + colIndex + "]}", Object.class);  
417:                      HtmlOutputText colOutput = new HtmlOutputText();//(HtmlOutputText)application.createComponent( HtmlOutputText.COMPONENT_TYPE );  
418:                      SelectBooleanCheckbox colInput = new SelectBooleanCheckbox();//(InputText)application.createComponent(InputText.COMPONENT_TYPE);  
419:                      colInput.setValueExpression("value", colValueExp);  
420:                      colOutput.setValueExpression("value", colValueExp);  
421:                      ce.getFacets().put("output", colOutput);  
422:                      ce.getFacets().put("input", colInput);  
423:                      col.getChildren().add(ce);  
424:                      }  
425:                   else{  
426:                      ValueExpression colValueExp = FacesAccessor.createValueExpression(elc, "#{item[" + colIndex + "]}", Object.class);  
427:                      HtmlOutputText colOutput = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);  
428:                      colOutput.setValueExpression("value", colValueExp);  
429:                      col.getChildren().add(colOutput);  
430:                      }  
431:                   }  
432:              else if(el.getName().equals("IMAGE")){  
433:                   GraphicImage colOutput = (GraphicImage)application.createComponent(GraphicImage.COMPONENT_TYPE);  
434:                   colOutput.setHeight(el.getAttribute("h","50"));  
435:                   colOutput.setWidth(el.getAttribute("w","50"));  
436:                   colOutput.setAlt("No Photo");  
437:                   ValueExpression colValueExp = FacesAccessor.createValueExpression(elc, "#{imageBean.getImageBytes(\"select " + el.getValue() + " from " + pg.getAttribute("table","table") + " where " + pg.getAttribute("keyfield","kf") + " = ?\")}", DefaultStreamedContent.class);  
438:                   UIParameter param = new UIParameter();  
439:                   param.setName("pk");  
440:                   param.setValueExpression("value",FacesAccessor.createValueExpression(elc, "#{item[0]}", String.class));     //this is OK coz pk is always at index 0  
441:                   //default image in case of missing photo ?  
442:                   UIParameter missing = new UIParameter();  
443:                   missing.setName("missing");  
444:                   missing.setValue("missing1.jpg");  
445:                   colOutput.getChildren().add(param);  
446:                   colOutput.getChildren().add(missing);  
447:                   FacesContext context = FacesContext.getCurrentInstance();  
448:                   if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {  
449:                      log.info("at RENDER RESPONSE");  
450:                      //colOutput.setValue(new DefaultStreamedContent());  
451:                      }  
452:                   else{  
453:                      colOutput.setValueExpression("value", colValueExp);  
454:                      }  
455:                   col.getChildren().add(colOutput);  
456:                  }  
457:              else if(el.getName().equals("DATATABLE")){  
458:                    ValueExpression nestValueExp = FacesAccessor.createValueExpression(elc, el.getAttribute("wheresql") + "= #{item[0]}", String.class);  
459:                   //ValueExpression wVE = FacesAccessor.createValueExpression(elc, "#{item[0]}", String.class);  
460:                   //el.removeAttribute("wheresql")  
461:                   //el.setAttribute("wheresql", (pg.getAttribute("keyfield") + "=5"));  
462:                   //el.setAttribute("wheresql", (innerTable.getAlt() + " " + wVE));  
463:                   //log.info("nesting link: " + el.getAttribute("wheresql"));  
464:                   //NESTED DATATABLEs SEEM technicaly INFEASIBLE !!!!!!!  
465:                   DataTable innerTable = createDataTable(el, getDs(), -1, _orgId, _superUser);  
466:                   innerTable.setValueExpression("emptyMessage",nestValueExp);  
467:                   //log.info("INNER TABLE emptyMessage = " + innerTable.getEmptyMessage());  
468:                   col.getChildren().add(innerTable);  
469:                   }  
470:              colIndex++;  
471:              if(el.getAttribute("visible","true").equals("false"))  
472:                  col.setRendered(false);  
473:              }  
474:            //if(pg.getAttribute("toggler","false").equals("true")){  
475:            if(childgrid != null){  
476:              //log.info("CREATING ROWEXPANSION...");  
477:              RowExpansion expCol = (RowExpansion) application.createComponent(RowExpansion.COMPONENT_TYPE);  
478:              expCol.setId("xpcol" + pg.getAttribute("key"));  
479:              HtmlPanelGrid xGrid = buildGridForm(childgrid,model,getDs(), new HashMap<String,String>(), _userId, _orgId);  
480:              //HtmlPanelGrid xGrid = buildGridForm(childgrid,true);  
481:              expCol.getChildren().add(xGrid);  
482:              table.getChildren().add(expCol);  
483:              }  
484:          //if(pg.getAttribute("roweditor","false").equals("true")){  
485:          if(!pg.getAttribute("updatetable","").equals("")){  
486:              //Testing row editor  
487:              Column rowCol = (Column) application.createComponent(Column.COMPONENT_TYPE);  
488:              RowEditor re = new RowEditor();  
489:              rowCol.getChildren().add(re);  
490:              table.getChildren().add(rowCol);  
491:              }  
492:          if(group){  
493:             SummaryRow sRow = new SummaryRow();  
494:             sRow.setId("sr" + table.getId());  
495:             MethodExpression MESummary = FacesAccessor.createMethodExpression("#{eventManager.summaryRowSum}",String.class, String.class);  
496:             sRow.setListener(MESummary);  
497:             Column col1 = (Column)application.createComponent(Column.COMPONENT_TYPE);  
498:             //col1.setColspan(2);  
499:             col1.setColspan(Integer.parseInt(pg.getAttribute("colspan","2")));  
500:             col1.setStyle("text-align:right");  
501:             HtmlOutputText sumLabel = new HtmlOutputText();     //summary label  
502:             //sumLabel.setValue("Summary");  
503:             sumLabel.setValue(pg.getAttribute("group").split(":")[2]);  
504:             col1.getChildren().add(sumLabel);  
505:             Column col2 = (Column)application.createComponent(Column.COMPONENT_TYPE);  
506:             //ValueExpression valExp = FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + parentModel.getDataIndex(pg.getAttribute("group").split(":")[1]) + "]}", Object.class);  
507:             //ValueExpression valExp = FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + model.getDataIndex(pg.getAttribute("group").split(":")[1]) + "]}", Object.class);  
508:             ValueExpression valExp = FacesAccessor.createValueExpression(elc, "#{eventManager.summary}", Object.class);  
509:             HtmlOutputText sumValue = new HtmlOutputText();  
510:             sumValue.setValueExpression("value", valExp);  
511:             col2.getChildren().add(sumValue);  
512:             //now add the columns to the summary row  
513:             sRow.getChildren().add(col1);  
514:             sRow.getChildren().add(col2);  
515:             table.getChildren().add(sRow);  
516:             }  
517:       return table;  
518:       }  

7 comments:

  1. Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us
    python Training institute in Pune
    python Training institute in Chennai
    python Training institute in Bangalore

    ReplyDelete
  2. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command
    Data Science course in Indira nagar
    Data Science course in marathahalli
    Data Science Interview questions and answers
    Data science training in tambaram
    Data Science course in btm layout
    Data science course in kalyan nagar

    ReplyDelete
  3. This post is so interactive and informative.keep update more information...
    Android Training in Tambaram
    Android Training in Chennai

    ReplyDelete

Feel free to leave a comment