From 420c0ab37aae9959b08bb12d0d00c931349075dd Mon Sep 17 00:00:00 2001 From: willemc Date: Wed, 23 Mar 2011 16:59:52 +0100 Subject: [PATCH] added onChange option in jsf frontend --- .../frontends/web/jsf/JSFVascUIComponent.java | 24 +++++++++-- .../web/jsf/JSFVascUIComponentRenderer.java | 40 ++++++++++++++++++- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java b/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java index f054ca1..6398967 100644 --- a/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java +++ b/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java @@ -70,7 +70,8 @@ public class JSFVascUIComponent extends UIComponentBase { public static final String INJECT_TABLE_OPTIONS_ID = "injectTableOptionsId"; public static final String INJECT_TABLE_COLUMNS_ID = "injectTableColumnsId"; public static final String DISABLE_LINK_COLUMNS = "disableLinkColumns"; - + public static final String INJECT_TABLE_OPTIONS_ON_CHANGE = "injectTableOptionOnChange"; + private JSFVascFrontendRenderer renderer = null; private JSFVascEntrySupportBean supportBean = null; private String renderFacetState = null; @@ -80,6 +81,7 @@ public class JSFVascUIComponent extends UIComponentBase { private Object stateEditId = null; private Logger logger = null; private Boolean initClear = null; + private String injectTableOptionOnChange = null; public JSFVascUIComponent() { logger = Logger.getLogger(JSFVascUIComponent.class.getName()); @@ -92,7 +94,7 @@ public class JSFVascUIComponent extends UIComponentBase { @Override public Object saveState(FacesContext facesContext) { logger.fine("Save State"); - Object values[] = new Object[7]; + Object values[] = new Object[8]; values[0] = super.saveState(facesContext); values[1] = this.getAttributes().get(VASC_CONTROLLER_KEY); values[2] = this.getAttributes().get(VASC_FRONTEND_DATA_KEY); @@ -100,6 +102,7 @@ public class JSFVascUIComponent extends UIComponentBase { values[4] = renderer; values[5] = supportBean; values[6] = renderFacetState; + values[7] = this.getAttributes().get(INJECT_TABLE_OPTIONS_ON_CHANGE); return values; } @@ -115,6 +118,7 @@ public class JSFVascUIComponent extends UIComponentBase { renderer = (JSFVascFrontendRenderer) values[4]; supportBean = (JSFVascEntrySupportBean) values[5]; renderFacetState = (String) values[6]; + injectTableOptionOnChange = (String) values[7]; // TODO: check if we can move this some day... String entrySupportVar = (String)getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY); @@ -290,7 +294,21 @@ public class JSFVascUIComponent extends UIComponentBase { public String getRenderFacetState() { return renderFacetState; } - + + /** + * @return the injectTableOptionOnChange + */ + public String getInjectTableOptionOnChange() { + return injectTableOptionOnChange; + } + + /** + * @param injectTableOptionOnChange the injectTableOptionOnChange to set + */ + public void setInjectTableOptionOnChange(String injectTableOptionOnChange) { + this.injectTableOptionOnChange = injectTableOptionOnChange; + } + public VascEntry createClonedVascEntry() { String entryName = null; diff --git a/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java b/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java index 319adb5..9eea442 100644 --- a/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java +++ b/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java @@ -42,11 +42,19 @@ import javax.faces.component.UIColumn; import javax.faces.component.UIComponent; import javax.faces.component.UIInput; import javax.faces.component.UIOutput; +import javax.faces.component.UISelectMany; import javax.faces.component.UIViewRoot; import javax.faces.component.html.HtmlCommandLink; +import javax.faces.component.html.HtmlInputText; +import javax.faces.component.html.HtmlInputTextarea; import javax.faces.component.html.HtmlMessage; import javax.faces.component.html.HtmlOutputText; import javax.faces.component.html.HtmlSelectBooleanCheckbox; +import javax.faces.component.html.HtmlSelectManyListbox; +import javax.faces.component.html.HtmlSelectManyMenu; +import javax.faces.component.html.HtmlSelectOneListbox; +import javax.faces.component.html.HtmlSelectOneMenu; +import javax.faces.component.html.HtmlSelectOneRadio; import javax.faces.context.FacesContext; import javax.faces.context.ResponseWriter; import javax.faces.event.AbortProcessingException; @@ -126,7 +134,7 @@ public class JSFVascUIComponentRenderer extends Renderer { String injectTableColumnsId = (String)comp.getAttributes().get(JSFVascUIComponent.INJECT_TABLE_COLUMNS_ID); UIComponent injectEditFieldsComponent = JSFVascUIComponent.findComponentById(comp.getFacet("editView"),injectEditFieldsId); - UIComponent injectTableOptionsComponent = JSFVascUIComponent.findComponentById(comp.getFacet("listView"),injectTableOptionsId); + UIComponent injectTableOptionsComponent = JSFVascUIComponent.findComponentById(comp.getFacet("listView"),injectTableOptionsId,comp); UIComponent injectTableColumnsComponent = JSFVascUIComponent.findComponentById(comp.getFacet("listView"),injectTableColumnsId); if (injectEditFieldsComponent==null) { throw new NullPointerException("Could not find injectEditFieldsId: "+injectEditFieldsId); @@ -273,7 +281,7 @@ public class JSFVascUIComponentRenderer extends Renderer { } - private void addTableOptions(FacesContext fc,UIComponent grid) throws FacesException, VascException { + private void addTableOptions(FacesContext fc,UIComponent grid,JSFVascUIComponent comp) throws FacesException, VascException { //Application application = fc.getApplication(); //UIViewRoot viewRoot = fc.getViewRoot(); @@ -295,6 +303,34 @@ public class JSFVascUIComponentRenderer extends Renderer { model.setValue(option.getDefaultValue()); UIInput jsfEdit = (UIInput)editor.createComponent(entry,option,model,grid); jsfEdit.addValueChangeListener(new ModelChangeListener(model)); + + if (comp.getInjectTableOptionOnChange()!=null && comp.getInjectTableOptionOnChange().isEmpty()==false) { + if (jsfEdit instanceof HtmlSelectBooleanCheckbox) { + ((HtmlSelectBooleanCheckbox)jsfEdit).setOnchange(comp.getInjectTableOptionOnChange()); + } + if (jsfEdit instanceof HtmlSelectManyMenu) { + ((HtmlSelectManyMenu)jsfEdit).setOnchange(comp.getInjectTableOptionOnChange()); + } + if (jsfEdit instanceof HtmlInputText) { + ((HtmlInputText)jsfEdit).setOnchange(comp.getInjectTableOptionOnChange()); + } + if (jsfEdit instanceof HtmlInputTextarea) { + ((HtmlInputTextarea)jsfEdit).setOnchange(comp.getInjectTableOptionOnChange()); + } + if (jsfEdit instanceof HtmlSelectManyListbox) { + ((HtmlSelectManyListbox)jsfEdit).setOnchange(comp.getInjectTableOptionOnChange()); + } + if (jsfEdit instanceof HtmlSelectOneMenu) { + ((HtmlSelectOneMenu)jsfEdit).setOnchange(comp.getInjectTableOptionOnChange()); + } + if (jsfEdit instanceof HtmlSelectOneRadio) { + ((HtmlSelectOneRadio)jsfEdit).setOnchange(comp.getInjectTableOptionOnChange()); + } + if (jsfEdit instanceof HtmlSelectOneListbox) { + ((HtmlSelectOneListbox)jsfEdit).setOnchange(comp.getInjectTableOptionOnChange()); + } + } + Class clazz = option.getVascEntryFieldType().getAutoDetectClass(); if (clazz!=null && model.getValue()!=null) { if (clazz.equals(model.getValue().getClass())==false) {