1

我能够显示值并对其进行编辑,但是当我提交表单时,它会遇到以下错误。

爪哇

public Class Baskets {
  private Basket basket;
  ...

  public String edit(){
    System.err.println("item>>>" + this.basket.getItems().get(0).getProduct().getPrice());
    ...
  }
  getter and setters
}

JSP

 <form name="edit" method="POST" action="edit">
      <table border="4">
        <thead><td>Product</td><td>Price 2</td><td>User</td><td>Time</td></thead>  
        <tbody>
           <s:iterator value="basket.items" var="item" status="cur">
             <tr>
                <s:textfield type="hidden" id="item[%{#cur.index}].id" name="item[%{#cur.index}].id" value="%{id}" theme="simple"/>
                  <td>

                      Price : <s:textfield id="item[%{#cur.index}].product.price" name="item[%{#cur.index}].product.price" value="%{prodcut.price}" theme="simple"/>
                      <br/>
                      Name: <s:label value="%{product.name}" theme="simple"/> 

                  </td>

                  <td>
                      <s:textfield name="item[%{#cur.index}].product.price2" 
                                   id="item[%{#cur.index}].product.price2" 
                                   value="%{product.price2}" theme="simple"/>
                  </td>

                  <td><s:label value="%{name}" theme="simple"/> </td>
                  <td><s:label value="%{time}" theme="simple"/> </td>

            </tr>
         </s:iterator>
       </tbody>
       </table>        
    <input id="edit" type="submit" name="action" value="Edit"/>
 </form>

控制台错误

   ognl.OgnlException: source is null for getProperty(null, "0")

浏览器错误

java.lang.NullPointerException

com.myproject.controller.Baskets.edit(Baskets.java:100)

第100行如下

 System.err.println("item>>>" + this.basket.getItems().get(0).getProduct().getPrice());

HTML

 <form name="edit" method="POST" action="edit">
    <table border="4">
           <thead><td>Product</td><td>Price 2</td><td>User</td><td>Time</td></thead>
                <tbody>
                  <tr>
                    <input type="hidden" name="item[0].id" value="16" id="item[0].id"/>
                    <td>Price : <input type="text" name="item[0].product.price"    
                                   value="55" id="item[0].product.price"/>
                        <br/>
                       Name: <label id="">Product 1</label> </td>

                   <td><input type="text" name="item[0].product.price2" value="1000" 
                                          id="item[0].product.price2"/></td>

                            <td><label id="">User1</label> </td>
                            <td><label id="">9:31:03 AM</label> </td>

                  </tr>

                <tr>  
                   <input type="hidden" name="item[1].id" value="17" id="item[1].id"/>
                   <td>Price : <input type="text" name="item[1].product.price" 
                                  value="60" id="item[1].product.price"/>
                    <br/>
                                Name: <label id="">Product 2</label> </td>

                   <td><input type="text" name="item[1].product.price2" value="1000" 
                             id="item[1].product.price2"/></td>

                            <td><label id="">User1</label> </td>
                            <td><label id="">11:25:55 AM</label> </td>

                </tr>

                </tbody>
            </table>
            <label id="balance"></label>        
            <input id="edit" type="submit" name="action" value="Edit"/>
        </form>
4

1 回答 1

1
<s:textfield id="item[ {#cursor.index}].product.price" 
                               name="item[%{#cursor.index}].product.price" 
                               value="%{product.price}" /> 

好像漏掉了%basket.item请指正

<s:textfield id="basket.item[%{#cursor.index}].product.price" 
                               name="basket.item[%{#cursor.index}].product.price" 
                               value="%{product.price}" /> 
于 2013-10-29T02:39:07.960 回答