Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
995 views
in Technique[技术] by (71.8m points)

hibernate - org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'chargesName' cannot be found on null

My project based on spring boot,Thymeleaf,mysql,html and Jquery.

My scenario is to Get the List iterate and show the data in the table 1st column in the HTML and post the data (html-chargesName and input amount) which is getting from the dynamic input fields and save it into related columns,so it will need to the hit spring boot @RestController.

But I got Thymeleaf ERROR like

org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'chargesName' cannot be found on null

Here is Full Code...

/**
 * This is for set charges form
 */

$(document).ready(function() {
 $("select").change(function() 
 {
    var amttype = $(this).val();
    if (amttype == 1) 
    {
      $("#amt1").show();
      $("#amt2").hide();
      $("#amt3").hide();
      
    } 
    else if (amttype == 2) 
    {
      $("#amt1").hide();
      $("#amt2").show();
      $("#amt3").hide();
    } 
    else if (amttype == 3) 
    {
      $("#amt1").hide();
      $("#amt2").hide();
      $("#amt3").show();
    }
    else {
      $("#amt1").hide();
      $("#amt2").hide();
      $("#amt3").hide();
    }
    
  });

});
    <!DOCTYPE html>
    <html xmlns:th="http://www.thymeleaf.org">
    <head>
    <meta charset="ISO-8859-1">
    <title>Insert title here</title>
     <!-- bootstrap css lib --> 
          <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    </head>
    <body>
    <!-- Bootstrap/Jquery CDN library files -->
    <script src="https://code.jquery.com/jquery-3.2.1.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <!-- External JQuery Script -->
    <script type="text/javascript" src="../js/formjs/setchargesform.js"></script>
    
    <!-- Body Content Goes Here -->
     <div class="container">
    <form method="post" th:object="${entSetCharges}" th:action="@{/updatesetcharges}">
    <div class="table-responsive"> 
    
    <table class="table table-hover">
    <thead>
        <tr>
          <th>Charge Name</th>
          <th>Amount</th>
          <th>Charge/Unit Type</th>
        </tr>
        </thead>
        
        <tbody>
        <tr th:each="savedcharges:${savedchargeslist}">
          <td>
          <label th:text="${savedcharges.chargesName}" th:value="${savedcharges.chargesName}" th:field="*{chargesName}"></label>
          </td>
          
          <td>
          <input id="amt1" class="form-control" th:field="*{perFlat}">
          <input id="amt2" class="form-control" th:field="*{perUnit}">
          <input id="amt3" class="form-control" th:field="*{perSqrft}">
          </td>
          
          <td>
    <select id="societyname" class="form-control" th:field="*{tempunitType}">
    <option value="1" selected="selected">perFlat</option>
    <option value="2">perUnit</option>
    <option value="3">perSqrft</option>
    </select>
          </td>
        </tr>
        </tbody>
        
    </table>
    </div>
    
    <button type="submit" class="btn btn-info">Submit</button>
    <button type="reset" class="btn btn-warn">Reset</button>
    </form>
    </div>
    <!-- Body content finishes -->
    </body>
    </html>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

1 Answer

0 votes
by (71.8m points)

You used the form at the top of your html page:

<form method="post" th:object="${entSetCharges}" th:action="@{/updatesetcharges}">

The th:field="*{chargesName} is bound to the object/bean inside your th:object="${entSetCharges}. Meaning that you are searching for a chargesName field inside your entSetCharges object which does not exist or is null.

Solution:

  • Maybe change your th:field="*{chargesName}" to ${savedcharges.chargesName} expression to access your object's field.

  • Try adding respondResult.addObject("entSetCharges",new EntSetCharges()); above your return line. Your view doesn't automatically create this object for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
...