Expand my Community achievements bar.

Converting JSP to HTML (HTL)

Avatar

Level 1

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.

6 Replies

Avatar

Level 9

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!

Avatar

Level 1

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;
	}

 

 

Avatar

Level 9

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-thr...

 

Hope it helps!

Avatar

Community Advisor

@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>

Avatar

Level 1

This part of the code is coming up blank:

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

 

Any ideas how to fix it?

Avatar

Administrator

@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