2012-05-16 78 views
0

我被迫從myfaces(2.1.7)切換到mojarra(2.1.7)。在此之後,我收到了這樣一個例外情況。從myfaces切換到mojarra後發生IndexOutOfBoundsException

我正在提交表單,這給我驗證錯誤。到目前爲止這是正確的。我再次提交表單,這給我驗證錯誤。到目前爲止這是正確的。現在我再次提交表單,並得到IndexOutOfBoundsException。

javax.faces.FacesException: Unexpected error restoring state for component with id someForm:someField. Cause: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1. 
    at com.sun.faces.application.view.StateManagementStrategyImpl$2.visit(StateManagementStrategyImpl.java:272) 
    at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151) 
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1612) 
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) 
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) 
    at javax.faces.component.UIForm.visitTree(UIForm.java:371) 
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) 
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) 
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) 
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) 
    at com.sun.faces.application.view.StateManagementStrategyImpl.restoreView(StateManagementStrategyImpl.java:251) 
    at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:188) 
    at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123) 
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:453) 
    at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:142) 
    at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:303) 
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:192) 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116) 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) 
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602) 
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) 
    at java.lang.Thread.run(Thread.java:619) 
Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 
    at java.util.ArrayList.RangeCheck(ArrayList.java:547) 
    at java.util.ArrayList.get(ArrayList.java:322) 
    at javax.faces.component.AttachedObjectListHolder.restoreState(AttachedObjectListHolder.java:165) 
    at javax.faces.component.UIInput.restoreState(UIInput.java:1411) 
    at com.sun.faces.application.view.StateManagementStrategyImpl$2.visit(StateManagementStrategyImpl.java:264) 
    ... 35 more 

我用google搜索了這個,但還沒有找到任何線索呢。

Jonny

回答

1

stacktrace暗示您正在使用PrimeFaces。

此問題在PrimeFaces的舊版本中已知,實際上是PrimeFaces中的一個錯誤,而不是在Mojarra中。確保您使用的是PrimeFaces版本。到目前爲止,當您使用PF2時爲2.2.1,或者當您使用PF3時爲3.2。

+0

嗨BalusC,感謝您的quichk答覆。我看到了這個問題,但我不認爲它這一點。我使用PF3.2我縮小了它,當我使用''就像這樣'' \t \t '我正在運行進入這個錯誤。刪除禁用驗證的東西_solves_它。我很困惑。 – user871611

+0

昨天我遇到了同樣的問題,並且不得不搜索很長一段時間解決這個問題。我希望人們在需要的時候找到這個頁面,因爲問題是由validateBean組件引起的。不需要刪除標籤,但在進入另一個轉換之前,您需要刷新頁面。一種方法是將「ajax ='false'」添加到提交表單的命令按鈕中。希望這將有助於未來的人:) – devnomore

0

我有完全相同的問題,很容易重現。
你可以用下面的類重現:

驗證:

@FacesValidator("testValidator") 
public class TestValidator implements Validator { 

    @Override 
    public void validate(FacesContext fc, UIComponent uic, Object o) throws ValidatorException { 
     if (!(o instanceof Integer)) { 
      throw new ValidatorException(new FacesMessage("validation message!")); 
     } 
    } 
} 

FacesComponent:

@ListenerFor(systemEventClass = PreValidateEvent.class) 
@FacesComponent("testField") 
public class TestField extends UIComponentBase implements NamingContainer { 

@Override 
public String getFamily() { 
    return UINamingContainer.COMPONENT_FAMILY; 
} 

@Override 
public void processEvent(ComponentSystemEvent event) throws AbortProcessingException { 
    super.processEvent(event); 
    UIComponent findComponent = findComponent("input"); 
    if (findComponent instanceof UIInput) { 
     UIInput i = (UIInput) findComponent; 
     boolean notFound = true; 
     for (Validator v : i.getValidators()) { 
      if (v instanceof TestValidator) { 
       notFound = false; 
      } 
     } 
     if (notFound) { 
      i.addValidator(new TestValidator()); 
     } 
    } 
} 

} 

自定義組件:

<?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:cc="http://java.sun.com/jsf/composite"> 

    <!-- INTERFACE --> 
    <cc:interface componentType="testField"> 
    </cc:interface> 

    <!-- IMPLEMENTATION --> 
    <cc:implementation> 
     field: <h:inputText id="input" value="#{testController.inputText}" /> 
    </cc:implementation> 
</html> 

ManagedBean:

@SessionScoped 
@Named("testController") 
public class TestController implements Serializable { 

private static final long serialVersionUID = 1L; 

private String inputText = ""; 

public TestController() { 
} 

public void actionListener(ActionEvent event) { 

} 

public String myAction() { 
    return ""; 
} 

public String getInputText() { 
    return inputText; 
} 

public void setInputText(String inputText) { 
    this.inputText = inputText; 
} 

} 

的index.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:t="http://java.sun.com/jsf/composite/test" 
     xmlns:f="http://java.sun.com/jsf/core" 
     xmlns:h="http://xmlns.jcp.org/jsf/html"> 
    <h:head> 
     <title>Jsf Problem</title> 
    </h:head> 
    <h:body> 
     <h:form>  
      <h:messages /> 
      <t:field /> 
      <h:commandButton value="Submit" action="#{testController.myAction()}" /> 
     </h:form> 
    </h:body> 
</html> 

定製組件字段內的的inputText得到一個新的驗證添加在的processEvent()方法內PreValidateEvent。
如果提交按鈕現在連續按下三次並出現驗證錯誤,則拋出ArrayIndexOutOfBoundException異常。我試圖調試,發現這個異常拋在了AttachedObjectListHolder#restoreState(FacesContext,Object)裏面,之後我的eclipse調試器變得瘋狂了......

我覺得這是一個JSF Bug!

我想發表評論,但我'不許尚未... :(

相關問題