Announcement Announcement Module
Collapse
No announcement yet.
Complex Form Object from and to Controller/View Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Complex Form Object from and to Controller/View

    Hi everybody,

    I'm wondering what is the best way to overcome the following problem.

    I have a complex bean(AdapterChanWFForm) that has a bean ChannelWorkflowStatesListBean as field.
    Then the ChannelWorkflowStatesListBean has two collections as field, Collection<ChannelState> and Collection<WorkflowState> that finally have two string fileds (channel and state).

    Now In my jsp I have the below code to access the string fields channel and state and so far so good, everything
    works fine.

    The problem is when I try to submit the strings channel and state, based on the selected checkboxes, through the tglib <form:form>.
    Actually upon submitting the form, the method in the controller receives the AdapterChanWFForm with its ChannelWorkflowStatesListBean object null.

    In the first instance, I tried to use after <c:forEach the <form:input path="", but that didn't work for me,
    so I decided to just use <input name="chStateList[${counter.index}].channel" value="${chStateList.channel}", that
    indeed correctly displays the datas. My doubt is, would Spring be able to reconstruct the complex bean
    if I don't use its tglib, in this case <form:form path=""..etc., or is there another way to achieve this?

    Please find below my code.

    Many thanks in advance.

    Bean-------------------------------------------------------------------------------------------
    public class AdapterChanWFForm {

    ChannelWorkflowStatesListBean chWfStateList;
    ------------------------------------------------------------------------------------------------

    Bean-------------------------------------------------------------------------------------------
    public class ChannelWorkflowStatesListBean {

    Collection<ChannelState> chStateList;
    Collection<WorkflowState> wfStateList;
    ------------------------------------------------------------------------------------------------

    Bean-------------------------------------------------------------------------------------------
    public class ChannelState {

    String channel;
    String state;
    ------------------------------------------------------------------------------------------------

    Method Signature-------------------------------------------------------------------------------
    @ActionMapping(params = "action=actionTwo")
    public void actionChangeChannelsState(ActionRequest request, ActionResponse response,@ModelAttribute("adapterchanwfform")
    AdapterChanWFForm acwf, BindingResult result, Model model
    -------------------------------------------------------------------------------------------------


    JSP----------------------------------------------------------------------------------------------
    <c:forEach items="${chWfStateListBean.chStateList}" var="chStateList"
    varStatus="counter">
    <tr>
    <td><input name="chStateList[${counter.index}].channel"
    value="${chStateList.channel}" /></td>
    <td><input name="chStateList[${counter.index}].channel"
    value="${chStateList.state}" disabled="disabled" /></td>
    <td><input name="chStateList[${counter.index}].channel"
    value="${chStateList.checked}" type="checkbox" /></td>
    </tr>
    </c:forEach>
    --------------------------------------------------------------------------------------------------
Working...
X