Results 1 to 4 of 4

Thread: Binding Lists

  1. #1
    Join Date
    Oct 2006
    Posts
    2

    Question Binding Lists

    I know there are many posts with the bind lists. I tried all the options but I am still getting the darn "Neither Errors instance nor plain target object for bean name 'bene' available as request attribute" .

    Can someone please help me with this:

    Here is my jsp:
    <c:forEach items="${model.beneData}" var="bene" varStatus="status">
    <spring:bind path="bene.get[${status.index}].claimNumber">
    <input type="hidden" name="claimNumber" value="<c:out .claimNumber}"/>" >
    </spring:bind>

    Here is my controller:

    public ModelAndView onSubmit(Object command,BindException errors)
    throws ServletException {

    String claimNumber = ((BeneFind) command).getClaimNumber();

    String now = (new java.util.Date()).toString();
    List beneData = getBeneManager().getBeneInfo(claimNumber);
    Map myModel = new HashMap();
    myModel.put("now", now);
    myModel.put("beneData", beneData);
    return new ModelAndView(getSuccessView(), "model", myModel);
    }

    protected Object formBackingObject(HttpServletRequest request) throws ServletException {
    BeneFind benefind = new BeneFind();
    benefind.setClaimNumber("");
    return benefind;
    }

    I am trying to return to the same jsp page after updating:

    <property name="formView"><value>displayBene</value></property>
    <property name="successView"><value>displayBene</value></property>

  2. #2
    Join Date
    Oct 2004
    Location
    Fareham, England
    Posts
    313

    Default

    Hi ishsn0

    Have you tried Spring MVC's secret handshake with regard to the ModelAndView, namely the BindException.getModel() method?

    Code:
    public ModelAndView onSubmit(Object command,BindException errors)
    throws ServletException {
        String claimNumber = ((BeneFind) command).getClaimNumber();
    
        String now = (new java.util.Date()).toString();
        List beneData = getBeneManager().getBeneInfo(claimNumber);
    
        Map myModel = errors.getModel();
        myModel.put("now", now);
        myModel.put("beneData", beneData);
        return new ModelAndView(getSuccessView(), "model", myModel);
    }
    Using the Map returned from BindException.getModel() will result in the command object being present in the model, which might address your address (unless of course it is some other issue, but this is a start).

    Ping the forum back if this does not resolve your issue.

    Cheers
    Rick

  3. #3
    Join Date
    Oct 2006
    Posts
    2

    Default Same result

    Hi Rick,

    Thank you for your speedy response. I did what you said:

    public ModelAndView onSubmit(Object command,BindException errors)
    throws ServletException {

    String claimNumber = ((BeneFind) command).getClaimNumber();

    String now = (new java.util.Date()).toString();
    List beneData = getBeneManager().getBeneInfo(claimNumber);

    Map myModel = errors.getModel();
    myModel.put("now", now);
    myModel.put("beneData", beneData);

    return new ModelAndView(getSuccessView(), "model", myModel );
    }

    And I still get the same error:
    "Neither Errors instance nor plain target object for bean name 'bene' available as request attribute"

  4. #4
    Join Date
    Jan 2006
    Location
    Wichita, KS
    Posts
    16

    Default

    You are using the following in your jsp:

    <spring:bind path="bene.get[${status.index}].claimNumber">

    This is saying that your form controller command name is set to "bene". The "bene" object instance has a method named getGet() that returns a List that contains an object that has a setClaimNumber() method.

    Instead, I am guessing that you probably want to do the following:

    • Set your form controller command name to "beneData"
    • move "List beneData = getBeneManager().getBeneInfo(claimNumber);" to the formBackingObject method and return the List.
    • Iterate through ${beneData}
    • Make the spring bind tag path="beneData[${status.index}].claimNumber"

Posting Permissions

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