0

the problem I have is that the command button in my dialog doesn't fire the action method in the controller. No logger outputs for the example method "greet". Can anybody look over please and give me hints? What am I doing wrong?

My JSF-Page:

<!DOCTYPE HTML>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
    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" xmlns:o="http://omnifaces.org/ui"
    xmlns:of="http://omnifaces.org/functions">

<f:view id="bestellungLieferantView">
    <f:metadata>
        <f:event type="preRenderView"
            listener="#{camundaTaskForm.startTaskForm()}" />
    </f:metadata>
    <h:head>
        <title>Paket zusammenstellen</title>
    </h:head>
    <h:body>
        <h:form id="bestellungLieferantForm">
            <p:dialog id="komponentenAuswahlDialog"
                header="Komponenten auswählen" widgetVar="komponentenAuswahlDialog"
                modal="true" height="auto" width="auto">

                    <p:pickList id="komponenteAuswahlPickList"
                        value="#{bestellungLieferantController.komponentenDualListModel}"
                        var="komponente" itemLabel="#{komponente.serienNummer}"
                        converter="entityConverter"
                        itemValue="#{komponente}" showSourceFilter="true"
                        showTargetFilter="true">
                        <f:facet name="sourceCaption">Quelle</f:facet>
                        <f:facet name="targetCaption">Ziel</f:facet>
                    </p:pickList>

                    <p:commandButton process="@this"
                        action="#{bestellungLieferantController.greet}"
                        id="auswahlSpeichern" value="Auswahl speichern"
                        oncomplete="PF('komponentenAuswahlDialog').hide();" />
            </p:dialog>
            <h:panelGrid id="paketInformationPG" columns="2" border="1">
                <f:facet name="header">
                    <h:outputText value="Paket zusammenstellen" />
                </f:facet>
                <h:outputLabel value="Kunde:" />
                <h:outputText value="#{processVariables['kunde']}" />

                <h:outputLabel value="Betriebssystem:" />
                <h:outputText value="Platzhalter" />

                <h:outputLabel value="Benutzer:" />
                <h:outputText value="#{processVariables['benutzerName']}" />
            </h:panelGrid>
            <h:panelGrid id="komponentenZusammenstellungPG" columns="2"
                border="1">
                <f:facet name="header">
                    <h:panelGrid columns="2">
                        <h:outputText value="Komponenten" />
                        <p:commandButton id="auswahlKomponenteButton"
                            action="#{bestellungLieferantController.createAvailableKomponentDualListModel()}"
                            type="button" onclick="PF('komponentenAuswahlDialog').show();"
                            value="+" />
                    </h:panelGrid>
                </f:facet>
                <p:dataTable id="komponenteTable" widgetVar="komponenteTable"
                    var="komponente"
                    value="#{bestellungLieferantController.komponentenList}">
                    <p:column>
                        <f:facet name="header">Typ</f:facet>
                        <h:outputText value="#{komponente.produkt.typ.name}" />
                    </p:column>

                    <p:column>
                        <f:facet name="header">Bezeichnung</f:facet>
                        <h:outputText value="#{komponente.produkt.name}" />
                    </p:column>

                    <p:column>
                        <f:facet name="header">SN</f:facet>
                        <h:outputText value="#{komponente.serienNummer}" />
                    </p:column>

                    <p:column headerText="Kaufdatum">
                        <f:facet name="header">Kaufdatum</f:facet>
                        <h:outputText value="#{komponente.bestellDatum}" />
                    </p:column>

                    <p:column>
                        <f:facet name="header">Aktion</f:facet>
                        <p:commandLink value="Bearbeiten" />
                        <p:commandLink value="Enfernen" />
                    </p:column>
                </p:dataTable>
            </h:panelGrid>
        </h:form>
    </h:body>
</f:view>
</html>

My Bean:

@ManagedBean(name="bestellungLieferantController")
@SessionScoped
public class BestellungLieferantController implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 2862985625231368306L;

    @EJB
    private BestellungFacade bestellungFacade;

    @EJB
    private PaketFacade paketFacade;

    @EJB
    private KomponenteFacade komponenteFacade;

    @EJB
    private BetriebssystemFacade betriebssystemFacade;

    // Komponent-List with added komponent items
    private List<Komponente> komponentenList = new ArrayList<Komponente>();

    private DualListModel<Komponente> komponentenDualListModel;

    private static final Logger logger = Logger.getLogger(BestellungLieferantController.class);

    public DualListModel<Komponente> getKomponentenDualListModel() {
        return komponentenDualListModel;
    }

    public void setKomponentenDualListModel(DualListModel<Komponente> komponentenDualListModel) {
        this.komponentenDualListModel = komponentenDualListModel;
    }

    public List<Komponente> getKomponentenList() {
        logger.info("KomponenList-Size: " + this.komponentenList.size());
        return komponentenList;
    }

    public void setKomponentenList(List<Komponente> komponentenList) {
        logger.info("Setting a new KomponentenList...");
        this.komponentenList = komponentenList;
    }

    public void greet(){
        logger.info("Greet Method Invoked!");
    }


    /**
     * Gets the actual Model with the distinct source and 
     * @param targetList
     * @return
     */
    @PostConstruct
    public void createAvailableKomponentDualListModel(){
        // Logger

        logger.info("CreateAvailableKomponentDualList invoked!");
        List<Komponente> sourceKomponenteList = this.komponenteFacade.getAllAvailableKomponente();
        List<Komponente> sourceKomponenteDistinctList = new ArrayList<Komponente>();

        if (this.komponentenList.size() != 0){
            for(Komponente k : sourceKomponenteList){
                if (!komponentenList.contains(k)){
                    sourceKomponenteDistinctList.add(k);
                }
            }
        } else {
            sourceKomponenteDistinctList = sourceKomponenteList;
        }


//      komponentenDualListModel.setSource(sourceKomponenteDistinctList);
//      komponentenDualListModel.setTarget(komponentenList);

        this.setKomponentenDualListModel(new DualListModel<Komponente>());
        this.getKomponentenDualListModel().setSource(sourceKomponenteDistinctList);
        this.getKomponentenDualListModel().setTarget(this.komponentenList);
    }

    public void putSelectionIntoKomponenteList(){
        logger.info("PutSelectionIntoKomponentList");
        logger.info("KOMPONENTELIST: " + komponentenDualListModel.getTarget());
        this.komponentenList = this.komponentenDualListModel.getTarget();
    }
}

My Converter:

@FacesConverter(value = "entityConverter")
public class EntityConverter implements Converter {

    // Checking the converter
    private static final Logger logger = Logger.getLogger(EntityConverter.class);

    private static Map<Object, String> entities = new WeakHashMap<Object, String>();

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object entity) {
        synchronized (entities) {
            logger.info("[Converter] GetAsString: " + ", Class:" +  entity.getClass() + ", Component-ID: " + component.getId());
            if (!entities.containsKey(entity)) {
                String uuid = UUID.randomUUID().toString();
                entities.put(entity, uuid);
                return uuid;
            } else {
                return entities.get(entity);
            }
        }
    }

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String uuid) {
        logger.info("[Converter] GetAsString: " + ", UUID:" +  uuid + ", Component-ID: " + component.getId());
        for (Entry<Object, String> entry : entities.entrySet()) {
            if (entry.getValue().equals(uuid)) {
                return entry.getKey();
            }
        }
        //return uuid;
        return null;
    }
}
LupoZ
  • 191
  • 1
  • 1
  • 12
  • processVariables['kunde'] and #{processVariables['benutzerName']} looking wrong, what you want to do/show there? – lastresort Jan 30 '17 at 13:24
  • Check http://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value and see if you have a related issue – Kukeltje Jan 31 '17 at 08:17
  • @lastresort these are injected beans from the camunda engine... The component value will be mapped... – LupoZ Jan 31 '17 at 10:58

1 Answers1

0

you need actionListener attribute instead of action in your p:commandbutton tag. and Also use @ViewScoped instead of @SessionScoped in your backing bean. and add ajax="false" in p:commandButton

ArgaPK
  • 455
  • 1
  • 9
  • 22
  • It still doesn't work. What is working so far before I posted was that the button is capable to close the window. – LupoZ Jan 30 '17 at 13:16
  • Could it be cause by this thrown in the console? DEBUG validator:386 - Unable to validate expression #{processVariables['pcVorhanden']} using Bean Validation. Expression evaluates to a Map, List or array. – LupoZ Jan 30 '17 at 13:21
  • yeah, so first remove the validation and try the p:commmandButton working with actionListener attribute. – ArgaPK Jan 30 '17 at 13:25
  • And for Client Side validation , learn from here: http://www.primefaces.org/showcase/ui/csv/basic.xhtml – ArgaPK Jan 30 '17 at 13:33
  • Why would this be a solution? I cannot find any reason why it would – Kukeltje Jan 30 '17 at 17:35
  • @Kukeltje First of all, tell me did my answer is accepted by Lupoz?? Definitely Not. Secondly, tell me, Why would you downvote the answer if you don't understand the question and ask Lupoz to http://stackoverflow.com/help/mcve ; Third, I asked him ,did he solved the problem or get any solution??well i am still waiting for his response. – ArgaPK Jan 30 '17 at 18:07
  • **I** do understand the question. And **I** do understand that blatantly increasing the scope from view to session is **not** a good solution (at most a bad workaround) and **I** do understand that it should work with action to... and **I** do understand that an explantion on why this is **the** solution (that is what I requested from you) would make the answer better **IF** it was the right solution. – Kukeltje Jan 31 '17 at 08:17
  • @Lupoz For bean validation see this http://www.primefaces.org/showcase/ui/csv/bean.xhtml – ArgaPK Jan 31 '17 at 08:26
  • @ArgaPK it's not a primeface issue. I use a BPMN engine called camunda. And there is a bean by definition that I can use which can't get validated... That's could be the reason why it doesn't work.. – LupoZ Jan 31 '17 at 08:27
  • Why wouldn't you are using primefaces bean validation??? Some tips for bean validation http://beanvalidation.org/ – ArgaPK Jan 31 '17 at 08:29
  • @LupoZ did you try p:commandButton with actionListener without bean validation? – ArgaPK Jan 31 '17 at 08:37
  • Yeah I did. Now I solved the error but still no reaction. Only the javascript in the braces is working so the window get closed but the action-Method still can't be called. – LupoZ Jan 31 '17 at 08:53
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/134452/discussion-between-lupoz-and-argapk). – LupoZ Jan 31 '17 at 08:54
  • This answer can never, ever be the solution to the problem described in the question. This is sort of confirmed by the whole discussion in the chat. – Kukeltje Jan 31 '17 at 16:57
  • Chaging the scope has no influence though... Putting the components to be rendered into a container and updating this container was the solution though... – LupoZ Feb 03 '17 at 15:15