Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Webflow, the ID and version get stripped

I recently came across a strange error with Spring Webflow and I can't seem to find the problem, and noone ever experienced that, it seems.

When starting my flow I load from the database an object which the user will then modify in the flow. As the object is loaded, every property is correctly binded: while debugging the on-entry function, the object has all properties set. After that, though, when the view has been rendered, the object's "id" and "version" fields suddenly become null, so <form:hidden path="id" /> or <form:hidden path="version" /> do not display anything.

I don't know where to start and I don't want to put here useless code, so if you need some part of my code just ask.

Additional informations:

I also tried to forcefully modify those fields by using <form:input path="id" /> and trying to manually put some values inside and submitting the form, with no luck.

Important update It seems that this problem happens with every "complex" object, let's say that MyForm has another class in it, called B. If that B contains only basic types such as Integer and String, they are correctly stored and retrieved with their id and version field, if that B has other kind of object fields in it (a C class), then their id and version disappears.

Excerpt of the flow configuration that interests the view. Please note that every data is viewed correctly in the form except the id and version fields.

FLOW:

<input name="idObj" />
<decision-state id="createOrEdit">
    <if test="idObj== null" then="newObj" else="modObj" />
</decision-state>
...
<action-state id="modObj">
    <evaluate expression="Search.findOne(idObj)" result="flowScope.form"/>
    <transition to="object" />
</action-state>

<view-state id="object" view="flow.object" model="form">
    <on-entry>
        <evaluate expression="handler.prepare(flowScope.form)"/>
    </on-entry>
    <!-- transitions omitted -->
</view-state>

VIEW:

<form:form modelAttribute="form" cssClass="form form-horizontal">
    <form:input path="id" />
    <form:input path="version" />
    <!-- other fields -->
    <input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}"/>
</form:form>

HANDLER:

public void prepare(MyForm form) {

    int codType = form.getFormType().getId();
    FormType type = service.findOne(codType);

    form.setFormType(type); // This is here for JPA to save correctly the instance
    RequestContext requestContext = RequestContextHolder.getRequestContext();
    requestContext.getViewScope().put("typeList", typeService.findAll());
}
like image 323
Luca Avatar asked Dec 14 '25 13:12

Luca


1 Answers

Ok, after three days of hitting my head hard on the desk I discovered what follows:

In order for Webflow to work with any kind of custom form, it has to implement the Serializable interface, and my form object actually did it. But the object from which it inherited the id and version fields did not, so all the object-related properties were correctly stored, but not the inherited ones which weren't serialized.

So, in short, to make it work I just put the implements Serializable in the base database object class: public class BaseDTO implements Serializable.

like image 50
Luca Avatar answered Dec 17 '25 02:12

Luca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!