2 Replies Latest reply on Mar 19, 2009 8:51 AM by repkin

    How Can I Create HtmlAjaxCommandButton (JSF 1.2)

    repkin

      Hi,

      I want to create a command button with java code which makes same job as follow.

      
      <a4j:commandButton id="delete" action="#{controller.delete}" value=" #{msg.delete} ">
       <f:setPropertyActionListener value="#{item.someProperty}" target="#{controller.selected}" />
      </a4j:commandButton>
      
      


      I have created button and it is invoking method but I cant find how can I set a field or pass a value to the method. I have send class list for expectedParamTypes, I have created method with specified param types, but it didnt invoked the method.


      
      HtmlAjaxCommandButton deleteButton = new HtmlAjaxCommandButton();
      deleteButton.setId("deleteCommandButton");
      deleteButton.setReRender("dataTable");
      deleteButton.setOnclick("if(!confirm('"+WebUtils.getMessage("areYouSure")+"')){return false;}else{this.disabled=true;Richfaces.showModalPanel('busyPanel')}");
      deleteButton.setOncomplete("this.disabled=false;Richfaces.hideModalPanel('busyPanel')");
      deleteButton.setIgnoreDupResponses(true);
      deleteButton.setValue(WebUtils.getMessage("delete"));
      
      MethodExpression deleteMethodExpression = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createMethodExpression(
       FacesContext.getCurrentInstance().getELContext(),
       "#{controller.deleteMethod}",
       null, new Class<?>[0]
      );
      deleteButton.setActionExpression(deleteMethodExpression);
      
      


      I will be so thankful if anyone suggest me any solution.

        • 1. Re: How Can I Create HtmlAjaxCommandButton (JSF 1.2)
          nbelaevski

          Hello,

          Action method does not have any arguments.
          Create and add this action listener: com.sun.faces.taglib.jsf_core.SetPropertyActionListenerImpl. Note: this would make your code incompatible with MyFaces!

          • 2. Re: How Can I Create HtmlAjaxCommandButton (JSF 1.2)
            repkin

            Nbelaevski thanks so much, I solve the problem.

            
            HtmlAjaxCommandButton deleteButton = new HtmlAjaxCommandButton();
            deleteButton.setId("deleteButton");
            deleteButton.setReRender("dataTable");
            deleteButton.setOnclick("if(!confirm('"+WebUtils.getMessage("areYouSure")+"')){return false;}else{this.disabled=true;Richfaces.showModalPanel('busyPanel')}");
            deleteButton.setOncomplete("this.disabled=false;Richfaces.hideModalPanel('busyPanel')");
            deleteButton.setIgnoreDupResponses(true);
            deleteButton.setValue(WebUtils.getMessage("delete"));
            
            MethodExpression deleteMethodExpression = expressionFactory.createMethodExpression(
             elContext, "#{controller.delete}", String.class, new Class<?>[0]
            );
            deleteButton.setActionExpression(deleteMethodExpression);
            
            ValueExpression target = expressionFactory.createValueExpression(elContext, "#{controller.selectedItem}", Long.class);
            ValueExpression propertyValue = expressionFactory.createValueExpression(elContext,"#{dataTableVar}", MyWrapper.class);
            SetPropertyActionListenerImpl listener = new SetPropertyActionListenerImpl(target,propertyValue);
            deleteButton.addActionListener(listener);
            
            editDelValueColumn.getChildren().add(deleteButton);