0 Replies Latest reply on May 25, 2018 4:51 AM by atlanticasoft

    Event not being called on my Custom PrimeFaces Component

    atlanticasoft

      I have a problem developing a custom component using PrimeFaces, however it is working properly unless the event associated with it is not being called.

       

       

      Here are the parts of this component for you to analyze:

       

      Component:

      package br.com.test.components;

       

       

       

      import java.io.IOException;

      import javax.faces.component.FacesComponent;

      import javax.faces.component.UIOutput;

      import javax.faces.component.html.HtmlPanelGroup;

      import javax.faces.context.FacesContext;

      import org.primefaces.component.commandbutton.CommandButton;

       

       

       

       

       

      @FacesComponent(value = CustomButton.COMPONENT_TYPE)

      public class CustomButton extends UIOutput

      {

      //

      public static final String COMPONENT_TYPE = "br.com.CustomButton";

      public static final String COMPONENT_FAMILY = COMPONENT_TYPE;

      //

      private HtmlPanelGroup group = null;

      private CommandButton commandButton = null;

      //

      private String someVariable = null;

       

      //

      private enum PropertyKeys

      {

      buttonValue, rendered;

      //

      String toString;

       

       

       

      PropertyKeys(String toString)

      {

      this.toString = toString;

      }

       

       

       

      PropertyKeys()

      {

      }

       

       

       

      public String toString()

      {

      return((this.toString != null) ? this.toString : super.toString());

      }

      }

       

       

       

      //

      public String getButtonValue()

      {

      return (String) getStateHelper().eval(PropertyKeys.buttonValue, null);

      }

       

       

       

      public void setButtonValue(String buttonValue)

      {

      getStateHelper().put(PropertyKeys.buttonValue, buttonValue);

      }

       

       

       

      //

      private void initializeComponents()

      {

      group = new HtmlPanelGroup();

      commandButton = new CommandButton();

      //

      group.setId(this.getId());

      //

      group.setParent(this);

      //

      commandButton.setValue(getButtonValue());

      //

      commandButton.setProcess("@this");

      //

      commandButton.setUpdate("@none");

      //

      commandButton.addActionListener(new MyAction());

      //

      group.getChildren().add(commandButton);

      //

      commandButton.setParent(this);

      }

       

       

       

      //

      @Override

      public boolean isRendered()

      {

      return (Boolean) getStateHelper().eval(PropertyKeys.rendered, true);

      }

       

       

       

      @Override

      public void setRendered(boolean rendered)

      {

      getStateHelper().put(PropertyKeys.rendered, rendered);

      }

       

       

       

      @Override

      public boolean getRendersChildren()

      {

      return true;

      }

       

       

       

      @Override

      public String getFamily()

      {

      return COMPONENT_FAMILY;

      }

       

       

       

      @Override

      public void processDecodes(FacesContext ctx)

      {

      super.processDecodes(ctx);

      //

      group.processDecodes(ctx);

      }

       

       

       

      @Override

      public void decode(FacesContext ctx)

      {

      group.decode(ctx);

      }

       

       

       

      @Override

      public void encodeBegin(FacesContext ctx) throws IOException

      {

      initializeComponents();

      //

      group.encodeBegin(ctx);

      }

       

       

       

      @Override

      public void encodeChildren(FacesContext ctx) throws IOException

      {

      group.encodeChildren(ctx);

      }

       

       

       

      @Override

      public void encodeEnd(FacesContext ctx) throws IOException

      {

      group.encodeEnd(ctx);

      }

       

       

       

      @Override

      public void restoreState(FacesContext ctx, Object state)

      {

      Object[] stateArr = (Object[]) state;

      //

      super.restoreState(ctx, stateArr[0]);

      //

      this.someVariable = (String) stateArr[1];

      //

      this.initializeComponents();

      }

       

       

       

      @Override

      public Object saveState(FacesContext ctx)

      {

      Object[] stateArr = new Object[2];

      //

      stateArr[0] = super.saveState(ctx);

      //

      stateArr[1] = someVariable;

      //

      return stateArr;

      }

      }

       

      Event:

       

      package br.com.test.components;

       

      import javax.faces.event.AbortProcessingException;

      import javax.faces.event.ActionEvent;

      import javax.faces.event.ActionListener;

       

      public class MyAction implements ActionListener

      {

      @Override

      public void processAction(ActionEvent event) throws AbortProcessingException

      {

      System.out.println("Test...");

      }

      }

       

      TagLib:

       

      <tag>

       

      <tag-name>customButton</tag-name>

       

      <component>

       

      <component-type>br.com.CustomButton</component-type>

       

      </component>

       

      <attribute>

       

      <name>buttonValue</name>

       

      <required>true</required>

       

      <type>java.lang.String</type>

       

      </attribute>

       

      </tag>

       

      XHTML:

       

      <test:customButton buttonValue="Test" />

       

      For some reason this event is not called, could anyone help to understand the error?