user5783530
user5783530

Reputation: 251

Pass javascript variable to jstl tags

I need to change (parse) one of the object property. Is it any way I can save the parse value in the js variable and then pass it back. This is what I tried but it does not work:

    <c:forEach var="user" items="${requestScope.users}">
       var parsedName= parseUserName("${user.name}");
       <c:set target = "${user}" property = "parsedName" value ="${parsedName}"/>  
    </c:forEach>

Upvotes: 0

Views: 6097

Answers (3)

Shinto Anto
Shinto Anto

Reputation: 41

If possible try to implement the parseUserName() logic in JSP itself using JSTL.

If you need help with that post the JS method logic here.

Upvotes: 0

The Cloud Guy
The Cloud Guy

Reputation: 982

No it is not possible to do what you are trying to do. The only possible solution is to send the variable to the server using a partial refresh and set the required property once the page has been refreshed

Upvotes: 2

devops
devops

Reputation: 9179

Your idea is:

<c:forEach var="user" items="${requestScope.users}">
    <script type="javascript">
        var parsedName= parseUserName("${user.name}");
    </script>
    <c:set target = "${user}" property = "parsedName" value ="${parsedName}"/>
</c:forEach>

unfortunately it is not possible.

The jstl code happen on the server side and javascript on the client side.

Upvotes: 2

Related Questions