当尝试使用基本的primefaces扩展示例时,当启动页面时出现以下错误,
环境细节:
- Java 8
- wildfly 8.0
- primefaces - 5.2
- Primefaces-extension-3.1.0
- commons-lang-3.3.1
- gson - 2.3
- mojarra-2.2.8
2015-05-25 14:51:59,224 FATAL [javax.enterprise.resource.webcontainer.jsf.context] (default task-2) JSF1073: java.lang.StackOverflowError caught during processing of RENDER_RESPONSE 6 : UIComponent-ClientId=, Message=null
2015-05-25 14:51:59,236 FATAL [javax.enterprise.resource.webcontainer.jsf.context] (default task-2) No associated message: java.lang.StackOverflowError
at java.util.concurrent.atomic.AtomicReferenceArray.get(AtomicReferenceArray.java:125) [rt.jar:1.8.0_20]
at com.google.common.cache.LocalCache$Segment.getFirst(LocalCache.java:2688)
at com.google.common.cache.LocalCache$Segment.getEntry(LocalCache.java:2695)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2176)
at com.google.common.cache.LocalCache.get(LocalCache.java:3932)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3936)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4806)
at org.jboss.weld.util.cache.LoadingCacheUtils.getCacheValue(LoadingCacheUtils.java:52) [weld-core-impl-2.1.1.Final.jar:2013-12-03 09:59]
at org.jboss.weld.resolution.NameBasedResolver.resolve(NameBasedResolver.java:92) [weld-core-impl-2.1.1.Final.jar:2013-12-03 09:59]
at org.jboss.weld.manager.BeanManagerImpl.getBeans(BeanManagerImpl.java:826) [weld-core-impl-2.1.1.Final.jar:2013-12-03 09:59]
at org.jboss.weld.el.AbstractWeldELResolver.lookup(AbstractWeldELResolver.java:102) [weld-core-impl-2.1.1.Final.jar:2013-12-03 09:59]
at org.jboss.weld.el.AbstractWeldELResolver.getValue(AbstractWeldELResolver.java:91) [weld-core-impl-2.1.1.Final.jar:2013-12-03 09:59]
at org.jboss.as.jsf.injection.weld.ForwardingELResolver.getValue(ForwardingELResolver.java:46) [wildfly-jsf-injection-8.0.0.CR1.jar:8.0.0.CR1]
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:188) [javax.el-3.0-b07.jar:3.0-b07]
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) [jsf-impl-2.2.8.jar:2.2.8]
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) [jsf-impl-2.2.8.jar:2.2.8]
at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:116) [javax.el-3.0-b07.jar:3.0-b07]
at com.sun.el.parser.AstValue.getBase(AstValue.java:151) [javax.el-3.0-b07.jar:3.0-b07]
at com.sun.el.parser.AstValue.getValue(AstValue.java:200) [javax.el-3.0-b07.jar:3.0-b07]
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226) [javax.el-3.0-b07.jar:3.0-b07]
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50) [weld-core-impl-2.1.1.Final.jar:2013-12-03 09:59]
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50) [weld-core-impl-2.1.1.Final.jar:2013-12-03 09:59]
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) [jsf-impl-2.2.8.jar:2.2.8]
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) [jsf-api-2.2.8.jar:2.2]
at org.primefaces.extensions.component.base.AbstractDynamicData.getValue(AbstractDynamicData.java:110) [primefaces-extensions-3.1.0.jar:3.1.0]
at org.primefaces.extensions.component.dynaform.DynaForm.invokeOnChildren(DynaForm.java:243) [primefaces-extensions-3.1.0.jar:3.1.0]
at org.primefaces.extensions.component.base.AbstractDynamicData.invokeOnComponent(AbstractDynamicData.java:437) [primefaces-extensions-3.1.0.jar:3.1.0]
at org.primefaces.extensions.component.dynaform.DynaForm.invokeOnChildren(DynaForm.java:256) [primefaces-extensions-3.1.0.jar:3.1.0]
at org.primefaces.extensions.component.base.AbstractDynamicData.invokeOnComponent(AbstractDynamicData.java:437) [primefaces-extensions-3.1.0.jar:3.1.0]
XHTML <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:pe="http://primefaces.org/ui/extensions"
>
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form prependId="false">
<h:panelGroup id="dynaFormGroup">
<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 :mainForm:inputValues"
oncomplete="handleComplete(xhr, status, args)"/>
<p:commandButton type="reset" value="Reset" style="margin-left: 5px;"/>
</f:facet>
</pe:dynaForm>
</h:panelGroup>
<p:dialog header="Input values" widgetVar="inputValuesWidget">
<p:dataList id="inputValues" value="#{dynaFormController.bookProperties}" var="bookProperty"
style="margin:10px;">
<h:outputText value="#{bookProperty.name}: #{bookProperty.formattedValue}"
style="margin-right: 10px;"/>
</p:dataList>
</p:dialog>
<h:outputScript id="dynaFormScript" target="body">
/* <![CDATA[ */
function handleComplete(xhr, status, args) {
if(args && args.isValid) {
PF('inputValuesWidget').show();
} else {
PF('inputValuesWidget').hide();
}
}
/* ]]> */
</h:outputScript>
<h:outputStylesheet id="dynaFormCSS">
/* note: trick with colspan is needed for IE8 */
.pe-dynaform-cell input,
.pe-dynaform-cell textarea,
.pe-dynaform-cell[colspan="1"] input,
.pe-dynaform-cell[colspan="1"] textarea {
width: 150px;
}
/* note: trick with colspan is needed for IE8 */
.pe-dynaform-cell.calendar input,
.pe-dynaform-cell[colspan="1"].calendar input {
width: 120px;
}
.pe-dynaform-cell.select .ui-selectonemenu {
width: 157px !important;
}
.pe-dynaform-cell.select .ui-selectonemenu .ui-selectonemenu-label {
width: 130px !important;
}
</h:outputStylesheet>
</h:form>
</h:body>
DynaFormController:
@Named
@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:
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;
}
}
我有同样的问题,并通过添加id属性到表单标签来修复它:
<h:form id="mainForm" prependId="false">
<h:panelGroup id="dynaFormGroup">
---- EDIT -----
当您查看发布的代码时,可以看到命令按钮具有update属性中组件的完全限定id:mainForm:dynaFormGroup
<p:commandButton value="Submit" action="#{dynaFormController.submitForm}"
process="dynaForm" update=":mainForm:dynaFormGroup :mainForm:inputValues"
oncomplete="handleComplete(xhr, status, args)"/>
这就是为什么表单应该有id="mainform"
另一方面,为什么当id缺失时,会导致java.lang。StackOverflowError,是我仍然不知道的东西。如果我找到原因,我会更新