You need to sign in to do that
Don't have an account?
Display <div> element if value in string set
My company runs events and sells stands at those events, and I would like to implement a feature which allows the sales teams to see which stands have been sold and which haven't. However, given that I am still trying to learn Visualforce and Apex through trial and error, I am finding it difficult to implement the 'reserved or vacant' part of this solution.
So far I have a visualforce page where the background is set to an image of the venue floorplan. Each stand is overlayed with a <div> element, where the background image of the <div> is a red diagonal line with a transparent background (indicating that stand is reserved).
So the code looks something like this:
<apex:page renderAs="pdf" standardController="Issue_Year__c" extensions="FloorplanSet"> <head> <style type="text/css"> @page { size: A4 landscape; } body { background-image:url("https://c.cs2.content.force.com/servlet/servlet.FileDownload?file=015R0000000AdVD"); background-repeat:no-repeat; } .med { position:absolute; float:left; background-image:url("https://c.cs2.content.force.com/servlet/servlet.FileDownload?file=015R0000000Ae5R"); background-repeat:no-repeat; height:20px; width:20px; } </style> </head> <body> <div style="position:relative;"> <div id="60" class="med" style="top:8.54cm; left:7.05cm;"></div> </div </body>
Obviously, I only want the red diagonal line to display when the stand number is reserved, so I need an Apex Class to get the list of reserved stands. I can then check if each stand number is in the list, and change the visibility of each <div> accordingly.
This class currently looks like this:
public class FloorplanSet { private final Issue_Year__c evis; private Set<String> stand; public FloorplanSet(ApexPages.StandardController stdController) { this.evis = (Issue_Year__c)stdController.getRecord(); } public Set<String> getStand() { for (Stand__c sta :[SELECT Name FROM Stand__c WHERE Event_Issue__c = :evis.Id AND Status__c = 'Reserved']){ stand.add(sta.Name); } return stand; } }
What I am having difficulty doing is retrieving the list of stand numbers ({!stand}) and seeing if the stand number for each <div> (which is also the id for the div, i.e. '60') is present in that list.
For testing purposes, I have tried simply adding {!stand} into the Visualforce page, and though it saves, I get the following error when I try to load the page:
common.apex.runtime.impl.ExecutionException: Attempt to de-reference a null object
Hope someone can help.
I've only gone and done it!
Visualforce:
Apex: