3

对于我当前的项目,我正在使用 JSF、Seam 和 Hibernate,但我遇到了 seam 问题。

我创建了一个带有输入字段(用于 productionMonth)的 XHTML 文件,并在其上定义了一个验证器以确保正确的用户输入。我还在现场启用了 ajax 支持,以使验证更加用户友好。

然后我创建了我的操作类(从我的 XHTML 引用)并添加了属性“productionMonth”和我需要的验证器。

现在,当我部署这个案例时,一切似乎都很好。但是:我在 productionMonth 字段中输入一个值,然后按 Enter 以提交我的表单。有时(当我足够快而我的电脑足够慢时)我会遇到异常:

Target Unreachable, identifier 'sateiFileHome' resolved to null"

奇怪的是

  1. 这只能在 IE 中重现(我使用的是 IE8)
  2. 当我删除 ajax 支持标签时,我没有错误,所以它一定与 ajax 相关

我对问题原因的最佳猜测是 AJAX 调用和提交是同时启动的。因此,其中一个调用无法解析对操作类的引用。但是为什么它只在 IE 中呢?

我也尝试使用 Hibernate 验证,但仍然是同样的问题!

我用谷歌搜索了这个问题,但找不到任何对我有帮助的东西。这里有什么猜测吗?

我的动作课:

@Name("sateiFileHome")
@Scope(ScopeType.CONVERSATION)
public class SateiFileHome extends CustomHome<Satei> {
    ...
    private Integer productionMonth = 0;
    ...
    public Integer getProductionMonth() {
        return productionMonth;
    }

public void setProductionMonth(Integer productionMonth) {
    this.productionMonth = productionMonth;
}
    ...
/* VALIDATORS */
public void validateProductionMonth(final FacesContext context,
        final UIComponent comp, final Object inputValue)
        throws ValidatorException {
    DateValidator.validateYearMonth(inputValue, false);
    this.productionMonth = Integer.parseInt(String.valueOf(inputValue));
}
    ...
}

我的 XHTML 文件:

<s:decorate id="productionMonthField" template="layout/edit.xhtml">
    <ui:define name="label">Production Month</ui:define>
    <h:inputText id="productionMonth" 
            value="#{sateiFileHome.productionMonth}" 
            validator=#{sateiFileHome.validateProductionMonth}
            required="true"
            size="7"
            maxlength="6">
                    <a:support event="onblur" reRender="productionMonthField"/>
    </h:inputText>
</s:decorate>

例外(仅可在 IE8 中重现):

Caused by javax.el.PropertyNotFoundException with message: "/SateiFile.xhtml @123,48 value="#{sateiFileHome.versionCode}": Target Unreachable, identifier 'sateiFileHome' resolved to null"

和完整的堆栈跟踪:

Exception during request processing:
Caused by javax.servlet.ServletException with message: "/SateiFile.xhtml @123,48 value="#{sateiFileHome.versionCode}": Target Unreachable, identifier 'sateiFileHome' resolved to null"
javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:619)
Caused by javax.el.PropertyNotFoundException with message: "/SateiFile.xhtml @123,48 value="#{sateiFileHome.versionCode}": Target Unreachable, identifier 'sateiFileHome' resolved to null"
com.sun.facelets.el.TagValueExpression.getType(TagValueExpression.java:62)
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:92)
com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:188)
com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:301)
javax.faces.component.UIInput.getConvertedValue(UIInput.java:942)
javax.faces.component.UIInput.validate(UIInput.java:868)
javax.faces.component.UIInput.executeValidate(UIInput.java:1072)
javax.faces.component.UIInput.processValidators(UIInput.java:672)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
javax.faces.component.UIForm.processValidators(UIForm.java:235)
org.ajax4jsf.component.AjaxViewRoot$3.invokeContextCallback(AjaxViewRoot.java:447)
org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:240)
org.ajax4jsf.component.AjaxViewRoot.processValidators(AjaxViewRoot.java:463)
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:619)
4

2 回答 2

2

将 bean 放在页面范围而不是会话范围中解决了这个问题。我们使用了对话范围,但我们没有离开页面,所以我们意识到对话范围并不是真正需要的。页面范围就足够了,它解决了问题。不要问我为什么以及如何,但它确实有效。

于 2011-10-13T07:18:48.110 回答
0

我会尝试几件事。

1) 应该

 validator=#{sateiFileHome.validateProductionMonth}

在属性值周围有引号?

 validator="#{sateiFileHome.validateProductionMonth}"

2) 弄清楚对话从哪里开始,是否确实有对话正在进行。它仅在 IE 中的事实可能意味着这不是问题。

3)您是否尝试过添加

immediate="true"

到 ajax 标签?

4)您也可以尝试将验证移至另一个类。这将使它更有用一点,然后验证就不会在对话范围的 bean 上。

5)您还可以实现自己的 javax.faces.validator.Validator 并将其作为标签添加到您的输入中。这意味着可以替换验证器 =“#{sateiFileHome.validateProductionMonth}”。

希望这里有帮助。

于 2011-10-12T12:11:52.570 回答