Results 1 to 10 of 10

Thread: Submitting Form gives ClassCastException

  1. #1
    Join Date
    Dec 2004
    Location
    CA
    Posts
    208

    Default Submitting Form gives ClassCastException

    Greetings!

    I am recieving the following ClassCastException whenever I submit my form. I believe there was similar post and the solution was to get the latest CVS build that fixed the problem. However, I am still getting the exception.

    java.lang.ClassCastException
    at org.springframework.webflow.execution.servlet.Serv letEvent.<init>(ServletEvent.java:83)
    at org.springframework.webflow.execution.servlet.Serv letEvent.<init>(ServletEvent.java:55)
    at org.springframework.webflow.execution.servlet.Serv letFlowExecutionManager.createEvent(ServletFlowExe cutionManager.java:102)
    at org.springframework.webflow.execution.servlet.Serv letFlowExecutionManager.handle(ServletFlowExecutio nManager.java:77)
    at org.springframework.webflow.mvc.FlowController.han dleRequestInternal(FlowController.java:137)
    at org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(AbstractController.java:128)
    at org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:44)
    at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:684)
    at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:625)
    at org.springframework.web.servlet.FrameworkServlet.s erviceWrapper(FrameworkServlet.java:386)
    at org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:355)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:152)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:90)
    at com.caucho.server.dispatch.ServletFilterChain.doFi lter(ServletFilterChain.java:99)
    at org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter.doFilterInternal(OpenSessionInVie wFilter.java:172)
    at org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
    at com.caucho.server.dispatch.FilterFilterChain.doFil ter(FilterFilterChain.java:70)
    at com.caucho.server.webapp.WebAppFilterChain.doFilte r(WebAppFilterChain.java:163)
    at com.caucho.server.dispatch.ServletInvocation.servi ce(ServletInvocation.java:207)
    at com.caucho.server.http.HttpRequest.handleRequest(H ttpRequest.java:249)
    at com.caucho.server.port.TcpConnection.run(TcpConnec tion.java:327)
    at com.caucho.util.ThreadPool.runTasks(ThreadPool.jav a:450)
    at com.caucho.util.ThreadPool.run(ThreadPool.java:394 )
    at java.lang.Thread.run(Thread.java:534)

    Any Ideas?
    Curtney Jacobs

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Can you post your view code? I need to see what the value of the _eventId parameter is as well as the _flowExecutionId. For some reason more than one person has submtited event ids with commas, and it gets treated as a String[] instead of a String (or something like that--it's not yet clear to me).

    Keith
    Keith Donald
    Core Spring Development Team

  3. #3
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Here is the line where the CCE occurs:

    String eventId = (String)searchForParameter(eventIdParameterName, parameterValueDelimiter);

    So the parameter returned is not a String, I believe it is a String[] erroneously. There *may* be a bug in the searchForParameter parsing., or it may be a error in your view submission code. Paste that view code and lets figure it out.
    Keith Donald
    Core Spring Development Team

  4. #4
    Join Date
    Dec 2004
    Location
    CA
    Posts
    208

    Default

    Greetings Keith.

    The following is the steps I am taking and the corresponding url/code:

    1. I click on a category to see a list of subcategories.

    url produced is:
    http://xxx.xxx.xxx.xxx/commerce/cate...ory&category=6

    2. The subcategory list is displayed, I then click on a create button that displays a form to create a new category.

    url produced is:
    http://xxx.xxx.xxx.xxx/commerce/cate...ate&category=6


    The form is displayed. The form code is:

    <%@ page session="false" %>
    <%@ include file="../../taglib.jsp"%>


    <div align="left">

    <form name="NewCategoryForm" method="POST">
    <input type="hidden" name="_flowExecutionId" value="<c:out value="${flowExecutionId}"/>">
    <input type="hidden" name="category" value="<c:out value="${param.category}"/>">
    <input type="hidden" name="_eventId" value="submit">


    <table border="0" cellpacing="0" cellpadding="0" width="100%">

    <tr bgcolor="#FFFF88">
    <td>Name:</td>
    <td>
    <spring:bind path="categoryForm.name">
    <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"/>
    </spring:bind>
    </td>
    </tr>

    <tr bgcolor="#FFFF88">
    <td>Short Description</td>
    <td>
    <spring:bind path="categoryForm.shortDescription">
    <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"/>
    </spring:bind>
    </td>
    </tr>

    <tr bgcolor="#FFFF88">
    <td>Long Description</td>
    <td>
    <spring:bind path="categoryForm.longDescription">
    <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"/>
    </spring:bind>
    </td>
    </tr>


    <tr>
    <td colspan="2">
    <div align="right">
    <input type="button" onclick="javascript:document.NewCategoryForm.submi t()" value="Submit">
    </div>
    </td>
    </tr>
    </table>
    </form>
    </div>

    4. Clicking the form submit button gives the following:

    url produced is: (does not change from the previous step)
    http://xxx.xxx.xxx.xxx/commerce/cate...ate&category=6

    Error:

    java.lang.ClassCastException
    at org.springframework.webflow.execution.servlet.Serv letEvent.<init>(ServletEvent.java:83)
    at org.springframework.webflow.execution.servlet.Serv letEvent.<init>(ServletEvent.java:55)
    at org.springframework.webflow.execution.servlet.Serv letFlowExecutionManager.createEvent(ServletFlowExe cutionManager.java:102)
    at org.springframework.webflow.execution.servlet.Serv letFlowExecutionManager.handle(ServletFlowExecutio nManager.java:77)
    at org.springframework.webflow.mvc.FlowController.han dleRequestInternal(FlowController.java:137)
    at org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(AbstractController.java:128)
    at org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:44)
    at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:684)
    at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:625)
    at org.springframework.web.servlet.FrameworkServlet.s erviceWrapper(FrameworkServlet.java:386)
    at org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:355)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:152)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:90)
    at com.caucho.server.dispatch.ServletFilterChain.doFi lter(ServletFilterChain.java:99)
    at org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter.doFilterInternal(OpenSessionInVie wFilter.java:172)
    at org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
    at com.caucho.server.dispatch.FilterFilterChain.doFil ter(FilterFilterChain.java:70)
    at com.caucho.server.webapp.WebAppFilterChain.doFilte r(WebAppFilterChain.java:163)
    at com.caucho.server.dispatch.ServletInvocation.servi ce(ServletInvocation.java:207)
    at com.caucho.server.http.HttpRequest.handleRequest(H ttpRequest.java:249)
    at com.caucho.server.port.TcpConnection.run(TcpConnec tion.java:327)
    at com.caucho.util.ThreadPool.runTasks(ThreadPool.jav a:450)
    at com.caucho.util.ThreadPool.run(ThreadPool.java:394 )
    at java.lang.Thread.run(Thread.java:534)


    Analysis:

    From what I can see is that although in my form view I am setting a new _eventId, I believe the eventId in the url and what is embedded
    in the form is also getting submitted. Multiple events seems to be the problem?

    Also here is the relevant portion of my parent flow and subflow.

    I hope this was not to much information, but you never know...

    Parent flow:

    public void buildStates() throws FlowBuilderException {



    addActionState (ACTION_SELECT_CATEGORY_ID, method ("getSubcategories", actionRef (CatalogAction.class)),

    new Transition[] { on ("showOnlyCategories", VIEW_ONLY_CATEGORIES_ID),

    on ("showCategoriesAndProducts", VIEW_CATEGORIES_AND_PRODUCTS_ID)});



    addViewState (VIEW_ONLY_CATEGORIES_ID, VIEW_ONLY_CATEGORIES,

    new Transition[] {on("showCategory", ACTION_SELECT_CATEGORY_ID),

    on ("addCategory",SUB_FLOW_ADD_CATEGORY),

    on ("duplicateCategory", SUB_FLOW_DUPLICATE_CATEGORY),

    on ("applyCategory",SUB_FLOW_APPLY_CATEGORY),

    on ("updateCategory",SUB_FLOW_UPDATE_CATEGORY),

    on ("removeCategory",SUB_FLOW_REMOVE_CATEGORY),

    on ("deleteCategory",SUB_FLOW_DELETE_CATEGORY)});



    addViewState (VIEW_CATEGORIES_AND_PRODUCTS_ID, VIEW_CATEGORIES_AND_PRODUCTS,

    new Transition[] {on("showCategory", ACTION_SELECT_CATEGORY_ID),

    on ("showProduct", ACTION_GET_PRODUCT_ID)});



    addSubFlowState(SUB_FLOW_DUPLICATE_CATEGORY, flow(SUB_FLOW_DUPLICATE_CATEGORY), new BrowseCatalogFlowAttributeMapper(),

    new Transition[] { on(finish(), DUPLICATE_INLINE_REDIRECT), on(error(), "error") });



    addSubFlowState(SUB_FLOW_ADD_CATEGORY, flow(SUB_FLOW_ADD_CATEGORY), new BrowseCatalogFlowAttributeMapper(),

    new Transition[] { on(finish(), UPDATE_INLINE_REDIRECT), on(error(), "error") });



    addSubFlowState(SUB_FLOW_APPLY_CATEGORY, flow(SUB_FLOW_APPLY_CATEGORY),

    new Transition[] { on(finish(), APPLY_INLINE_REDIRECT), on(error(), "error") });



    addSubFlowState(SUB_FLOW_UPDATE_CATEGORY, flow(SUB_FLOW_UPDATE_CATEGORY),

    new Transition[] { on(finish(), UPDATE_INLINE_REDIRECT), on(error(), "error") });



    addSubFlowState(SUB_FLOW_DELETE_CATEGORY, flow(SUB_FLOW_DELETE_CATEGORY), new BrowseCatalogFlowAttributeMapper(),

    new Transition[] { on(finish(), DELETE_INLINE_REDIRECT), on(error(), "error") });



    addSubFlowState(SUB_FLOW_REMOVE_CATEGORY, flow(SUB_FLOW_REMOVE_CATEGORY), new BrowseCatalogFlowAttributeMapper(),

    new Transition[] { on(finish(), REMOVE_INLINE_REDIRECT), on(error(), "error") });



    addActionState (ACTION_GET_PRODUCT_ID, method (ACTION_GET_PRODUCT_METHOD, actionRef (ProductAction.class)), on("showProductDetail",VIEW_PRODUCT_DETAIL_ID));



    addEndState (VIEW_PRODUCT_DETAIL_ID, VIEW_PRODUCT_DETAIL);


    Relevant child flow:

    public void buildStates() throws FlowBuilderException {



    //determine which method to create a category (inline or via template).

    addActionState (METHOD, method(METHOD, actionRef(CategoryFormAction.class)),

    new Transition[] {on (TEMPLATE, CATEGORY_TEMPLATE_SETUP), on (INLINE, ADD_CATEGORY_INLINE)});



    //adds a category inline

    addActionState (ADD_CATEGORY_INLINE, method (ADD_CATEGORY_INLINE, actionRef(CategoryFormAction.class)),

    new Transition[] {on (success(), FINISHED), on (error(), ERROR)});



    //Properties for setting up named actions for creating category via template.

    HashMap p1 = new HashMap();

    p1.put ("name", "setup");

    p1.put ("method", SETUP_FORM);



    HashMap p2 = new HashMap ();

    p2.put ("name", "referenceData");

    p2.put ("method", "setupReferenceData");



    /*

    Setup Reference Data (Category Type list, Parent type list, etc)

    Note how both actions now have a name.

    Also note how there is only a transition for the success event of the referenceData action.

    This will result in the following behaviour:



    1) The setupForm action is executed and it returns "success".

    Since there is no transition matching "setup.success", the action state will continue action execution with the next action.



    2) The setupReferenceData action is executed and it returns "success".

    Since the there is a matching transition "referenceData.success",

    the action state stops action execution and transitions to the next state: "VIEW_CATEGORY_FORM".

    */

    addActionState (CATEGORY_TEMPLATE_SETUP, new AnnotatedAction [] {annotate(actionRef(CategoryFormAction.class), p1),

    annotate(actionRef (CategoryFormAction.class), p2)},

    new Transition[] {on ("referenceData.success", CATEGORY_TEMPLATE), on ("referenceData.error", ERROR)});



    //Display the input form view.

    addViewState (CATEGORY_TEMPLATE, CATEGORY_TEMPLATE, new Transition[] {on(submit(), BIND_N_VALIDATE_FORM)});



    //Bind and validate input data from the form.

    addActionState (BIND_N_VALIDATE_FORM, method (BIND_N_VALIDATE_FORM, actionRef (CategoryFormAction.class)),

    new Transition[] {on (error(), CATEGORY_TEMPLATE), on (success(), ADD_CATEGORY_TEMPLATE)});



    //NOTE: If VIEW_CATEGORY_FORM does not work try CATEGORY_VIEW_SETUP on transition "createAnother"

    addActionState (ADD_CATEGORY_TEMPLATE, method (ADD_CATEGORY_TEMPLATE, actionRef (CategoryFormAction.class)),

    new Transition[] {on (success(), "finish"), on ("createAnother", CATEGORY_TEMPLATE), on(error(), "error") });





    addEndState("finish");



    //end - an error occured

    //addEndState(error(), "error");

    }
    Curtney Jacobs

  5. #5
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Something to double check: if you have the '_eventId' field accidently declared more than once for the same form, I believe the servlet API will treate the parameter as a String[] instead of a String--not sure exactly the repo steps, but I believe something like this is happening (it would help to do a debug of the http parameter list.) We'll make a explicit check for this in the next release.
    Keith Donald
    Core Spring Development Team

  6. #6
    Join Date
    Dec 2004
    Location
    CA
    Posts
    208

    Default

    Yeah, I believe this is what is happening. In my form I am also submitting an '_eventId' and also in my url, from a previous request, their is also an '_eventId'.
    If I do a redirct to strip the url of its '_eventId' then everything works. However, my flow does not work as it suppose to.
    When I do a redirect I loose all of my flowScope attributes (used for conidtion logic in jsp) and my form object.

    So, I guess my question is how do I do a redirect without loosing these objects? I know you said this is possible, but I don't see it . :cry:

    The following is flow snippet:

    This is the first state that is entered, determine whether or not a category only view or a category and product view is shown.
    Code:
    addActionState &#40;ACTION_SELECT_CATEGORY_ID, method &#40;"getSubcategories", actionRef &#40;CatalogAction.class&#41;&#41;, 
    new Transition&#91;&#93; &#123; on &#40;"showOnlyCategories", VIEW_ONLY_CATEGORIES_ID&#41;,
    on &#40;"showCategoriesAndProducts", VIEW_CATEGORIES_AND_PRODUCTS_ID&#41;&#125;&#41;;
    This is my main view, where depending on the user action, subflows are spawn.

    Code:
    addViewState &#40;VIEW_ONLY_CATEGORIES_ID, VIEW_ONLY_CATEGORIES,
    new Transition&#91;&#93; &#123;on&#40;"showCategory", ACTION_SELECT_CATEGORY_ID&#41;, 
    on &#40;"addCategory",ADD_CATEGORY_INLINE&#41;,
    on &#40;"duplicateCategory", SUB_FLOW_DUPLICATE_CATEGORY&#41;, 
    on &#40;"applyCategory",SUB_FLOW_APPLY_CATEGORY&#41;,
    on &#40;"updateCategory",SUB_FLOW_UPDATE_CATEGORY&#41;,
    on &#40;"removeCategory",SUB_FLOW_REMOVE_CATEGORY&#41;,
    on &#40;"deleteCategory",SUB_FLOW_DELETE_CATEGORY&#41;,
    on &#40;submit&#40;&#41;, BIND_N_VALIDATE&#41;&#125;&#41;;
    The following adds a default category, and set attributes within the flow that will be used
    in my jsp page (conditionl ogic) .
    On 'success', if I do a redirect I loose my form ojbect and flow scope attributes.
    If I just go back to 'ACTION_SELECT_CATEGORY_ID' state, I cannot submit the form because of "double _eventId" problem. I cannot go back to 'VIEW_ONLY_CATEGORIES_ID' state becaue my view will not be updated/refresh.

    Code:
    addActionState &#40;ADD_CATEGORY_INLINE, method &#40;ADD_CATEGORY_INLINE, actionRef&#40;CategoryFormAction.class&#41;&#41;,
    new Transition&#91;&#93; &#123;on &#40;success&#40;&#41;,UPDATE_INLINE_REDIRECT&#41;, on &#40;error&#40;&#41;, "error"&#41;&#125;&#41;;
    If I do a redirect, then everything is gone
    Code:
    addEndState &#40;UPDATE_INLINE_REDIRECT,  new RedirectViewDescriptorCreator&#40;"categoryBrowse.html?select=$&#123;flowScope.category&#125;&category=$&#123;flowScope.category&#125;&action=$&#123;flowScope.action&#125;&method=$&#123;flowScope.method&#125;&row=$&#123;flowScope.row&#125;"&#41;&#41;;
    I have been struggling with this for a while now, I can't see the solution.

    Any ideas?
    Curtney Jacobs

  7. #7
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Curtney,

    It's a redirect triggered as the result of an end state entering, though. This means that the flow will be terminated and anything in flow scope will be cleaned up. So yes, in this case the form object, etc will NOT be available - the flow is history!

    Why is the flow ending at a state called "update inline"? Is it really done at that point? It doesn't sound like it.

    Keith
    Keith Donald
    Core Spring Development Team

  8. #8
    Join Date
    Dec 2004
    Location
    CA
    Posts
    208

    Default

    I looked at pr3 api and did not find an action state that is capable of redireting. I did try to redirect in a view state, but that did not work, using:
    Code:
    addViewState&#40;java.lang.String stateId, ViewDescriptorCreator creater, Transition&#91;&#93; transitions, java.util.Map properties&#41;
    The naming of my states are off. Initially, I was hoping to terminate the flow (redirect) and jump into subflow (update inline) that would handle adding a category.

    I guess I need to put more time into designing my flows.

    _CJ
    Curtney Jacobs

  9. #9
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    You could certainly terminate one flow via an end state and have that redirect to a URL that launches another (it wouldn't be a subflow in that case though, it'd just be another flow.) In that case, you'd need to pass the flow everything it needs as input. The flow launcher sample app demonstrates this.

    Is there a valid use case for redirecting mid flow? We'd likely need a custom state type for that.

    Keith
    Keith Donald
    Core Spring Development Team

  10. #10
    Join Date
    Dec 2004
    Location
    CA
    Posts
    208

    Default

    In my case, I don't think it was valid for me to redirect in the middle of the flow, it complicated things alot. I decided to refactor and was able to get the desired flow. However, it would be nice to have the ability to redirect from action states.

    In terms of the ClassCastException, it definetly was a "double _eventId" problem. After changing my form method from ' POST' to 'GET' the problem was solved, only a single '_eventId' was sent.

    Thanks Keith.

    Curtney
    Curtney Jacobs

Similar Threads

  1. Replies: 3
    Last Post: Jun 8th, 2010, 03:27 AM
  2. Replies: 9
    Last Post: May 4th, 2006, 09:53 AM
  3. Submitting empty field on form
    By strbuf in forum Web
    Replies: 11
    Last Post: Aug 11th, 2005, 07:29 PM
  4. Replies: 23
    Last Post: Jul 30th, 2005, 04:01 PM
  5. Replies: 10
    Last Post: Sep 3rd, 2004, 07:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •