0

I'm implementing a PrimeFaces picklist in a dialog. Everytime the dialog is shown the contents of the target of the picklist should change depending on a list entry shown before. Before I open the dialog I fill the target of the picklist in ProdukteBean.onEditProdukt(..) with the appropriate values. Unfortunately these target values do not show up in the target container. Here are the relevant code pieces:

list.xhtml:

<p:commandLink id="editButton" update=":dialogForm:editDialogPanel" title="Edit" 
    oncomplete="produktDialog.show();" 
    process="@this" partialSubmit="true"
    action="#{produkteBean.onEditProdukt}">
            <h:outputText value="Bearbeiten" /> 
            <f:setPropertyActionListener value="#{p}" target="#{produkteBean.produkt}" /> 
</p:commandLink>

dialog.xhtml:

<!-- ... -->
<p:dialog id="dialog" header="Produkt-Details" widgetVar="produktDialog" appendToBody="true" showEffect="explode" hideEffect="explode"  modal="true" width="500"> 
<p:messages id="msgs"/> 
        <h:form id="dialogForm"> 
            <!-- ... -->
            <p:pickList id="produkteDatenList" var="proddat" value="#{produkteBean.datenList}"
        itemLabel="#{proddat.bezeichnung}" itemValue="#{proddat}" 
        converter="produktDatConverter"/> 
            <!-- ... -->
        </h:form>
</p:dialog>

ProdukteBean.java:

    @Named("produkteBean")
    @ViewScoped // @SessionScoped // @ViewScoped
    public class ProdukteBean implements Serializable {

        @Inject @Transient private ProdukteService produkteService; 
        @Inject @Transient private DatenService datenService; 

        @Inject()
        private ProdukteDatenBean produkteDatenBean;

        private DualListModel<Dat> datenList = new DualListModel<Dat>();  

        private Dat dat = null;

        public ProdukteBean() {

        }

        @PostConstruct
        private void init() {

            getAll();
        }

        private void getAll() {
            logger.debug("getAll()");
            getAllProdukte();
            getAllDaten();
        }

        private void getAllDaten() {
            logger.debug("getAllDaten()");

            List<Dat> source = new ArrayList<Dat>();
            source.addAll(datenService.list());

            List<Dat> target = new ArrayList<Dat>();
            if (produkt.getDaten() != null) {
                logger.debug("adding " + produkt.getDaten().size() + " daten to produkt " + produkt.getName());
                target.addAll(produkt.getDaten());
            }       

            DualListModel<Dat> datenList = new DualListModel<Dat>();  
            datenList.setSource(source);
            datenList.setTarget(target);
            setDatenList(datenList);
        }

        public List<Produkt> getAllProdukte() {
            logger.debug("getAllProdukte()");
            return produkteService.list();
        }

        public void onEditProdukt() {

            onEditProdukt(null);
        }

        public void onEditProdukt(ActionEvent actionEvent) {

            logger.debug("onEditProdukt: " + ReflectionToStringBuilder.toString(produkt));
            if (produkt != null) {
                setSelectedEinheit(produkt.getEinheit());
                getAllDaten();
            }
            FacesMessage msg = new FacesMessage("Produkt ausgewählt", produkt.getName());  
            FacesContext.getCurrentInstance().addMessage(null, msg);  
        }

        /**
         * @return the einheitList
         */
        public List<Einheit> getEinheitList() {

            if (einheitList == null) {
                einheitList = produkteService.getEinheiten();
            }
            return einheitList;
        }

    }

ProduktDatConverter.java:

@FacesConverter(forClass=Dat.class,value="produktDatConverter")
@ViewScoped
public class ProduktDatConverter implements Converter {

@Inject
@Transient DatenService datenService;

@Transient
protected final Logger logger = Logger.getLogger(getClass().getName());

    // gets never called (of course)
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String str) {
       logger.debug("getAsObject(): " + str);
       return null;
    }

public String getAsString(FacesContext arg0, UIComponent arg1, Object object) {
   if (object instanceof Dat) {
            // logger.debug("   returning id " + String.valueOf(((Dat) object).getId()));
        return Long.toString(((Dat) object).getId());
   }
   return null;
}
}

Any ideas? Many thanks in advance!

dilino
  • 97
  • 1
  • 3
  • 8

2 Answers2

0

You are using @ViewScoped along CDI Managed Bean. Change it to JSF Managed Bean. Better, use CODI instead

Also see:

Community
  • 1
  • 1
Johny T Koshy
  • 3,857
  • 2
  • 23
  • 40
0

I suppose it's converter + injection problem. Please, click here and refer to the BalusC answer. You can also try to replace:

@FacesConverter(forClass=Dat.class,value="produktDatConverter")

@ViewScoped

with

@ManagedBean

@RequestScoped

and call the converter like this: converter="#{produktDatConverter}"

Community
  • 1
  • 1
gadzix90
  • 744
  • 2
  • 13
  • 28
  • Thank you. I tried that and also changed all the `@Named` annotations to `@ManagedBean` and the `@Inject` annotations to `@ManagedProperty` I also double-checked that the backing bean values are in-place and they are. Unfortunately it still doesn't work ... – dilino Jan 26 '13 at 14:16