سؤال

I am a bit new to JSF and Primefaces, just studying a book and try learning by doing ;-) Doing this I am hanging with a problem, which I obviously will not solve alone.

The following xhtml code

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <h:head>
        <title>My Testpage</title>
    </h:head>
    <h:body>

        <h:panelGroup>

            <pe:dynaForm id="form_kairos" value="#{kairosController.model}" var="m">

                <pe:dynaFormControl type="input" for="txt">  
                    <p:inputText cols="80" id="txt" value="#{m.value}" required="true"/>  
                </pe:dynaFormControl> 

                <f:facet name="buttonBar">  
                    <p:commandButton value="Submit" 
                                     action="#{kairosController.submitForm}"
                                     style="margin-left: 5px;"/>

                </f:facet>
            </pe:dynaForm>

        </h:panelGroup>

    </h:body>
</html>

shows my input field and a Submit button as expected - fine! But pressing the button does not jump into the submitForm method :o .

My Bean code is as simple as possible (for now) and goes like this:

import de.hlg.kairos.TextInput;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import org.primefaces.extensions.model.dynaform.DynaFormControl;
import org.primefaces.extensions.model.dynaform.DynaFormLabel;
import org.primefaces.extensions.model.dynaform.DynaFormModel;
import org.primefaces.extensions.model.dynaform.DynaFormRow;

@ManagedBean
@SessionScoped
public class KairosController implements Serializable {

    private DynaFormModel model;  
    private TextInput myValue;

    public KairosController() {

        model = new DynaFormModel();  
        myValue = new TextInput("myValue");
        DynaFormRow row = model.createRegularRow();
        DynaFormLabel label11 = row.addLabel("my label", 1, 1);  
        DynaFormControl control12 = row.addControl(myValue, "input", 1, 1);  
        label11.setForControl(control12);  

    }

    public DynaFormModel getModel() {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "getModel()");
        return model;
    }

    public String submitForm() {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "submitForm()");
        return null;
    }
}

I already read some threads talking about nested forms, which seem not to work with commandButton. Others said that an ajax="false" could help for the button, but in my example these hints did not help, so I think there could be something else (maybe something very obvious to someone more experienced :lol: ) wrong with my code.

Unfortunally I must mention, that I see exactly the same behaviour with the PFE showcase, so I cannot compare to something working.

Any suggestions or working examples that make a commandButton work without ajax in a dynaForm component?

Cheers, Joern

هل كانت مفيدة؟

المحلول

I took a closer look at your example and also at the dynamic "form" from the primeface extensions. The dynaForm is not generating a form. It "only" generates a table. So when you try to make the commandButton non-ajax by adding a ajax=false attribute to it the commandButton will complain that no surrounding form exists.

Add a surrounding form element. Then your request should work the way you expect.

<h:form id="mainForm">
    <pe:dynaForm id="form_kairos" value="#{kairosController.model}" var="m">

        <pe:dynaFormControl type="input" for="txt">
        <p:inputText cols="80" id="txt" value="#{m.value}" required="true" />
        </pe:dynaFormControl>

        <f:facet name="buttonBar">
            <p:commandButton id="commandButton" value="Submit" ajax="false"
             actionListener="#{kairosController.submitForm}" style="margin-left: 5px;" />

        </f:facet>
    </pe:dynaForm>
</h:form>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top