0

I am working on a Spring application which has a JSP page. In one single JSP page, I have 3 actions. Out of them 2 actions don't require any parameter and the third one has a static parameter(/note/list/1234), 1234 being the static parameter.

If I call any of the 2 functions, the third function should use the static parameter and execute. Instead of that it calls /note/list/0. I have no idea why. I am posting the JSP file below. Kindly have a look.

Note.JSP

<h1>
    Add notes
</h1>

<c:url var="addAction" value="/note/add" ></c:url>
<form:form action="${addAction}" commandName="notices">
    <table>
        <c:if test="${!empty notices.notetext}">
            <tr>
                <td>
                    <form:label path="noticesid">
                        <spring:message text="noticesid"/>
                    </form:label>
                </td>
                <td>
                    <form:input path="noticesid" readonly="true" size="8"  disabled="true" />
                    <form:hidden path="noticesid" />
                </td>
            </tr>
        </c:if>
        <tr>
            <td>
                <form:label path="notetext">
                    <spring:message text="notetext"/>
                </form:label>
            </td>
            <td>
                <form:input path="notetext"  />
            </td>
        </tr>
        <tr>
            <td>
                <form:label path="notetag" >
                    <spring:message text="notetag"/>
                </form:label>
            </td>
            <td>
                <form:input path="notetag"/>
            </td>
        </tr>
        <tr>
            <td>
                <form:label path="notecolor">
                    <spring:message text="notecolor"/>
                </form:label>
            </td>
            <td>
                <form:input path="notecolor" />
            </td>
        </tr>

        <tr>
            <td>
                <form:label path="canvasid">
                    <spring:message text="canvasid"/>
                </form:label>
            </td>
            <td>
                <form:input path="canvasid" />
            </td>
        </tr>

        <tr>
            <td>
                <form:label path="sectionid">
                    <spring:message text="sectionid"/>
                </form:label>
            </td>
            <td>
                <form:input path="sectionid"  />
            </td>
        </tr>

        <tr>
            <td>
                <form:label path="canvasnName">
                    <spring:message text="canvasnName"/>
                </form:label>
            </td>
            <td>
                <form:input path="canvasnName"  />
            </td>
        </tr>


        <tr>
            <td colspan="2">
                <c:if test="${!empty notices.noticesid}">
                    <input type="submit"
                           value="<spring:message text="Edit note"/>" />
                </c:if>
                <c:if test="${empty notices.notetext}">
                    <input type="submit"
                           value="<spring:message text="Add note"/>" />
                </c:if>
            </td>
        </tr>
    </table>
</form:form>
<br>

<h3>Notes List</h3>
<c:url var="listAction" value="/note/listing" ></c:url>
 <form:form action="${listNotes}" commandName="notices" method="post">
<c:if test="${!empty notices.noticesid}">
    <table class="tg">
        <tr>
            <th width="80">Notes ID</th>
            <th width="120">Notes text</th>
            <th width="120">Note Tag</th>
            <th width="120">Note color</th>
            <th width="120">Note section</th>
            <th width="120">Canvas id</th>
            <th width="120">Canvas name</th>
            <th width="120">Other id</th>
            <th width="60">Edit</th>
            <th width="60">Delete</th>
        </tr>
        <c:forEach items="${listNotes}" var="notices">
            <tr>
                <td>${notices.noticesid}</td>
                <td>${notices.notetext}</td>
                <td>${notices.notetag}</td>
                <td>${notices.notecolor}</td>
                <td>${notices.sectionid}</td>
                <td>${notices.canvasid}</td>
                <td>${notices.canvasnName}</td>
                <td>${notices.personid}</td>
                <td><a href="<c:url value='/editnote/${notices.noticesid}' />" >Edit</a></td>
                <td><a href="<c:url value='/removenote/${notices.noticesid}' />" >Delete</a></td>
            </tr>
        </c:forEach>
    </table>
</c:if>
</form:form>

<c:url var="listAction" value="/note/list/2323" ></c:url>  // This method here calls /note/list/0
<form:form action="${listNotes}" commandName="notices" method="post">
    <c:if test="${!empty notices.noticesid}">
        <table class="tg">
            <tr>
                <th width="80">Notes ID</th>
                <th width="120">Notes text</th>
                <th width="120">Note Tag</th>
                <th width="120">Note color</th>
                <th width="120">Note section</th>
                <th width="120">Canvas id</th>
                <th width="120">Canvas name</th>
                <th width="120">Other id</th>
                <th width="60">Edit</th>
                <th width="60">Delete</th>
            </tr>
            <c:forEach items="${listNotes}" var="notices">
                <tr>
                    <td>${notices.noticesid}</td>
                    <td>${notices.notetext}</td>
                    <td>${notices.notetag}</td>
                    <td>${notices.notecolor}</td>
                    <td>${notices.sectionid}</td>
                    <td>${notices.canvasid}</td>
                    <td>${notices.canvasnName}</td>
                    <td>${notices.personid}</td>
                    <td><a href="<c:url value='/editnote/${notices.noticesid}' />" >Edit</a></td>
                    <td><a href="<c:url value='/removenote/${notices.noticesid}' />" >Delete</a></td>
                </tr>
            </c:forEach>
        </table>
    </c:if>
</form:form>
</body>
</html>

Controller :

@RequestMapping(value = "/note/list/{id}", method=RequestMethod.GET)
public String listNotes(@PathVariable int id,Model model) {
    System.out.println("Did we reach in noteslist");
    System.out.println("Section id is"+id);  // returns zero on first execution unless called manually with /note/list/{number}
    Person person = personService.getCurrentlyAuthenticatedUser();
      model.addAttribute("person", new Person());
    model.addAttribute("listPersons", this.personService.listPersons());
    model.addAttribute("listNotes",this.notesService.listNotesBySectionId(id,person));
    return "note";
}

What can I do that it will get called with the proper URL i.e /note/list/1234 even if I call /note/add. Any help would be nice. Thank you.

We are Borg
  • 5,117
  • 17
  • 102
  • 225
  • possible duplicate of [Passing parameters from jsp to Spring Controller method](http://stackoverflow.com/questions/26652679/passing-parameters-from-jsp-to-spring-controller-method) – Roman C Oct 30 '14 at 20:53
  • @RomanC Problem is a bit different now. – We are Borg Oct 31 '14 at 07:55

0 Answers0