Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8477679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:32:03+00:00 2026-06-10T18:32:03+00:00

Possible Duplicate: primefaces selectOneMenu doesn’t working when it should my setPropertyActionListener is not setting

  • 0

Possible Duplicate:
primefaces selectOneMenu doesn’t working when it should

my setPropertyActionListener is not setting the corresponding bean property. I need to get the select public after i click the corresponding delete button (cbViewExcluir) which shows a confirm dialog before delete. Below is my xhtml:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:p="http://primefaces.org/ui"
            template="./../../resources/templates/baseTemplate.xhtml">

<ui:define name="content">
    <f:view id="vRoot">
        <p:fieldset legend="Manage publics">
            <h:form id="frmPublics">

                <!-- Global messages -->
                <p:growl id="gMessages" sticky="false" globalOnly="true" />

                <!-- Public list on dataTable -->
                <p:dataTable id="dtPublics" 
                             value="#{publicBean.lstPublics}"
                             paginator="true" rows="5" 
                             rowsPerPageTemplate="5,10"
                             paginatorPosition="bottom"
                             paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                             var="actual">

                    <f:facet name="header">
                        <p:commandButton id="cbViewNew" value="New" type="button"  onclick="dlgNew.show();" />
                    </f:facet>
                    <!-- Colunas de edição e exclusão -->
                    <p:column>
                        <f:facet name="header">
                            <h:outputLabel value="Edit"/>
                        </f:facet>
                        <p:commandButton id="cbViewEdit"  
                                         image="ui-icon-pencil" 
                                         title="Edit"
                                         update=":frmEdit:pEditPublic"
                                         oncomplete="dlgEdit.show();">
                            <f:setPropertyActionListener value="#{actual}" target="#{publicBean.selectedPublic}" />
                        </p:commandButton>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputLabel value="Delete"/>
                        </f:facet>
                        <p:commandButton id="cbViewDelete" onclick="dlgDelete.show();" 
                                         icon="ui-icon-close" title="Delete">
                            <f:setPropertyActionListener value="#{actual}" target="#{publicBean.selectedPublic}" />
                        </p:commandButton> 
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            Name
                        </f:facet>
                        <h:outputLabel id="olViewPublicName" value="#{actual.publicName}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            Public Type
                        </f:facet>
                        <h:outputLabel id="olViewPublicType" value="#{actual.publicType}"/>
                    </p:column>
                </p:dataTable>
            </h:form>

            <!-- New dialog -->
            <p:dialog id="dlgNewPublic" widgetVar="dlgNew" modal="true" header="New Public"
                      resizable="false">
                <h:form id="frmNew">
                    <p:panel id="pNewPublico">
                        <p:messages id="mNewMessages" redisplay="false" />
                        <p:panelGrid columns="2">
                            <p:outputLabel id="olNewPublicName" value="Name:" for="itNewPublicName"/>
                            <p:inputText id="itNewPublicName" value="#{publicBean.name}" required="true"
                                         requiredMessage="Enter the public name."/>

                            <p:outputLabel id="olNewPublicType" for="somNewPublicType" value="Public type:"/>
                            <p:selectOneMenu id="somNewPublicType" value="#{publicBean.publicType}" effect="fade" 
                                             converter="#{publicBean.converter}" 
                                             required="true" requiredMessage="Enter the public type."
                                             > 
                                <f:selectItem itemLabel="-- Select --" itemValue=""/>
                                <f:selectItems value="#{publicBean.publicTypes}" var="actual" itemLabel="#{actual.label}" itemValue="#{actual}"></f:selectItems>
                            </p:selectOneMenu>
                            <p:commandButton value="Cancel" immediate="true" onclick="dlgNew.hide()"/>
                            <p:commandButton id="cbSaveNew" value="Save" 
                                             actionListener="#{publicBean.save}"
                                             oncomplete="handleSave(xhr, status, args);" 
                                             update=":frmPublics:dtPublics :frmNew :frmPublics:gMessages"
                                             ajax="true"/>
                        </p:panelGrid>
                    </p:panel>
                </h:form>
            </p:dialog>

            <!-- Delete dialog -->
            <p:confirmDialog id="dialogDelete" message="Are you sure?"
                             header="Delete public" severity="alert" 
                             widgetVar="dlgDelete">
                <h:form id="frmDelete">
                    <p:commandButton id="cbDeleteCancel" value="Cancel" onclick="dlgDelete.hide()" type="button" /> 
                    <p:commandButton id="cbDeleteContinue" value="Continue"
                                     update=":frmPublics:dtPublics :frmPublics:gMessages" 
                                     oncomplete="dlgDelete.hide()"
                                     actionListener="#{publicBean.delete}"/>
                </h:form>
            </p:confirmDialog>

            <!-- Edit dialog -->
            <p:dialog id="dialogEdit" widgetVar="dlgEdit" header="Edit public"
                      resizable="false" modal="true">
                <h:form id="frmEdit">
                    <p:panel id="pEditPublic">
                        <p:messages id="mEditMessages" redisplay="false" />
                        <p:panelGrid columns="2">
                            <p:outputLabel id="olEditPublicName" value="Name:" for="itEditPublicName"/>
                            <p:inputText id="itEditPublicName" value="#{publicBean.selectedPublic.publicName}" required="true"
                                         requiredMessage="Enter the public name."/>

                            <p:outputLabel id="olEditPublicType" for="somEditPublicType" value="Public type:"/>
                            <p:selectOneMenu id="somEditPublicType" 
                                             value="#{publicBean.selectedPublic.publicType}" 
                                             effect="fade" 
                                             converter="#{publicBean.converter}" 
                                             required="true" 
                                             requiredMessage="Select a public type."
                                             > 
                                <f:selectItem itemLabel="-- Select --" itemValue=""/>
                                <f:selectItems value="#{publicBean.publicTypes}" 
                                               var="actual" 
                                               itemLabel="#{actual.label}" 
                                               itemValue="#{actual}"></f:selectItems>
                            </p:selectOneMenu>
                            <p:commandButton value="Cancel" immediate="true" onclick="dlgEdit.hide()"/>
                            <p:commandButton id="cbEditSave" value="Save" 
                                             actionListener="#{publicBean.alter}"
                                             oncomplete="dlgEdit.hide();" 
                                             update=":frmPublics :frmEdit"/>
                        </p:panelGrid>
                    </p:panel>
                </h:form>
            </p:dialog>
        </p:fieldset>
    </f:view>

    <!-- Javascript callbacks -->
    <script type="text/javascript">
        function handleSaved(xhr, status, args){
            if(args.saved){
                dlgNew.hide();
            }
        }
        function handleEdited(xhr, status, args){
            if(args.edited){
                dlgEdit.hide();
            }
        }
    </script>
</ui:define>

And my bean is as follows:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/
package br.siseventos.managed;

import br.siseventos.dao.da.PublicoDAO;
import br.siseventos.dao.da.TipoPublicoDAO;
import br.siseventos.model.TbPublico;
import br.siseventos.model.TdTipoPublico;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import org.primefaces.context.RequestContext;

@ManagedBean(name = "publicoBean")
@SessionScoped
public class PublicoBean {

    // Campos
    private TipoPublicoDAO daoTipoPublico = null;
    private PublicoDAO daoPublico = null;

    private String nome;
    private List<SelectItem> lstMenuTipoPublico = new ArrayList<SelectItem>();
    private TdTipoPublico tipoPublicoSelecionado = null;

    private List<TbPublico> lstDataTablePublico = null;
    private TbPublico publicoSelecionado;

    // Util
    private int maximoLinhasTablePublico = 5;
    private boolean mostrarMsg = false;

    // Construtor
    public PublicoBean() {
        // Inicializando as daos
        daoPublico = new PublicoDAO();
        daoTipoPublico = new TipoPublicoDAO();

        // Carregando o datatable de publicos
        lstDataTablePublico = daoPublico.consultarTodos();

        // Carregando o menu de tipos de público
        List<TdTipoPublico> l = getDaoTipoPublico().consultarTodos();
        Iterator<TdTipoPublico> i = l.iterator();
        while (i.hasNext()) {
            TdTipoPublico atual = (TdTipoPublico) i.next();
            lstMenuTipoPublico.add(new SelectItem(atual, atual.getNmeTipoPublico()));
        }
    }

    public TipoPublicoDAO getDaoTipoPublico() {
        return daoTipoPublico;
    }

    public void setDaoTipoPublico(TipoPublicoDAO daoTipoPublico) {
        this.daoTipoPublico = daoTipoPublico;
    }

    public PublicoDAO getDaoPublico() {
        return daoPublico;
    }

    public void setDaoPublico(PublicoDAO daoPublico) {
        this.daoPublico = daoPublico;
    }

    // Getters e Setters
    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public List<SelectItem> getLstMenuTipoPublico() {
        return lstMenuTipoPublico;
    }

    public void setLstMenuTipoPublico(List<SelectItem> lstMenuTipoPublico) {
        this.lstMenuTipoPublico = lstMenuTipoPublico;
    }

    public TdTipoPublico getTipoPublicoSelecionado() {
        return tipoPublicoSelecionado;
    }

    public void setTipoPublicoSelecionado(TdTipoPublico tipoPublicoSelecionado) {
        this.tipoPublicoSelecionado = tipoPublicoSelecionado;
    }

    public List<TbPublico> getLstDataTablePublico() {
        return lstDataTablePublico;
    }

    public void setLstDataTablePublico(List<TbPublico> lstDataTablePublico) {
        this.lstDataTablePublico = lstDataTablePublico;
    }

    public int getMaximoLinhasTablePublico() {
        return maximoLinhasTablePublico;
    }

    public void setMaximoLinhasTablePublico(int maximoLinhasTablePublico) {
        this.maximoLinhasTablePublico = maximoLinhasTablePublico;
    }

    public boolean isMostrarMsg() {
        return mostrarMsg;
    }

    public void setMostrarMsg(boolean mostrarMsg) {
        this.mostrarMsg = mostrarMsg;
    }

    public TbPublico getPublicoSelecionado() {
        return publicoSelecionado;
    }

    public void setPublicoSelecionado(TbPublico publicoSelecionado) {
        this.publicoSelecionado = publicoSelecionado;
    }

    // Actions e listeners
    public void cadastrarPublico(ActionEvent ex) {
        FacesContext contexto = FacesContext.getCurrentInstance();
        FacesMessage msg = new FacesMessage();
        try {
            TbPublico p = new TbPublico();
            p.setNmePublico(getNome());
            p.setTdTipoPublico(getTipoPublicoSelecionado());

            getDaoPublico().incluir(p);

            // Carregar a lista de publicos novamente
            lstDataTablePublico = getDaoPublico().consultarTodos();

            // Mostrando msg de sucesso!
            msg.setSummary("Público cadastrado com sucesso!");
            msg.setSeverity(FacesMessage.SEVERITY_INFO);
            contexto.addMessage(null, msg);

            // Invocando script no cliente
            RequestContext rc = RequestContext.getCurrentInstance();
            rc.addCallbackParam("salvo", true);

        } catch (Exception e) {
            msg.setSummary("Erro ao cadastrar público!");
            msg.setSeverity(FacesMessage.SEVERITY_ERROR);
            contexto.addMessage(null, msg);
        }
    }

    public void excluirPublico(ActionEvent e) {
        FacesMessage msg = new FacesMessage();
        FacesContext contexto = FacesContext.getCurrentInstance();
        // Mostrando msg de sucesso!
        msg.setSummary(publicoSelecionado.getNmePublico());
        msg.setSeverity(FacesMessage.SEVERITY_INFO);
        contexto.addMessage(null, msg);
        /*try {
            // Excluindo o publico selecionado
            daoPublico.excluir(getPublicoSelecionado().getIdtPublico());
        } catch (Exception ex) {
            msg.setSummary("Erro ao cadastrar público!");
            msg.setSeverity(FacesMessage.SEVERITY_ERROR);
            contexto.addMessage(null, msg);
        }*/
    }

    public void alterarPublico() {
        FacesMessage msg = new FacesMessage("Publico alterado!");
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
    // Converters

    public Converter getConversor() {
        return new Converter() {

            @Override
            public Object getAsObject(FacesContext context, UIComponent component, String value) {
                // Transformar string em objeto
                TdTipoPublico r = null;
                try {
                    r = getDaoTipoPublico().consultarPorIdt(Integer.parseInt(value));
                } catch (NumberFormatException e) {
                }


                return r;

            }

            @Override
            public String getAsString(FacesContext context, UIComponent component, Object value) {
                // Transformar objeto em string
                String r = null;
                if (value instanceof TdTipoPublico) {
                    r = ((TdTipoPublico) value).getIdtTipoPublico().toString();
                }
                return r;
            }
        };

    }
}

There is something i’m doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:32:04+00:00Added an answer on June 10, 2026 at 6:32 pm

    its because of the attribute type=”button” which is not firing the actionlistener.
    when you declare this attribute (type=”button”) its not a p:commandButton anymore.
    type=”button” is push button purposes, it does not do any action or submit the form
    try to remove type=”button” attribute. it’d fire the actionlistener.

         <p:commandButton id="cbViewExcluir" 
    
                                         image="ui-icon-circle-close" 
                                         onclick="dlgExcluir.show()" 
                                         title="Excluir"
                                         update=":frmExcluir">
    
                            <!-- This is not working properly -->
                            <f:setPropertyActionListener value="#{atual}" target="#   {publicoBean.publicoSelecionado}" />
                        </p:commandButton> 
    

    lemme know if this helps 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: Get the size of a list in python? I need to be
Possible Duplicate: PHP get all arguments as array? Within a javascript function arguments always
Possible Duplicate: Why is String.Concat not optimized to StringBuilder.Append? One day I was ranting
Possible Duplicate: Turning on camera flash LED in Android? I need to turn on
Possible Duplicate: Unable to get a list of installed Python modules How do I
Possible Duplicate: What is the fastest XML parser in PHP? I still need to
Possible Duplicate: Difference of create Index by using include column or not using Edit:
Possible Duplicate: Javascript window resize event I want to get an event which is
Possible Duplicate: When should I use “using” blocks in C#? A lot of classes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.