Converting JSP to HTML (HTL) | Community
Skip to main content
August 18, 2023

Converting JSP to HTML (HTL)

  • August 18, 2023
  • 3 replies
  • 1837 views

JSP code
<c:set var="roomdetails" value="${roomcontroller.roomDetailsfromRequest}" />
<c:set var="code" value="${roomcontroller.roomCode}" />
<c:set var="matched_room" value="${roomdetails[code]}" /> (variables above)

Returns the following values:
roomdetails:{A2-ET=url.models.hotelreservation.Room@name1, W1-
ET=url.models.hotelreservation.Room@name2}

code: W1-ET

matched_room: url.models.hotelreservation.Room@name2


HTL:
<sly data-sly-set.roomdetails="${roomcontroller.roomDetailsfromRequest}" />
<sly data-sly-set.code="${roomcontroller.roomcode}" />
<sly data-sly-set.matched_room="${roomdetails['code']}" /> (variables above)
also tried:
<sly data-sly-set.matched_room="${roomdetails[code]}" /> (variables above)

Returns the following values:
roomdetails:{A2-ET, W1-ET}. (any data after the "=" is not showing up, although in the java when I log the output, I'm getting the full return as above)

code: W1-ET

matched_room: (nothing)

 

The Java is the same in both for these and is producing the same data output.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

sherinregi-1
Community Advisor
Community Advisor
August 18, 2023

hi @maui1 

can you try using map here in sightly

<sly data-sly-set.code="${roomcontroller.roomcode}" />
//iterate over the map object in list and then find the matched room and set to matched room
<sly
data-sly-list="${roomcontroller.roomDetailsfromRequest}"> <sly data-sly-set.matched_room= "${roomcontroller.roomDetailsfromRequest[code]}"/> </sly>

 Hope it helps!

maui1Author
August 18, 2023

I really appreciate you looking into this for me.

 

When I turn the set into the list, the value is then blank:

<sly data-sly-list="${roomcontroller.roomDetailsfromRequest}">


If I keep it as data-sly-set with the above code, it still is blank. Probably due to the Java?

 

 

public Map<String, Room> getRoomDetailsfromRequest() { Map<String, Room> roomSearchOutput = null; if (null != slingHttpServletRequest.getAttribute(USER_ROOM_RESPONSE)) { roomSearchOutput = (Map<String, Room>) slingHttpServletRequest.getAttribute(USER_ROOM_RESPONSE); } return roomSearchOutput; }

 

 

sherinregi-1
Community Advisor
Community Advisor
August 18, 2023

hi @maui1 

Can you try the below link sightly code. From the java code i can see that its a map of string and object . So the iteration like in the below link should work

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/sightly-how-to-iterate-through-map-lt-string-object-gt/m-p/271415

 

Hope it helps!

Sudheer_Sundalam
Community Advisor
Community Advisor
August 18, 2023

@maui1 

Based on the variables values the HTL file is printing out, Try the below code:

<sly data-sly-set.code="${roomcontroller.roomcode}" /> //iterate over the map object in list and then find the matched room and set to matched room <sly data-sly-list.roomsMapKey="${roomcontroller.roomDetailsfromRequest}"> <sly data-sly-test = "${code == roomsMapKey}"> <sly data-sly-set.matched_room= "${roomcontroller.roomDetailsfromRequest[roomsMapKey]}"/> </sly> </sly>
maui1Author
August 24, 2023

This part of the code is coming up blank:

 <sly data-sly-set.matched_room= "${roomcontroller.roomDetailsfromRequest[roomsMapKey]}"/>

 

Any ideas how to fix it?

kautuk_sahni
Community Manager
Community Manager
September 18, 2023

@maui1 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni