4 Replies Latest reply on Nov 6, 2007 6:01 AM by Karthik M

    Query on ajax4jsf

    Karthik M Newbie

      Hi,

      I have a custom JSF component which i need to make AJAX aware. But this component would not be mentioned in XHTML, this is generated dynamically. I shall mention in my xhtml only below line?

      <myTag:dynamicControl id="my_id" groupName="#{dynAjaxCtrlBean.groupName}"

      metaData="#{dynAjaxCtrlBean.metaData}" dataObject="#{dynAjaxCtrlBean.myControldata}" />

      This will internally generate componnents and output it in a panel. The number of components I render depends upon my metadata(it?s a list of metadata objetcs) each object will specify the following..

      ü Type of control

      ü The value binding for the value.

      ü Its ajax event , action , oncomplete, rerender

      ?dataObject (list ) provides data for each of the controls..


      Now in my java code I generate the compoenent using?


      UIAjaxInputText input = (UIAjaxInputText) context.getApplication().createComponent("ips.component.AjaxInputText");

      And then set all data from metadata to the input reference and add to container - in this case our panel?

      Now doing this all my A4j scripts are generated but have following issues?

      ü The aja4jsf script declaration is not added by the framework if I generate dynamically?it is added if I directly place tag for UIAjaxInputText in XHTML.

      ü To overcome this I added script manually but now in spite of the a4j script being there and its declaration in place?my AJAX action is not firing?.

      Please advice on any suggestion why this is happening?any help is highly appreciated.

        • 1. Re: Query on ajax4jsf
          Sergei Abragevich Newbie

          Could you post here your application code snippet?

          • 2. Re: Query on ajax4jsf
            Karthik M Newbie

            xhtml
            ______


            <ips:dynamicControl id="karthik_id" groupName="#{dynAjaxCtrlBean.compMD.groupName}"
            metaData="#{dynAjaxCtrlBean.compMD}" dataObject="#{dynAjaxCtrlBean.testDO}" />

            dynAjaxCtrlBean Bean
            ____________________

            package com.manh.ils.ui.test.dynamiccontrol;

            import java.util.ArrayList;
            import java.util.LinkedHashMap;
            import java.util.List;
            import java.util.Map;

            import com.manh.ils.base.dynamic.DynamicControlMetaData;
            import com.manh.ils.base.dynamic.DynamicGroupComponentMetaData;
            import com.manh.ils.base.finitevalue.dynamic.PSControlType;

            public class DynamicAjaxCtrlsTestBean {

            private DynAjaxCtrlsTestDataObject _testDO = null;

            private DynamicGroupComponentMetaData _compMD = null;

            public DynamicAjaxCtrlsTestBean() {
            buildDfltDO();
            buildDfltMD();
            }

            public DynAjaxCtrlsTestDataObject getTestDO() {
            if (_testDO == null) {
            buildDfltDO();
            }

            return _testDO;
            }

            public void setTestDO(DynAjaxCtrlsTestDataObject dataObj) {
            _testDO = dataObj;
            }

            public DynamicGroupComponentMetaData getCompMD() {
            if (_compMD == null) {
            buildDfltMD();
            }

            return _compMD;
            }

            public void setCompMD(DynamicGroupComponentMetaData md) {
            _compMD = md;
            }

            private void buildDfltDO() {
            _testDO = new DynAjaxCtrlsTestDataObject();

            _testDO.setMyAjaxTextBox("AjaxTextBoxValue");
            _testDO.setMyAjaxDropDown("AjaxDropDownValue");
            _testDO.setMyAjaxInputMask("11.11");
            }

            private void buildDfltMD()
            {
            _compMD = new DynamicGroupComponentMetaData();

            _compMD.setGroupName("Group 1");
            _compMD.setId("testAjaxcomp1");
            _compMD.setLocnMap(null);

            List dynControls = new ArrayList();

            //First one, required and disabled
            DynamicControlMetaData dc1 = createMetaData("Field One", "myAjaxTextBox", "AAAAA", "True", "F", PSControlType.AJAX_TEXTBOX,"onmouseover","#{ajaxInputBean.ajaxEventAction1}",null,"destBox",null);

            DynamicControlMetaData dc2_dropDown = createMetaData("Field Two", "myAjaxDropDown", "AAAAA", "True", "F", PSControlType.AJAX_DROPDOWN,"onmouseover","#{ajaxInputBean.ajaxEventAction1}",null,"destBox",null);

            DynamicControlMetaData dc3_inputMask = createMetaData("Field Three", "myAjaxInputMask", "NN.NN", "True", "F", PSControlType.AJAX_INPUTMASK,"onmouseover","#{ajaxInputBean.ajaxEventAction1}",null,"destBox",null);
            dynControls.add(dc1);
            dynControls.add(dc2_dropDown);
            dynControls.add(dc3_inputMask);

            _compMD.setDynamicControls(dynControls);
            }

            private DynamicControlMetaData createMetaData(String label, String ctrlId,
            String mask, String required, String disabled,
            PSControlType ctrlType,String event,String action,String onComplete,String reRender,List ajaxSupportItem) {

            DynamicControlMetaData dynCtrlMD = new DynamicControlMetaData();

            //Defaults
            // Map valMap = new LinkedHashMap();
            // valMap.put("val0", "val0");
            // dynCtrlMD.setControlValueMap(valMap);
            //
            // Object[] defaultArr = { "dflt0" };
            // dynCtrlMD.setDefaultValue(defaultArr);

            //Arguments
            dynCtrlMD.setControlType(ctrlType);
            dynCtrlMD.setControlLabel(label);
            dynCtrlMD.setControlId(ctrlId);
            dynCtrlMD.setMaxLength(mask.length());
            dynCtrlMD.setMask(mask);
            dynCtrlMD.setRequired(required);
            dynCtrlMD.setDisabled(disabled);
            dynCtrlMD.setEvent(event);
            dynCtrlMD.setAction(action);
            dynCtrlMD.setOnComplete(onComplete);
            dynCtrlMD.setReRender(reRender);
            dynCtrlMD.setAjaxSupportItem(ajaxSupportItem);

            return dynCtrlMD;
            }
            }

            Renderer
            _______

            private void createAjaxTextBoxComponent(FacesContext context, UIPanel dynamicControlPanel,
            Object entity, DynamicControlMetaData contrlMeta, UIDynamicControl dynCtrl)
            {
            if(willLogDebug)
            {
            IPSLogger.logDebug(CLASS_NAME + "createAjaxTextBoxComponent-start");
            }

            UIComponent inputComp;
            UIComponent outPutTextComp;
            outPutTextComp = getLocalInstance().createOutputText(
            contrlMeta.getControlLabel(), context);
            dynamicControlPanel.getChildren().add(outPutTextComp);

            //R205 / CR 1414 - if component is tagged as required, add the necessary HTML
            if(contrlMeta.getRequired().equalsIgnoreCase(TRUE))
            {
            dynamicControlPanel.getChildren().add(new HtmlBlock(REQD_BLOCK_STRING));
            }

            //TODO This will need to change to support left-oriented labels.
            addHtmlBreak(dynamicControlPanel);
            // dynamicControlPanel.getChildren().add(addHtmlSpaces(2));

            String value = "";

            if(null != entity)
            {
            Class entityClass = entity.getClass();
            value = getControlValuesFromModel(entity, entityClass, contrlMeta);
            }

            if(willLogDebug)
            {
            IPSLogger.logDebug(CLASS_NAME + "createAjaxTextBoxComponent-value" + value);
            }

            //R205 / CR 1414 -- support disabling individual fields. Disable if set to "true"
            // at field level or at entire component level.
            boolean disableComp = _disabled || contrlMeta.getDisabled().equalsIgnoreCase(TRUE);

            // inputComp = getLocalInstance().createAjaxInputTextLimitSize(value,
            // contrlMeta.getControlId()+dynamicId, context, disableComp,contrlMeta.getEvent(),contrlMeta.getAction(),contrlMeta.getOnComplete(),contrlMeta.getReRender(),contrlMeta.getAjaxSupportItem());

            inputComp = getLocalInstance().createAjaxInputTextLimitSize(value,
            dynamicId, context, disableComp,contrlMeta.getEvent(),contrlMeta.getAction(),contrlMeta.getOnComplete(),contrlMeta.getReRender(),contrlMeta.getAjaxSupportItem());


            //R205 / CR 1414
            applyJSEvents(dynCtrl, inputComp);

            dynamicControlPanel.getChildren().add(inputComp);
            dynamicControlPanel.getChildren().add(addHtmlSpaces(3)); //TODO Make this configurable

            if(willLogDebug)
            {
            IPSLogger.logDebug(CLASS_NAME + "createAjaxTextBoxComponent-end");
            }
            }

            Helper creating component
            ________________________

            public UIComponent createAjaxInputTextLimitSize(String value, String id,
            FacesContext context, boolean isDisabled, String event,
            String action, String onComplete, String reRender,
            List ajaxSupportItem)
            {
            UIAjaxInputText input = (UIAjaxInputText) context.getApplication().createComponent("ips.component.AjaxInputText");
            input.setId(id);

            ValueBinding vb = context.getApplication().createValueBinding("#{ajaxInputBean.textValue}");
            input.setValueBinding("value",vb);
            input.setEvent(event);
            input.setAction(action);
            input.setOnComplete(onComplete);
            input.setReRender(reRender);
            input.setAjaxSupportItem(ajaxSupportItem);


            if(isDisabled)
            {
            input.setOnfocus("this.blur();");
            input
            .setStyle("border-style: solid; border-color:darkgray; color:darkgray; padding: .1em; margin: .1em; border-width: 1px; text-align: left;");
            }
            return input;

            }

            the ajax text box works fine when used in xhtml directly...when renderere dynamically i get a4j not defined..the xhtml whre i place dynamic control has a a4j namespace defined..if you can send me ur mail id i wil send attachments..Thanks..

            • 3. Re: Query on ajax4jsf
              Sergei Abragevich Newbie

              Can you create an issue in our jira with exact steps to reproduce and attach your application in .war file?

              http://jira.jboss.com/jira/browse/RF