0

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

Joern
  • 15
  • 4
  • Does that mean the showcase does not work for you? Then there must be something wrong with your browser? – Jens Jan 03 '13 at 08:58
  • I also blamed my browser (which is latest Firefox) and tried with IE, too, but also no success. Yes, the showcase does not work for me. In detail this means, when I add a breakpoint to the submitForm method (or just add a Logger line as shown above), this line is never reached. The visualization in the browser looks exactly how it should. – Joern Jan 03 '13 at 09:07
  • @Jens: But btw: if the showcase worked for me, then I would have to ask where my code differs from the showcase?! – Joern Jan 03 '13 at 09:08
  • So the showcase basically does work (if it looks the way it is supposed to be). Where do you add the breakpoint? Are you using eclipse? If so are you sure the debugger works correctly? Can you set a breakpoint elsewhere and the debugger stops? – Jens Jan 03 '13 at 09:24
  • I understand the interest of your question and can asure you to use the debugger correctly (being new to JSF, not to java at all ;-). – Joern Jan 03 '13 at 09:32
  • I can set the breakpoint where ever I want into the method, it is never reached. I can successfully set a breakpoint into the getModel Method and debugger stops there. – Joern Jan 03 '13 at 09:34

1 Answers1

0

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>
Jens
  • 6,243
  • 1
  • 49
  • 79
  • Thank you very much, that works. I thought the dynaForm component is a form, but did not check! You really made my day! Thanx! – Joern Jan 03 '13 at 14:20