Spring 3 mvc nested form:select

In my scenario, i'm developing nested select on a JSP, binded to a bean:

Bean

public class WizardPanelp1Bean {

private Integer id;
private Stringofpanels stringofpanels;
private Paneltype paneltype;
private Integer number;
private String paneltypestring;
//and getters/setters... [Omitted]

Now i have the Paneltype object, another simple bean

Paneltype

private Integer id;
private double peakpower;
private double weight;
private String name;
private double dimension;
private double conversion;
private Set functions = new HashSet(0);
private Set sensors = new HashSet(0);
private Set panels = new HashSet(0);
//[Getters/setters omitted as usual]

So, i prepare the view, with a bean named wb a simple arraylist of panels

 public class PanelsBean {
    private ArrayList<WizardPanelp1Bean> panels =new ArrayList<WizardPanelp1Bean>();

and finally i go to the jsp (please note this is in a )

<tbody>
         <c:forEach items="${wb.panels}" varStatus="loop" var="item">
            <tr>
                <td>${item.id}</td>
                <td>
                    <form:select  path="panels[${loop.index}].paneltype" >
                        <c:forEach var="type" items="${types}">
                            <c:choose>
                                <c:when test="${item.paneltype.id==type.id}">
                                    <form:option selected="selected" value="${type.id}" label="${type.name}" />
                                </c:when>
                                <c:otherwise>
                                    <form:option value="${type.id}" label="${type.name}" />
                                </c:otherwise>
                            </c:choose>
                        </c:forEach>
                    </form:select>
                </td>
                    <td><form:input style="width:180px" path="panels[${loop.index}].number" /></td>
                    <td>
                    <div>
                        <form:input style="visibility: hidden ; width:0px" path="panels[${loop.index}].id" disabled="disabled" />
                        <a href="javascript:remove(${item.id},${stringofpanels.id})" class="wb.panels.remove" >Rimuovi</a>
                    </div>
                    </td>
                </tr>
            </c:forEach>    
     </tbody>

every time i get a null reference to paneltype. I obviously used a @InitBinder on the controller: Initbinder

@InitBinder
    protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
            binder.registerCustomEditor(Paneltype.class, "paneltype", new PropertyEditorSupport() {
                @Override
                public void setAsText(String text) {
                    int i=0;
                    PaneltypeDAO pDAO=new PaneltypeDAO();
                    setValue(pDAO.findById(Integer.parseInt(text)));
                }
            });
        }

but the code never reach this. It's like the jsp is sure that the value is null.

Suggestions? Thanks

Answers


I think your problem persists when you try to submit this form and not getting the binded values in the model.

Try to initialize your list using LazyList. Please replace your panels declaration in PanelsBean class as below.

private List<WizardPanelp1Bean> panels = LazyList.decorate(new ArrayList<WizardPanelp1Bean>(),FactoryUtils.instantiateFactory(WizardPanelp1Bean.class));

Hope this helps you. Cheers.


Need Your Help

Dynamic html form values are not being stored in database

javascript php jquery html json

I am developing a game portal in which professor should be able to add any type of questions in a game. I have created the question type(multiple choice or descriptive ) functions in form.php and i...

Modify Wordpress plugin function in functions.php

php wordpress function wordpress-plugin

I need to change the value of a function from a Wordpress plugin that I'm using.