Dyna Form

Community Driven Extensions Project
kdhrubo
Posts: 58
Joined: 26 Sep 2010, 06:52
Location: Kolkata, India
Contact:

14 Jun 2012, 14:42

What is the best way to retrieve dynaform data and populate an Entity object?
Since in dynaform i have a list of value for each editable field
For example if I have an Entity Employee with 10 fields now each field value will be abale in the FormField object with name and value. I know you will say this is a design decision but we loop through this form fields and use reflection to populate the attributes in Employee object?

Any other mechanism or good practice you have in mind?

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

14 Jun 2012, 14:50

I'm not sure I have understood you. What is your intention exactly? Have you seen this example? http://fractalsoft.net/primeext-showcas ... rForms.jsf (see model class with select items).

There isn't best way to retrieve dynaform data. It's technology dependent. You can retrieve them from DB, FileSystem, WebDav, ... What was the question?
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

kdhrubo
Posts: 58
Joined: 26 Sep 2010, 06:52
Location: Kolkata, India
Contact:

14 Jun 2012, 15:08

OK i will try to give a better example

I have an Entity --- (persistable) called Employee
Employee {
first name - string
last name - string
age - int
salary - int
}

Now I for each of these fields i will have a form field property like your book property - EmployeeProperty -- firstname, EmployeeProperty - last name etc
When the form is submitted I get a list of Employee Property --- 4 items
I create an employee object and set each field of this object with values from employee property? So is this advisable to do it with reflection because each EmployeeProperty has field name?

I hope I am clear now.

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

14 Jun 2012, 15:35

You can do

Code: Select all

EmployeeProperty implement Serializable {
    Employee employee;
    String propertyName;

    public EmployeeProperty(Employee employee, String propertyName) {
        this.employee = employee;
        trhis.propertyName = propertyName;
    }

    public Object getValue() {
        // if-else logic or reflection or BeanUtils (Apache Commons) to get employee property with propertyName
    }

    public void setValue(Object value) {
        // if-else logic or reflection or BeanUtils (Apache Commons) to get employee property with propertyName
    }
}

Employee employee = ...  // retrieve employee

...

row.addControl(EmployeeProperty(employee, "firstName") "input", 1, 1);
row.addControl(EmployeeProperty(employee, "seconfName") "input", 1, 1);
row.addControl(EmployeeProperty(employee, "age") "input", 1, 1);
row.addControl(EmployeeProperty(employee, "salary") "input", 1, 1);
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

18 Jun 2012, 12:29

Thanks for link, Cagatay. Answered.
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

kdhrubo
Posts: 58
Joined: 26 Sep 2010, 06:52
Location: Kolkata, India
Contact:

21 Jun 2012, 14:26

OK I finally have a dynamic form I submit and populate my bean mapping the field name to my bean property via reflection
But when there is error on the form I do not see any error message as on the example. What have I done wrong compared to the show case example. Here is my dynaform code

Code: Select all

<p:panel header="Create Target">

			<h:panelGroup id="dynaFormGroup" layout="block"
				style="margin-top: 15px;">
				<p:messages id="messages" showSummary="true" />

				<pe:dynaForm id="dynaForm" value="#{targetCreateForm.model}"
					var="data" openExtended="true" widgetVar="dynaFormWidget">

					<pe:dynaFormControl styleClass="pe-dynaform-label">
						<h:outputText value="#{data}" />
					</pe:dynaFormControl>
					
					<pe:dynaFormControl type="legend"
						styleClass="separator ui-state-disabled">
						<div class="ui-fieldset ui-widget ui-widget-content ui-corner-all">
							<h:outputText value="#{data}" />
						
						</div>
					</pe:dynaFormControl>

					<pe:dynaFormControl type="input" for="txt">
						<p:inputText id="txt" value="#{data.value}"
							required="#{data.required}" />
					</pe:dynaFormControl>
					
					<pe:dynaFormControl type="calendar" for="cal" styleClass="calendar">
						<p:calendar id="cal" value="#{data.value}"
							required="#{data.required}" showOn="button" />
					</pe:dynaFormControl>
					<pe:dynaFormControl type="select" for="sel" styleClass="select">
						<p:selectOneMenu id="sel" value="#{data.value}"
							required="#{data.required}" converter="#{lovConverter}">
							<f:selectItems value="#{data.lov}" var="l" itemLabel="#{l.name}"
								itemValue="#{l}" />
						</p:selectOneMenu>
					</pe:dynaFormControl>

					<pe:dynaFormControl type="selectU" for="selU" styleClass="select">
						<p:selectOneMenu id="selU" value="#{data.value}" var="u" effect="fade"
							required="#{data.required}" converter="#{userConverter}">
							<f:selectItems value="#{data.lov}" var="l"
								itemLabel="#{l.email}" itemValue="#{l}" />
							<p:column>#{u.firstName} #{u.lastName}</p:column>	
						</p:selectOneMenu>
					</pe:dynaFormControl>

					<pe:dynaFormControl type="textarea" for="tarea">
						<p:inputTextarea id="tarea" value="#{data.value}"
							required="#{data.required}" autoResize="false" />
					</pe:dynaFormControl>
					<pe:dynaFormControl type="rating" for="rat">
						<p:rating id="rat" value="#{data.value}"
							required="#{data.required}" />
					</pe:dynaFormControl>

					

					<f:facet name="buttonBar">
						<p:commandButton value="Submit" action="#{targetCreateForm.save}"
							process="dynaForm" />
						<p:commandButton type="reset" value="Reset"
							style="margin-left: 5px;" />
					</f:facet>
				</pe:dynaForm>
			</h:panelGroup>
		</p:panel>








kdhrubo
Posts: 58
Joined: 26 Sep 2010, 06:52
Location: Kolkata, India
Contact:

21 Jun 2012, 14:29

One more point I would like to make here. I do not clearly understand the rational for defining the form model (in some form bean) and then again the form controls in xhtml. My bet is it should be straightforward just like Menu model like this

Code: Select all

<pe:dynaForm id="dynaForm" value="#{targetCreateForm.model}"
               var="data" openExtended="true" widgetVar="dynaFormWidget">

</pe:dynaForm>
Finish end of story. You already have all the information to create this form in the model. Why declare it again and run loops over it??

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

21 Jun 2012, 15:08

@To your last post, creating whole form by model. I think you haven't understood this component ;) How do you want to create 100+ components with 1000+ attributes in Java? Form can contain almost every component inside. If you want to create everything in Java, you can use "binding" attribute. But binding is not ideal and have limitations (can be only used with request scoped beans).

Think on Tree please. You create there TreeNodes and map them to p:treeNode tag. p:treeNode can contain everything inside, but you don't create everything in Java. Right? DynaForm follows the same approach.
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

21 Jun 2012, 15:15

@To you first post.

Code: Select all

<p:commandButton value="Submit" action="#{targetCreateForm.save}" process="dynaForm" />
And where is update=":dynaFormGroup" or at least update=":messages"? You nothing update because default of "update" it @none. Be also aware, that DynaForm is a NamingContainer!
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

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 25 guests