当我尝试从ShowCase运行DynaForm示例时,我得到了Stackoverflow。
我尝试了其他示例,看看我在安装扩展程序时是否出错。 pe:analogClock和pe:时间表工作得很好。
有人可以看看并指出我正确的方向吗?
谢谢!
库:
java.lang.StackOverflowError
java.util.HashMap.hash(HashMap.java:338)
java.util.HashMap.get(HashMap.java:556)
org.apache.catalina.connector.Request.getAttribute(Request.java:942)
org.apache.catalina.connector.RequestFacade.getAttribute(RequestFacade.java:285)
org.apache.myfaces.context.servlet.RequestMap.getAttribute(RequestMap.java:47)
org.apache.myfaces.util.AbstractAttributeMap.containsKey(AbstractAttributeMap.java:62)
org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:182)
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:65)
org.apache.myfaces.el.convert.VariableResolverToELResolver.getValue(VariableResolverToELResolver.java:96)
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72)
org.apache.el.parser.AstValue.getValue(AstValue.java:161)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
org.apache.myfaces.view.facelets.el.TagValueExpression.getValue(TagValueExpression.java:85)
javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:260)
org.primefaces.extensions.component.base.AbstractDynamicData.getValue(AbstractDynamicData.java:110)
org.primefaces.extensions.component.dynaform.DynaForm.invokeOnChildren(DynaForm.java:243)
org.primefaces.extensions.component.base.AbstractDynamicData.invokeOnComponent(AbstractDynamicData.java:437)
org.primefaces.extensions.component.dynaform.DynaForm.invokeOnChildren(DynaForm.java:256)
org.primefaces.extensions.component.base.AbstractDynamicData.invokeOnComponent(AbstractDynamicData.java:437)
org.primefaces.extensions.component.dynaform.DynaForm.invokeOnChildren(DynaForm.java:256)
org.primefaces.extensions.component.base.AbstractDynamicData.invokeOnComponent(AbstractDynamicData.java:437)
DynaFormControl:
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import org.primefaces.context.RequestContext;
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
@ViewScoped
public class DynaFormController implements Serializable {
private static final long serialVersionUID = 20120423L;
private DynaFormModel model;
private static List<SelectItem> LANGUAGES = new ArrayList<SelectItem>();
@PostConstruct
protected void initialize() {
model = new DynaFormModel();
// add rows, labels and editable controls
// set relationship between label and editable controls to support outputLabel with "for" attribute
// 1. row
DynaFormRow row = model.createRegularRow();
DynaFormLabel label11 = row.addLabel("Author");
DynaFormControl control12 = row.addControl(new BookProperty("Author", true), "input");
label11.setForControl(control12);
DynaFormLabel label13 = row.addLabel("ISBN");
DynaFormControl control14 = row.addControl(new BookProperty("ISBN", true), "input");
label13.setForControl(control14);
// 2. row
row = model.createRegularRow();
DynaFormLabel label21 = row.addLabel("Title");
DynaFormControl control22 = row.addControl(new BookProperty("Title", false), "input", 3, 1);
label21.setForControl(control22);
// 3. row
row = model.createRegularRow();
DynaFormLabel label31 = row.addLabel("Publisher");
DynaFormControl control32 = row.addControl(new BookProperty("Publisher", false), "input");
label31.setForControl(control32);
DynaFormLabel label33 = row.addLabel("Published on");
DynaFormControl control34 = row.addControl(new BookProperty("Published on", false), "calendar");
label33.setForControl(control34);
// 4. row
row = model.createRegularRow();
DynaFormLabel label41 = row.addLabel("Language");
DynaFormControl control42 = row.addControl(new BookProperty("Language", false), "select");
label41.setForControl(control42);
DynaFormLabel label43 = row.addLabel("Description", 1, 2);
DynaFormControl control44 = row.addControl(new BookProperty("Description", false), "textarea", 1, 2);
label43.setForControl(control44);
// 5. row
row = model.createRegularRow();
DynaFormLabel label51 = row.addLabel("Rating");
DynaFormControl control52 = row.addControl(new BookProperty("Rating", 3, true), "rating");
label51.setForControl(control52);
}
public DynaFormModel getModel() {
return model;
}
public List<BookProperty> getBookProperties() {
if (model == null) {
return null;
}
List<BookProperty> bookProperties = new ArrayList<BookProperty>();
for (DynaFormControl dynaFormControl : model.getControls()) {
bookProperties.add((BookProperty) dynaFormControl.getData());
}
return bookProperties;
}
public String submitForm() {
FacesMessage.Severity sev = FacesContext.getCurrentInstance().getMaximumSeverity();
boolean hasErrors = (sev != null && (FacesMessage.SEVERITY_ERROR.compareTo(sev) >= 0));
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.addCallbackParam("isValid", !hasErrors);
return null;
}
public List<SelectItem> getLanguages() {
if (LANGUAGES.isEmpty()) {
LANGUAGES.add(new SelectItem("en", "English"));
LANGUAGES.add(new SelectItem("de", "German"));
LANGUAGES.add(new SelectItem("ru", "Russian"));
LANGUAGES.add(new SelectItem("tr", "Turkish"));
}
return LANGUAGES;
}
}
BookProperty.java:
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
public class BookProperty implements Serializable {
private static final long serialVersionUID = 20120521L;
private String name;
private Object value;
private boolean required;
public BookProperty(String name, boolean required) {
this.name = name;
this.required = required;
}
public BookProperty(String name, Object value, boolean required) {
this.name = name;
this.value = value;
this.required = required;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Object getValue() {
return value;
}
public Object getFormattedValue() {
if (value instanceof Date) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("d MMM yyyy");
return simpleDateFormat.format(value);
}
return value;
}
public void setValue(Object value) {
this.value = value;
}
public boolean isRequired() {
return required;
}
public void setRequired(boolean required) {
this.required = required;
}
}
dynaform.xhtml文件:
<html xmlns="http://www.w3c.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions">
<ui:composition template="/templates/public/desktop/simple.xhtml">
<ui:define name="content">
<h:form id="mainForm">
<h:panelGroup widgetVar="detail" id="detail">
<p:messages id="messages" showSummary="true" />
<pe:dynaForm id="dynaForm" value="#{dynaFormController.model}"
var="data">
<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}">
<f:selectItems value="#{dynaFormController.languages}" />
</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="#{dynaFormController.submitForm}" process="dynaForm"
update="_mainForm_dynaFormGroup" />
<p:commandButton type="reset" value="Reset"
style="margin-left: 5px;" />
</f:facet>
</pe:dynaForm>
</h:panelGroup>
</h:form>
</ui:define>
</ui:composition>
</html>
template simple.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions">
<h:head></h:head>
<h:body>
<ui:insert name="content" />
</h:body>
</html>
答案 0 :(得分:1)
你只需要:
更改commandButton上的更新<p:commandButton value="Submit" action="#{dynaFormController.submitForm}" update=":mainForm:dynaFormGroup" />
update =“:mainForm:dynaFormGroup”
在第一个panelGrid上添加ID <h:panelGroup id="dynaFormGroup" widgetVar="detail" id="detail">
id =“dynaFormGroup”