Starting with DynaForm

Community Driven Extensions Project
Post Reply
RickertJ
Posts: 9
Joined: 02 Jan 2013, 17:08

02 Jan 2013, 17:32

Hi!

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

Code: Select all

<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:

Code: Select all

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 (see http://fractalsoft.net/primeext-showcas ... cUsage.jsf), so I cannot compare to something working.

Any suggestions?

Cheers,
Joern

P.S.: Using PF 3.4.1 with PFE 0.62 and Mojarra 2.1.6, developping under NB 7.2 with Glassfish

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

03 Jan 2013, 14:07

Try to set process="form_kairos" and update="form_kairos" on p:commandButton. You need this, otherwise you can not process the form and will not see any validation errors.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

RickertJ
Posts: 9
Joined: 02 Jan 2013, 17:08

03 Jan 2013, 14:45

I added both parameters, but same result except, that getModel() is called once more now after pressing the submit button!?! :-(

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

03 Jan 2013, 15:43

that getModel() is called once more now after pressing the submit button!?!
Sure, you should cache in the bean once created model. This is common in JSF.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

03 Jan 2013, 15:45

And where is your h:form? This is the reason of your issue. You always need a surrounded h:form on your page! Check the page structure here please http://code.google.com/p/primefaces-ext ... n_facelets or read PrimeFaces User's Guide.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

RickertJ
Posts: 9
Joined: 02 Jan 2013, 17:08

03 Jan 2013, 16:21

Hello Oleg,

thank you, that was the solution!
But now I have one more question - in the showcase sources (see http://code.google.com/p/primefaces-ext ... sage.xhtml) the h:form tag is also missing. Is that the reason, why the showcase also did not work for me or how does this example differ from my code?

Thanx,
Joern

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

03 Jan 2013, 18:31

In the showcase the h:form is not missed. It is simple not shown in the source tab. We have one big h:form.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

RickertJ
Posts: 9
Joined: 02 Jan 2013, 17:08

03 Jan 2013, 18:52

Thanks for checking, but I meant the source file from svn (see my previous link).

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 15 guests