1 Reply Latest reply on Aug 5, 2013 2:52 AM by Nicklas Karlsson

    Primefaces commandButton actionListener dose'nt fire the action....

    Hewagalhenage Nayanajith Udaya Kumara Galhenage Newbie

      I am creating a simple application to call a method in a bean through p:dialog. But my p:commandButton in p:dialog dosent fire the action in my bean. can anyone help me with this.?

      this is my xhtml code and java class for this application..



      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:p="http://primefaces.org/ui" xmlns:a4j="http://richfaces.org/a4j">
              <title>Change Properties</title>
          <p:growl id="growl" showDetail="true" life="3000" for="message" />
          <div class="body">
              <p:dialog header="Change color and Image of Button" widgetVar="dlg"
                  showEffect="explode" hideEffect="bounce">
                  <h:outputText value="" />
                  <table style="min-width: 250px; min-height: 0px;">
                          <td style="border: none">Color</td>
                          <td style="border: none"><p:colorPicker
                                  value="#{fileUploadController.color}" /></td>
                          <td style="border: none">Select Background image</td>
                          <td style="border: none"><h:form id="form1">
                                  <p:fileUpload fileUploadListener="#{fileUploadController.upload}"
                                      allowTypes="/(\.|\/)(gif|jpe?g|png)$/" sizeLimit="100000"
                                      description="Select Images" />
                          <td style="border: none"><p:commandButton value="Close"
                                  type="button" onclick="dlg.hide()" /></td>
                          <td style="border: none">
                          <h:form id="form2"></h:form>
                          <p:commandButton id="change"
                                  type="button" value="Change Properties"
                                  actionListener="#{fileUploadController.changeProperties}" ajax="false" />
              <p:dialog header="Change color and Image of Button" widgetVar="dlg1"
                  showEffect="explode" hideEffect="bounce">
                  <h:form id="form">
                      <p:fileUpload fileUploadListener="#{fileUploadController.upload}"
                          allowTypes="/(\.|\/)(gif|jpe?g|png)$/" sizeLimit="100000"
                          description="Select Images" />
              <p:commandButton value="Show" type="button" onclick="dlg.show()" />
              <p:commandButton value="openUpload" type="button"
                  onclick="dlg1.show()" />







      Hear is my java code for above xhtml page

      package com.UploadFile;
      import javax.faces.bean.ManagedBean;
      import javax.faces.bean.ViewScoped;
      import java.io.File;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.io.InputStream;
      import java.io.OutputStream;
      import javax.faces.application.FacesMessage;
      import javax.faces.context.FacesContext;
      import javax.faces.event.ActionEvent;
      import org.primefaces.event.FileUploadEvent;
      public class FileUploadController {
          private String destination = "D:\\tmp\\";
          public String messages;
          public String color;
          public String backgroundImageFilePath;
          public String ImgFilename;
          public void upload(FileUploadEvent event) {
              FacesMessage msg = new FacesMessage("Success! ", event.getFile()
                      .getFileName() + " is uploaded.");
              FacesContext.getCurrentInstance().addMessage(null, msg);
              try {
                  copyFile(event.getFile().getFileName(), event.getFile()
              } catch (IOException e) {
          public void copyFile(String fileName, InputStream in) {
              try {
                  OutputStream out = new FileOutputStream(new File(destination
                          + fileName));
                  int read = 0;
                  byte[] bytes = new byte[1024];
                  while ((read = in.read(bytes)) != -1) {
                      out.write(bytes, 0, read);
                  System.out.println("New file created!");
              } catch (IOException e) {
          public void changeProperties(ActionEvent actionEvent)
              System.out.println("Change properties occures");
          public String getImgFilename() {
              return ImgFilename;
          public void setImgFilename(String imgFilename) {
              ImgFilename = imgFilename;
          public String getBackgroundImageFilePath() {
              return backgroundImageFilePath;
          public void setBackgroundImageFilePath(String backgroundImageFilePath) {
              this.backgroundImageFilePath = backgroundImageFilePath;
          public String getMessages(ActionEvent e) {
              return messages;
          public void setMessages(String messages) {
              this.messages = messages;
          public String getColor() {
              return color;
          public void setColor(String color) {
              this.color = color;

      jboss 7.1

      primefaces 3.4

      jsf 2.0