This should guide you on how to dynamicaly create p:gridform
1: public static HtmlPanelGrid buildGridForm(XMLElement pg, LazyModel _model, DataSource d, HashMap<String,String> _props, int _userId, int _orgId){
2: setDs(d);
3: FacesContext fc = FacesContext.getCurrentInstance();
4: Application application = fc.getApplication();
5: ExpressionFactory ef = application.getExpressionFactory();
6: ELContext elc = fc.getELContext();
7: HtmlPanelGrid pGrid = new HtmlPanelGrid();
8: boolean embedded = false;
9: String user = pg.getAttribute("user");
10: if(user != null){
11: log.info("Building GRIDFORM.. user=" + user + ",_userId = " + _userId);
12: _props.put(user,"" + _userId + "");
13: }
14: if(_model != null)
15: embedded = true;
16: if(embedded) //if xpandable
17: pGrid.setId("xgf" + pg.getAttribute("key","x") + pg.getAttribute("keyfield","kf").replace("_",""));
18: else
19: pGrid.setId("gf" + pg.getAttribute("key","x") + pg.getAttribute("keyfield","kf").replace("_",""));
20: pGrid.setColumns(Integer.parseInt(pg.getAttribute("columns","4")));
21: pGrid.setTitle(pg.getAttribute("title","NO TITLE"));
22: pGrid.setStyle(pg.getAttribute("style","font-size:11px; text-align:left; padding-right:0px"));
23: pGrid.setStyleClass(pg.getAttribute("styleclass",""));
24: pGrid.setCellpadding(pg.getAttribute("cellpadding","0 px"));
25: pGrid.setCellspacing(pg.getAttribute("cellspacing","5 px"));
26: pGrid.setRendered(Boolean.parseBoolean(pg.getAttribute("visible","true")));
27: LazyModel parentModel = null;
28: boolean isChild = false; //linked to another datatable
29: //boolean isInput = false; //gets input from another datatable
30: //boolean isNested = false; //has nested children table within a table
31: //boolean isNew = Boolean.parseBoolean(pg.getAttribute("new","false"));
32: String link = pg.getAttribute("link","");
33: String input = pg.getAttribute("input","");
34: if(!link.equals("")){ //if a child
35: //log.info("PARENT for FORM link = " + link);
36: DataTable parent = (DataTable)FacesAccessor.getUIComponent("mainForm:dt" + link.split(":")[0] + (link.split(":")[1]).replace("_",""));
37: //log.info("FOUND parent id = " + parent.getId()); //
38: isChild = true;
39: parentModel = (LazyModel)parent.getValue();
40: }
41: else if(!input.equals("")){ //if a child
42: //log.info("PARENT for FORM link = " + link);
43: DataTable parent = (DataTable)FacesAccessor.getUIComponent("mainForm:dt" + input.split(":")[0] + (input.split(":")[1]).replace("_",""));
44: //log.info("FOUND parent id = " + parent.getId()); //
45: //isChild = true;
46: parentModel = (LazyModel)parent.getValue();
47: }
48: //activiti task variables
49: Map<String,Object> tVars = new HashMap<String, Object>();
50: for(XMLElement el : pg.getElements()) {
51: //label first
52: OutputLabel label = new OutputLabel();
53: label.setId("lbl" + pGrid.getId() + "_" + el.getValue());
54: label.setValue(el.getAttribute("title"));
55: pGrid.getChildren().add(label);
56: boolean isInput = false;
57: if(el.getAttribute("input","false").equals("true"))
58: isInput = true;
59: //activiti task variables
60: if(!el.getAttribute("var","").equals("")){
61: //get XML ELEMENTS marked with var="true" and use as Activiti Task Variables
62: tVars.put(el.getAttribute("var"),"");
63: }
64: // if(el.getName().equals("USERFIELD")){
65: // InputText txtUser = new InputText();
66: // txtUser.setId("txt" + pGrid.getId() + "_" + el.getValue());
67: // txtUser.setValue("loggedInUser");
68: // }
69: // else if(el.getName().equals("DEFAULT")){
70: // InputText txtDefault = new InputText();
71: // txtDefault.setId("txt" + pGrid.getId() + "_" + el.getValue());
72: // txtUser.setValue("loggedInUser");
73: // }
74: String defaultVal = el.getAttribute("defaultvalue");
75: if(el.getName().equals("TEXTFIELD")){
76: if(embedded){
77: InputText txt = new InputText();
78: txt.setId("txt" + pGrid.getId() + "_" + el.getValue());
79: txt.setSize(Integer.parseInt(el.getAttribute("w","25")));
80: //ValueExpression embVE = FacesAccessor.createValueExpression(elc, "#{item[" + _model.getDataIndex(el.getValue()) + "]}", String.class);
81: ValueExpression embVE = FacesAccessor.createValueExpression(elc, "#{item[" + _model.getDataIndex(el.getValue()) + "]}", String.class);
82: txt.setValueExpression("value",embVE);
83: txt.addClientBehavior("save", EventsManager.createAjaxBehaviour("inplaceUpdate","@parent"));
84: //txt.addClientBehavior("cancel", EventsManager.createAjaxBehaviour("inPlaceSave","@none"));
85: if(!el.getAttribute("tooltip","").equals(""))
86: txt.setTitle(el.getAttribute("tooltip"));
87: //txt.setValidator();
88: if(!el.getAttribute("requiredmessage","").equals("")){ //if there is a requiredmessage
89: txt.setRequired(true);
90: txt.setRequiredMessage(el.getAttribute("requiredmessage"));
91: }
92: label.setFor("txt" + pGrid.getId() + "_" + el.getValue());
93: Inplace inp = new Inplace();
94: //inp.setLabel(el.getAttribute("title","No Title"));
95: //inp.setValueExpression("label",FacesAccessor.createValueExpression(elc, "#{item[" + _model.getDataIndex(el.getValue()) + "]}", String.class));
96: inp.setValueExpression("label",FacesAccessor.createValueExpression(elc, "#{item[" + _model.getDataIndex(el.getValue()) + "]}", String.class));
97: inp.setEmptyLabel("EMPTY");
98: inp.setEditor(true);
99: inp.setSaveLabel("Save");
100: inp.setCancelLabel("Cancel");
101: inp.setEvent(el.getAttribute("event","click"));
102: inp.setToggleable(true);
103: inp.getChildren().add(txt);
104: pGrid.getChildren().add(inp);
105: }
106: else if(el.getAttribute("inline","false").equals("false")){
107: //log.info("FOUND TEXTFIELD value = " + el.getValue());
108: InputText txt = new InputText();
109: txt.setId("txt" + pGrid.getId() + "_" + el.getValue());
110: txt.setSize(Integer.parseInt(el.getAttribute("w","20")));
111: if (isChild || isInput){ //CORRECTION NEEDED HERE... if isInput i need to use onNewValue event
112: txt.setValueExpression("value",FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + parentModel.getDataIndex(el.getValue()) + "]}", String.class));
113: txt.addClientBehavior("blur", EventsManager.createAjaxBehaviour("onValueChange","@none"));
114: //if isInput look for mechanism to inject the value directly to newDataMap in DashboardBacker
115: }
116: else{ //means new
117: txt.addClientBehavior("blur", EventsManager.createAjaxBehaviour("onNewValue","@none"));
118: if (defaultVal != null){
119: txt.setValue(defaultVal);
120: }
121: }
122: if(!el.getAttribute("tooltip","").equals(""))
123: txt.setTitle(el.getAttribute("tooltip"));
124: //txt.setValidator();
125: if(!el.getAttribute("requiredmessage","").equals("")){ //if there is a requiredmessage
126: txt.setRequired(true);
127: txt.setRequiredMessage(el.getAttribute("requiredmessage"));
128: }
129: label.setFor("txt" + pGrid.getId() + "_" + el.getValue());
130: // attach message component
131: // Message msg = new Message();
132: // msg.setId("msg_" + pGrid.getId() + "_" + el.getValue());
133: // msg.setFor("txt" + pGrid.getId() + "_" + el.getValue());
134: // pGrid.getChildren().add(msg);
135: pGrid.getChildren().add(txt);
136: }
137: else{ //if inline .. this is only usable when EDITING
138: InputText txt = new InputText();
139: txt.setId("txt" + pGrid.getId() + "_" + el.getValue());
140: txt.setSize(Integer.parseInt(el.getAttribute("w","20")));
141: if (isChild || isInput){
142: txt.setValueExpression("value",FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + parentModel.getDataIndex(el.getValue()) + "]}", String.class));
143: txt.addClientBehavior("save", EventsManager.createAjaxBehaviour("inplaceUpdate","@parent"));
144: }
145: //txt.setValidator();
146: if(!el.getAttribute("requiredmessage","").equals("")){ //if there is a requiredmessage
147: txt.setRequired(true);
148: txt.setRequiredMessage(el.getAttribute("requiredmessage"));
149: }
150: label.setFor("txt" + pGrid.getId() + "_" + el.getValue());
151: Inplace inp = new Inplace();
152: //inp.setLabel(el.getAttribute("title","No Title"));
153: inp.setValueExpression("label",FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + parentModel.getDataIndex(el.getValue()) + "]}", String.class));
154: inp.setEmptyLabel("EMPTY");
155: inp.setEditor(Boolean.parseBoolean(el.getAttribute("editorbuttons","false")));
156: inp.setSaveLabel("Save");
157: inp.setCancelLabel("Cancel");
158: inp.setEvent(el.getAttribute("event","click"));
159: inp.setToggleable(true);
160: inp.getChildren().add(txt);
161: pGrid.getChildren().add(inp);
162: }
163: }
164: else if(el.getName().equals("AUTOCOMPLETE")){
165: log.info("FOUND AUTOCOMPLETE");
166: //AutoComplete autoComp = new AutoComplete();
167: //MyAutoComplete autoComp = new MyAutoComplete(); //my implementation
168: AutoComplete autoComp = new AutoComplete();
169: autoComp.setId("ac" + pGrid.getId() + "_" + el.getValue());
170: autoComp.setForceSelection(true);
171: autoComp.setRequired(true);
172: autoComp.setRequiredMessage(el.getAttribute("requiredmessage","Required"));
173: autoComp.setMinQueryLength(Integer.parseInt(el.getAttribute("querylength","3")));
174: autoComp.setMaxlength(Integer.parseInt(el.getAttribute("maxlength","10")));
175: autoComp.setMultiple(Boolean.parseBoolean(el.getAttribute("multiple","false")));
176: autoComp.setQueryDelay(Integer.parseInt(el.getAttribute("delay","500")));
177: //autoComp.setDropdown(true);
178: //autoComp.setConverter(el.getAttribute("converter","org.elegance.primetime.util.DefaultConverter"));
179: //autoComp.setValueChangeListener()
180: //autoComp.setVar("obj");
181: //autoComp.setItemLabel("#{obj.toString()}");
182: //autoComp.setItemValue("#{obj}");
183: //autoComp.setProcess();
184: //autoComp.setValue("testvalue");
185: //autoComp.setLptable(el.getAttribute("lptable"));
186: //autoComp.setLpfield(el.getAttribute("lpfield"));
187: //autoComp.setLpkey(el.getAttribute("lpkey"));
188: //MethodExpression cME = FacesAccessor.createMethodExpression("#{eventManager.onComplete(\"" + autoComp.getValue() + "\",\"" + el.getAttribute("lptable") + "\",\"" + el.getAttribute("lpfield") + "\")}",List.class, String.class);
189: MethodExpression cME = FacesAccessor.createMethodExpression("#{eventManager.onComplete}",List.class, String.class);
190: autoComp.setCompleteMethod(cME);
191: // MethodExpression cVE = FacesAccessor.createMethodActionListener("#{eventManager.onValueChange}",Void.class, String.class);
192: // autoComp.setValueChangeListener(cVE);
193: //ValueExpression colValueExp = FacesAccessor.createValueExpression(elc, "#{imageBean.getImageBytes(\"select " + el.getValue() + " from " + pg.getAttribute("table","table") + " where " + pg.getAttribute("keyfield","kf") + " = ?\")}", DefaultStreamedContent.class);
194: //START TESTING params
195: // UIParameter paramTable = new UIParameter();
196: // UIParameter paramField = new UIParameter();
197: // UIParameter paramKey = new UIParameter();
198: //
199: // paramTable.setName("lptable");
200: // //paramTable.setValue(el.getAttribute("lptable"));
201: // paramTable.setValue("p_entity");
202: //
203: // paramField.setName("lpfield");
204: // paramField.setValue(el.getAttribute("lpfield"));
205: //
206: // paramKey.setName("lpkey");
207: // paramKey.setValue(el.getAttribute("lpkey"));
208: //
209: // autoComp.getChildren().add(paramTable);
210: // autoComp.getChildren().add(paramField);
211: // autoComp.getChildren().add(paramKey);
212: //END TESTING params
213: label.setFor("ac" + pGrid.getId() + "_" + el.getValue());
214: // if (isChild || isInput){ //CORRECTION NEEDED HERE... if isInput i need to use onNewValue event
215: // autoComp.setValueExpression("value",FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + parentModel.getDataIndex(el.getValue()) + "]}", String.class));
216: // autoComp.addClientBehavior("itemSelect", EventsManager.createAjaxBehaviour("onValueChange","@none"));
217: // }
218: // else{
219: // autoComp.addClientBehavior("itemSelect", EventsManager.createAjaxBehaviour("onNewValue","@none"));
220: // }
221: pGrid.getChildren().add(autoComp);
222: }
223: else if(el.getName().equals("TEXTAREA")){
224: InputTextarea txtA = new InputTextarea();
225: txtA.setId("txtA" + pGrid.getId() + "_" + el.getValue());
226: txtA.setLabel("INLINE LABEL");
227: if (isChild || isInput){
228: txtA.setValueExpression("value",FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + parentModel.getDataIndex(el.getValue()) + "]}", String.class));
229: txtA.addClientBehavior("blur", EventsManager.createAjaxBehaviour("onValueChange","@parent"));
230: }
231: else{ //means new
232: txtA.addClientBehavior("blur", EventsManager.createAjaxBehaviour("onNewValue","@form"));
233: //TESTING ROBOT.. WORKS PERFECTLY
234: //txtA.addClientBehavior("focus", EventsManager.createAjaxBehaviour("runRobot","@this"));
235: if (defaultVal != null){
236: txtA.setValue(defaultVal);
237: }
238: }
239: txtA.setRows(Integer.parseInt(el.getAttribute("rows","5")));
240: txtA.setCols(Integer.parseInt(el.getAttribute("cols","25")));
241: //txtA.setRendered(Boolean.parseBoolean(el.getAttribute("visible","true")));
242: label.setFor("txtA" + pGrid.getId() + "_" + el.getValue());
243: pGrid.getChildren().add(txtA);
244: }
245: else if(el.getName().equals("CHECKBOX")){
246: SelectBooleanCheckbox chk = new SelectBooleanCheckbox();
247: chk.setId("chk" + pGrid.getId() + "_" + el.getValue());
248: chk.setLabel("INLINE LABEL");
249: if (isChild || isInput){
250: chk.setValueExpression("value",FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + parentModel.getDataIndex(el.getValue()) + "]}", String.class));
251: chk.addClientBehavior("blur", EventsManager.createAjaxBehaviour("onValueChange","@parent"));
252: }
253: else{ //means new
254: chk.addClientBehavior("blur", EventsManager.createAjaxBehaviour("onNewValue","@form"));
255: //TESTING ROBOT.. WORKS PERFECTLY
256: //txtA.addClientBehavior("focus", EventsManager.createAjaxBehaviour("runRobot","@this"));
257: if (defaultVal != null){
258: chk.setValue(defaultVal);
259: }
260: }
261: label.setFor("chk" + pGrid.getId() + "_" + el.getValue());
262: pGrid.getChildren().add(chk);
263: }
264: else if(el.getName().equals("TEXTDECIMAL")){
265: InputText txtD = new InputText();
266: txtD.setId("txtD" + pGrid.getId() + "_" + el.getValue());
267: txtD.setType("number");
268: txtD.setSize(Integer.parseInt(el.getAttribute("w","20")));
269: txtD.setStyle(el.getAttribute("style","text-align: right"));
270: if(!el.getAttribute("tooltip","").equals(""))
271: txtD.setTitle(el.getAttribute("tooltip"));
272: if (isChild || isInput){
273: txtD.setValueExpression("value",FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + parentModel.getDataIndex(el.getValue()) + "]}", Double.class));
274: txtD.addClientBehavior("blur", EventsManager.createAjaxBehaviour("onValueChange","@form"));
275: }
276: else{ //means new
277: txtD.addClientBehavior("blur", EventsManager.createAjaxBehaviour("onNewValue","@none"));
278: if (defaultVal != null){
279: txtD.setValue(defaultVal);
280: }
281: }
282: if(!el.getAttribute("requiredmessage","").equals("")){ //if there is a requiredmessage
283: txtD.setRequired(true);
284: txtD.setRequiredMessage(el.getAttribute("requiredmessage"));
285: }
286: txtD.setRendered(Boolean.parseBoolean(el.getAttribute("visible","true")));
287: label.setFor("txtD" + pGrid.getId() + "_" + el.getValue());
288: pGrid.getChildren().add(txtD);
289: }
290: else if(el.getName().equals("INPUTMASK")){
291: InputMask txtMask = new InputMask();
292: txtMask.setId("mask" + pGrid.getId() + "_" + el.getValue());
293: txtMask.setSize(Integer.parseInt(el.getAttribute("w","20")));
294: if(!el.getAttribute("style","").equals("")){
295: txtMask.setStyle(el.getAttribute("style"));
296: }
297: if (isChild || isInput){
298: txtMask.setValueExpression("value",FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + parentModel.getDataIndex(el.getValue()) + "]}", String.class));
299: txtMask.addClientBehavior("blur", EventsManager.createAjaxBehaviour("onValueChange","@form"));
300: }
301: else{ //means new
302: txtMask.addClientBehavior("blur", EventsManager.createAjaxBehaviour("onNewValue","@none"));
303: }
304: txtMask.setMask(el.getAttribute("mask",""));
305: label.setFor("mask" + pGrid.getId() + "_" + el.getValue());
306: pGrid.getChildren().add(txtMask);
307: }
308: // else if(el.getName().equals("GMAP")){
309: // log.info("CREATING map");
310: //
311: // GMap map = new GMap();
312: // MapModel model = new DefaultMapModel();
313: //
314: // map.setId("map" + pGrid.getId() + "_" + el.getValue());
315: // map.setWidgetVar(map.getId());
316: // map.setCenter(el.getAttribute("center","41.381542, 2.122893"));
317: // map.setZoom(Integer.parseInt(el.getAttribute("zoom","15")));
318: // map.setType(el.getAttribute("type","hybrid"));
319: // map.setStyle(el.getAttribute("style","width:400px;height:300px"));
320: //
321: // model.addOverlay(new Marker(new LatLng(36.879466, 30.667648), "M1"));
322: // map.setModel(model);
323: //
324: // pGrid.getChildren().add(map);
325: // }
326: else if(el.getName().equals("EDITOR")){ //'component does not implement Behaviour Interface'
327: Editor edt = new Editor();
328: //MethodExpression ee = FacesAccessor.createMethodExpression("#{eventManager.onNewValue}",Void.class, new Class[0]);
329: //edt.setValueChangeListener(ee);
330: edt.setId("edt" + pGrid.getId() + "_" + el.getValue());
331: if (isChild || isInput){
332: edt.setValueExpression("value",FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + parentModel.getDataIndex(el.getValue()) + "]}", String.class));
333: //edt.addClientBehavior("blur", EventsManager.createAjaxBehaviour("onValueChange","@form"));
334: }
335: //else{ //means new
336: //edt.addClientBehavior("blur", EventsManager.createAjaxBehaviour("onNewValue","@form"));
337: //}
338: edt.setWidth(Integer.parseInt(el.getAttribute("width","200")));
339: edt.setHeight(Integer.parseInt(el.getAttribute("heigth","100")));
340: edt.setControls(el.getAttribute("controls","bold italic underline strikethrough"));
341: edt.setRendered(Boolean.parseBoolean(el.getAttribute("visible","true")));
342: label.setFor("edt" + pGrid.getId() + "_" + el.getValue());
343: pGrid.getChildren().add(edt);
344: }
345: else if(el.getName().equals("TEXTDATE")){
346: //log.info("FOUND TEXTDATE value = " + el.getValue());
347: Calendar cal = new Calendar();
348: cal.setId("cal" + pGrid.getId() + "_" + el.getValue());
349: cal.setPattern("yyyy MMM dd");
350: cal.setNavigator(true);
351: //cal.setPages(3);
352: cal.setMode(el.getAttribute("mode","popup")); //button,inline,popup
353: //cal.setShowOn(String here);
354: cal.setYearRange(el.getAttribute("yearrange","1990:2020"));
355: //cal.setTimeOnly(true);
356: //cal.setShowWeek(true); //show week number
357: //cal.setShowButtonPanel(true); //Show TODAY and DONE
358: //cal.setImmediate(false); //process validations logic isexecuted at apply request values phase for this component
359: //cal.setSelectOtherMonths(true);
360: //cal.setShowOtherMonths(true);
361: //pattern="EEE, dd MMM, yyyy" showButtonPanel="true" navigator="true"
362: cal.setSize(Integer.parseInt(el.getAttribute("w","20")));
363: if (isChild || isInput){
364: //Date date = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH).parse(string);
365: //log.info("Trying Java Date Formatter ... " + new SimpleDateFormat("yyyyy MMMMM dd", Locale.ENGLISH).parse(new Date()));
366: cal.setValueExpression("value",FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + parentModel.getDataIndex(el.getValue()) + "]}", Date.class));
367: cal.addClientBehavior("dateSelect", EventsManager.createAjaxBehaviour("onValueChange","@form")); //or change or select
368: }
369: else{ //means new
370: cal.addClientBehavior("dateSelect", EventsManager.createAjaxBehaviour("onNewValue","@none"));
371: if (defaultVal != null){
372: cal.setValue(defaultVal);
373: }
374: }
375: cal.setRendered(Boolean.parseBoolean(el.getAttribute("visible","true")));
376: label.setFor("cal" + pGrid.getId() + "_" + el.getValue());
377: pGrid.getChildren().add(cal);
378: }//end if TEXTDATE
379: else if(el.getName().equals("COMBOLIST")){
380: SelectOneMenu cmblist = new SelectOneMenu();
381: cmblist.setId("cmblist" + pGrid.getId() + "_" + el.getValue());
382: label.setFor("cmblist" + pGrid.getId() + "_" + el.getValue());
383: List<XMLElement> data = el.getElements();
384: List<SelectItem> items = new ArrayList<SelectItem>();
385: for(XMLElement dt : data) {
386: if(dt.getName().equals("DATA")){ //HAS TO BE A DATA
387: items.add(new SelectItem(dt.getAttribute("key","-1"), dt.getValue()));
388: }//end if DATA
389: }
390: UISelectItems selectItems = new UISelectItems();
391: selectItems.setValue(items);
392: selectItems.setId("si" + pGrid.getId() + "_" + el.getValue());
393: cmblist.getChildren().add(selectItems);
394: if (isChild || isInput){
395: //log.info("COMBOLIST parentModel = " + (parentModel==null?"NO PARENT":"OK"));
396: cmblist.setValueExpression("value",FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + parentModel.getDataIndex(el.getValue()) + "]}", Object.class));
397: cmblist.addClientBehavior("change", EventsManager.createAjaxBehaviour("onValueChange","@form"));
398: }
399: else{ //means new
400: cmblist.addClientBehavior("change", EventsManager.createAjaxBehaviour("onNewValue","@none"));
401: }
402: pGrid.getChildren().add(cmblist);
403: }
404: else if (el.getName().equals("COMBOBOX")){
405: SelectOneMenu cmbbox = new SelectOneMenu();
406: cmbbox.setId("cmbbox" + pGrid.getId() + "_" + el.getValue());
407: //if heigtht is defined
408: if(!el.getAttribute("h","").equals("")){
409: cmbbox.setHeight(Integer.parseInt(el.getAttribute("h")));
410: }
411: label.setFor("cmbbox" + pGrid.getId() + "_" + el.getValue());
412: String wheresql = el.getAttribute("wheresql");
413: //the last argument is a 'suggestion/advice' as to the width of the array
414: List<Object[]> cdata = IOService.getListFromResultSet(getDs(), "SELECT " + (el.getAttribute("lpkey",el.getValue())) + "," + el.getAttribute("lpfield") + " FROM " + el.getAttribute("lptable") + (wheresql==null?"":" WHERE " + wheresql));
415: List<SelectItem> items = new ArrayList<SelectItem>();
416: items.add(new SelectItem("-1", "Select"));
417: for(Object[] dt : cdata) {
418: items.add(new SelectItem((Integer)dt[0], (String)dt[1]));
419: }
420: UISelectItems selectItems = new UISelectItems();
421: selectItems.setValue(items);
422: selectItems.setId("si" + pGrid.getId() + "_" + el.getValue());
423: cmbbox.getChildren().add(selectItems);
424: if (isChild || isInput){
425: if(el.getAttribute("input","false").equals("true")){
426: cmbbox.setValueExpression("value",FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + parentModel.getDataIndex(el.getValue()) + "]}", Integer.class));
427: cmbbox.setDisabled(true);
428: }
429: else{
430: cmbbox.setValueExpression("value",FacesAccessor.createValueExpression(elc, "#{eventManager.currentRow[" + parentModel.getDataIndex(el.getValue()) + "]}", Integer.class));
431: cmbbox.addClientBehavior("change", EventsManager.createAjaxBehaviour("onValueChange","@form")); //this may
432: }
433: }
434: else{ //means new
435: cmbbox.addClientBehavior("change", EventsManager.createAjaxBehaviour("onNewValue","@none"));
436: }
437: pGrid.getChildren().add(cmbbox);
438: }
439: else if(el.getName().equals("FIELDSET")){
440: log.info("FOUND FIELDSET id=" + el.getAttribute("id","no id"));
441: Fieldset fs = new Fieldset();
442: fs.setId("fs" + pGrid.getId() + "_" + el.getAttribute("id","k"));
443: fs.setLegend(el.getAttribute("legend","No Legend"));
444: HtmlPanelGrid fGrid = new HtmlPanelGrid();
445: fGrid.setColumns(2);
446: fGrid.setId("fgrid" + fs.getId());
447: for(XMLElement ell : el.getElements()) {
448: if(ell.getName().equals("TEXTFIELD")){
449: log.info("FIELDSET CHILD = " + ell.getName());
450: InputText fTxt = new InputText();
451: fTxt.setLabel("TESTING");
452: fTxt.setValue("TESTING");
453: fGrid.getChildren().add(fTxt);
454: }
455: else if(ell.getName().equals("TEXTAREA")){
456: fGrid.getChildren().add(new InputTextarea());
457: }
458: else if(ell.getName().equals("EDITOR")){
459: fGrid.getChildren().add(new Editor());
460: }
461: }
462: fs.getChildren().add(fGrid);
463: pGrid.getChildren().add(fs);
464: }//end if FIELDSET
465: // else if(el.getName().equals("FEEDREADER")){
466: // log.info("FOUND FEEDREADER title = " + el.getAttribute("title"));
467: //
468: // FeedReader fd = new FeedReader();
469: // fd.setId("fd" + pGrid.getId() + "_" + el.getAttribute("key","k"));
470: // fd.setValue(el.getAttribute("source","http://rss.news.yahoo.com/rss/sports"));
471: // fd.setVar("feed");
472: // fd.setRendered(true);
473: // fd.setSize(Integer.parseInt(el.getAttribute("size","10")));
474: //
475: //
476: // ValueExpression titleVE = FacesAccessor.createValueExpression(elc, "#{feed.title}", Object.class);
477: // ValueExpression contentVE = FacesAccessor.createValueExpression(elc, "#{feed.description.value}", Object.class);
478: //
479: // HtmlOutputText fdTitle = new HtmlOutputText();//(HtmlOutputText)application.createComponent( HtmlOutputText.COMPONENT_TYPE );
480: // fdTitle.setValueExpression("value",titleVE);
481: // //fdTitle.setValue("#{feed.title}");
482: //
483: // HtmlOutputText fdContent = new HtmlOutputText();
484: // fdContent.setValueExpression("value",contentVE);
485: // //fdContent.setValue("#{feed.description.value}");
486: //
487: // UIOutput errorMessage = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);
488: // errorMessage.setValue("Something Went Wrong");
489: //
490: // fd.getChildren().add(fdTitle);
491: // fd.getChildren().add(fdContent);
492: //
493: // fd.getFacets().put("error", errorMessage);
494: //
495: //
496: //
497: // RequestContext reqContext = RequestContext.getCurrentInstance();
498: // reqContext.update("feed");
499: //
500: // pGrid.getChildren().add(fd);
501: //
502: // }//end if FEEDREADER
503: else if(el.getName().equals("IMAGE")){
504: GraphicImage img = new GraphicImage();
505: img.setId("img" + pGrid.getId() + "_" + el.getValue());
506: FileUpload fup = new FileUpload(); //used when noimage present
507: //img.setTitle(el.getAttribute("title","No Title"));
508: img.setHeight(el.getAttribute("h","50"));
509: img.setWidth(el.getAttribute("w","50"));
510: img.setAlt("Photo Here");
511: if (isChild || isInput){
512: log.info("Trying to load image from database");
513: ValueExpression imgValueExp = FacesAccessor.createValueExpression(elc, "#{imageBean.getImageBytes(\"select " + el.getValue() + " from " + pg.getAttribute("table","table") + " where " + pg.getAttribute("keyfield","kf") + " = ?\")}", DefaultStreamedContent.class);
514: UIParameter param = new UIParameter();
515: param.setName("pk");
516: param.setName("148");
517: //param.setValueExpression("value",FacesAccessor.createValueExpression(elc, "#{item[0]}", String.class));
518: img.getChildren().add(param);
519: FacesContext context = FacesContext.getCurrentInstance();
520: if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
521: img.setValue(new DefaultStreamedContent());
522: }
523: else{
524: img.setValueExpression("value", imgValueExp);
525: }
526: img.addClientBehavior("change", EventsManager.createAjaxBehaviour("onValueChange","@form"));
527: }
528: else{ //means new
529: fup.setId("fup" + pGrid.getId() + "_" + el.getValue());
530: fup.setAuto(Boolean.parseBoolean(el.getAttribute("autoupload","false")));
531: fup.setLabel("Choose");
532: //fup.setAllowTypes(el.getAttribute("uploadfilter","/(\.|\/)(gif|jpe?g|png)$/"));
533: //
534: MethodExpression fl = FacesAccessor.createMethodExpression("#{eventManager.handleFileUpload}",Void.class, FileUploadEvent.class);
535: fup.setFileUploadListener(fl);
536: label.setFor("fup" + pGrid.getId() + "_" + el.getValue());
537: // log.info("Trying to load image from file");
538: // try{
539: // //if is child get from db
540: // //File imgFile = new File(el.getAttribute("file","no_file"));
541: //
542: // String missing = "file:///opt/tomcat7/webapps.labs/primetime/resources/images/missing_person.jpg";
543: // File imgFile = new File(new URI(el.getAttribute("file",missing)));
544: // log.info("Can Read ? = " + imgFile.canRead() + " Can Write ? = " + imgFile.canWrite());
545: // log.info("File = " + imgFile.getPath());
546: // StreamedContent strmImg;
547: // FacesContext context = FacesContext.getCurrentInstance();
548: //
549: // log.info("IMAGE phase = " + context.getCurrentPhaseId());
550: //
551: // if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
552: // log.info("at Render Response");
553: // // So, we're rendering the view. Return a stub StreamedContent so that it will generate right URL.
554: // // strmImg = new DefaultStreamedContent();
555: // strmImg = new DefaultStreamedContent(new FileInputStream(missing), el.getAttribute("mimetype","image/jpg") ,"photo");
556: // }
557: // else{
558: // //strmImg = new DefaultStreamedContent(new FileInputStream(imgFile), el.getAttribute("mimetype","image/jpg") ,"photo");
559: // strmImg = new DefaultStreamedContent(new FileInputStream(missing), el.getAttribute("mimetype","image/jpg") ,"photo");
560: // //InputStream stream = this.getClass().getResourceAsStream("barcalogo.jpg");
561: // //image = new DefaultStreamedContent(stream, "image/jpeg");
562: // }
563: // //img.addClientBehavior("change", EventsManager.createAjaxBehaviour("onNewValue","@none"));
564: // log.info("StreamedContent name = " + strmImg.getName() + ", contentType = " + strmImg.getContentType() + ", stream = " + strmImg.getStream());
565: //
566: // //img.setValue(imgFile.getPath());
567: // img.setValue(strmImg.getStream());
568: // // if(strmImg != null)
569: // // img.setValue(strmImg);
570: // // else
571: // // log.severe("strmImg IS NULL");
572: /*
573: }
574: catch(FileNotFoundException e){
575: log.severe("File Not Found : Message = " + e.getMessage());
576: }
577: catch(URISyntaxException ex){
578: log.severe("Invalid URI = " + ex.getMessage());
579: }*/
580: }
581: //pGrid.getChildren().add(img);
582: pGrid.getChildren().add(fup);
583: }//end if IMAGE
584: }
585: //new can be true (default for everyone), rolename(only members with a specified role)
586: if(pg.getAttribute("new","false").equals("true")){
587: //if(isChild == false){ //if its not a child
588: CommandButton btnNew = new CommandButton();
589: btnNew.setId("new_"+pg.getAttribute("table","no_table"));
590: btnNew.setValue("Save");
591: btnNew.setAjax(true);
592: btnNew.setAsync(true);
593: btnNew.setUpdate("@form");
594: // CommandButton btnReset = new CommandButton();
595: // btnReset.setId("reset_"+pg.getAttribute("table","no_table"));
596: // btnReset.setValue("Clear");
597: // btnReset.setTitle("Click to add entry");
598: // btnReset.setType("reset");
599: //
600: //log.info("audit = " + pg.getAttribute("audit","false"));
601: //ButtonActionListener listener = new ButtonActionListener(pg.getAttribute("table","no_table"),_userId, _orgId);
602: ButtonActionListener listener = new ButtonActionListener(pg.getAttribute("table","no_table"),_props);
603: btnNew.addActionListener(listener);
604: if(!pg.getAttribute("input","").equals("")) //if input is needed from a datatable.....
605: listener.setInputField(pg.getAttribute("input").split(":")[1]);
606: // if(!pg.getAttribute("user","").equals(""))
607: // listener.setUserField(pg.getAttribute("user"));
608: //if either audit is true or if we want to relate loggedInUser with the new entry
609: if(pg.getAttribute("audit","false").equals("true") || !pg.getAttribute("user","").equals(""))
610: listener.setAudit(true);
611: if(pg.getAttribute("tenant","false").equals("true"))
612: listener.setTenant(true);
613: if(!pg.getAttribute("activiti","").equals(""))
614: listener.setTaskVars(tVars);
615: /*
616: if(!pg.getAttribute("input","").equals("")) //if input is needed from a datatable.....
617: //btnNew.addActionListener(new ButtonActionListener(pg.getAttribute("input").split(":")[1]));
618: inputField
619: else if(pg.getAttribute("audit","false").equals("true"))
620: btnNew.addActionListener(new ButtonActionListener(_userId));
621: else
622: btnNew.addActionListener(new ButtonActionListener());
623: */
624: //btnNew.addActionListener(EventsManager.getBlistener());
625: //btnNew.setActionExpression(FacesAccessor.createMethodExpression("#{dashboardBacker.onRowSelect}",Void.class, new Class[0]));
626: //item.setActionExpression(expFact.createMethodExpression(elCtx, "#{menuBean.add}", Void.class, new Class[]{Object.class,String.class}));
627: pGrid.getChildren().add(btnNew);
628: //pGrid.getChildren().add(btnReset);
629: }
630: // else{ //UPDATE button needed
631: // @TODO
632: // CommandButton btnUpdate = new CommandButton();
633: // btnNew.setId("update_"+pg.getAttribute("table","no_table"));
634: // btnNew.setValue("Update");
635: // btnNew.setAjax(true);
636: // btnNew.setAsync(true);
637: // //btnNew.setUpdate("@form");
638: // btnNew.setUpdate("@form");
639: // pGrid.getChildren().add(btnUpdate);
640: // }
641: return pGrid;
642: }
No comments:
Post a Comment
Feel free to leave a comment