我有一个设置页面,其中显示了不同的设置。可以自由编辑设置然后保存。这是具有这种(单个)设置的代码片段:
<h:form>
<p:panel id="panel" header="header">
<p:messages id="messages" />
<p:inputMask value="#{settingsBean.getSettingByCode('SSTMOUT').value}" mask="9?99"/>
</p:panel>
<p:commandButton value="Save" update="panel" actionListener="#{settingsBean.saveAllSettings}"/>
</h:form>
对于上面的代码,有一个带有getSettingByCode方法的支持bean SettingsBean,如下所示:
public Setting getSettingByCode(String code) {
for(Setting sett : settings) {
if (sett.getCode().equals(code)) {
return sett;
}
}
// Lacking Settings are created during application startup by different class, so this code should never be called
return null;
}
现在有什么奇怪的。如果我转到此页面,它会呈现精细 - 显示设置(出于测试目的,我只留下一个要编辑的设置),我可以在inputMask字段中输入所有内容。此外,在第一页访问时,访问bean的所有属性都没有任何问题。但是,当我单击“保存”按钮时,将使用此堆栈抛出异常:
WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (http--127.0.0.1-8080-1) /pages/secure/a.xhtml @17,161 value="#{settingsBean.getSettingByCode('SSTMOUT').value}": The class 'packageName.app.beans.SettingsBean$Proxy$_$$_WeldClientProxy' does not have the property 'getSettingByCode'.: javax.el.PropertyNotFoundException: /pages/secure/a.xhtml @17,161 value="#{settingsBean.getSettingByCode('SSTMOUT').value}": The class 'packageName.app.beans.SettingsBean$Proxy$_$$_WeldClientProxy' does not have the property 'getSettingByCode'.
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100) [jsf-impl-2.1.7-jbossorg-2.jar:]
at org.primefaces.util.ComponentUtils.getConverter(ComponentUtils.java:126) [primefaces-5.0.jar:5.0]
at org.primefaces.renderkit.InputRenderer.getConvertedValue(InputRenderer.java:171) [primefaces-5.0.jar:5.0]
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIInput.validate(UIInput.java:960) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIInput.executeValidate(UIInput.java:1233) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIInput.processValidators(UIInput.java:698) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.primefaces.component.panel.Panel.processValidators(Panel.java:287) [primefaces-5.0.jar:5.0]
at javax.faces.component.UIForm.processValidators(UIForm.java:253) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.primefaces.component.layout.Layout.processValidators(Layout.java:233) [primefaces-5.0.jar:5.0]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]
在此异常之后,没有任何反应,也没有调用任何属性。我有点不知道该怎么做。我希望这段代码能够更新Setting的值字段的值,然后将其保存在我的数据库中。
我正在使用JBoss 7.1.1.Final。
答案 0 :(得分:1)
我建议采用以下方法。首先,在您的bean中添加以下内容:
private Map<String, Setting> settingsByCode = new HashMap<>();
@PostConstruct
public void initializeSettingsByCode() {
for(Setting setting : settings) {
settingsByCode.put(setting.getCode(), setting);
}
}
public Map<String, Setting> getSettingsByCode() {
return settingsByCode;
}
在您的XHTML中,将EL表达式更改为以下内容:
<p:inputMask value="#{settingsBean.settingsByCode['SSTMOUT'].value}" mask="9?99"/>