Hi team,
I have a requirement where in we should not load the launch based on the <xxx> = true parameter value.
we are loading launch as below :
Solved! Go to Solution.
Views
Replies
Total Likes
Below implementation working for me as expected.
Sling Model:
@Model(adaptables = {Resource.class, SlingHttpServletRequest.class})
public class DemoModel {
@SlingObject
SlingHttpServletRequest request;
private String launchEnabled = "false";
public String getLaunchEnabled() {
if (request.getParameter("launchDisabled") == null || request.getParameter("launchDisabled").equalsIgnoreCase("false"))
launchEnabled = "true";
return launchEnabled;
}
}
HTL:
<div data-sly-use.demo="com.blogspot.adapttoaem.core.models.DemoModel">
<sly data-sly-test="${demo.launchEnabled == 'true'}">
<p>Launch Enabled</p>
</sly>
</div>
Below implementation working for me as expected.
Sling Model:
@Model(adaptables = {Resource.class, SlingHttpServletRequest.class})
public class DemoModel {
@SlingObject
SlingHttpServletRequest request;
private String launchEnabled = "false";
public String getLaunchEnabled() {
if (request.getParameter("launchDisabled") == null || request.getParameter("launchDisabled").equalsIgnoreCase("false"))
launchEnabled = "true";
return launchEnabled;
}
}
HTL:
<div data-sly-use.demo="com.blogspot.adapttoaem.core.models.DemoModel">
<sly data-sly-test="${demo.launchEnabled == 'true'}">
<p>Launch Enabled</p>
</sly>
</div>
Thanks @anudeep_Garenepudi
Yes we have Page model and i was trying to do this via :
Views
Replies
Total Likes
If you want to compare Strings then ${varOne == varTwo} returns true if varOne and varTwo are equal. Or try changing launchEnabled type from String to boolean. Check the docs
Try:
<sly data-sly.test="${pageTrail.launchEnabled == 'true'}"> ... </sly>
@Anudeep_Garnepudi- I tried as suggested but it is still not working .
public boolean getlaunchEnabled() {
return !(Boolean.parseBoolean(request.getParameter("launchDisabled"))) ;
} and
html
<sly data-sly.test.launchEnabled="${pageTrail.launchEnabled'}"
@Anudeep_Garnepudi- when i tried above code <p> is always getting displayed as data-sly-test is checking if launchEnabled is having value or not. So i added a condition check and changed launchDisabled from boolean to String but somehow it is still not working.
public String getLaunchEnabled()
{
if (request.getParameter("launchDisabled") == null)
launchEnabled = "true" ;
return launchEnabled;
}
HTML :
<sly data-sly.test.launchEnabled="${pageTrail.launchEnabled == 'true'}" data-sly-call="${headlibRenderer.headlibs @ designPath = page.designPath, staticDesignPath = page.staticDesignPath, clientLibCategories = page.clientLibCategories, clientLibCategoriesJsHead = page.clientLibCategoriesJsHead, hasCloudconfigSupport = page.hasCloudconfigSupport}"> </sly>
Thanks for your help in advance.
@Anudeep_Garnepudi- I tried as suggested but it is still not working . I am able to see the launch Enabled in both the cases . https://<xx> and https://<xx>/?launchDisabled=true
I tried exactly same code as u mentioned above ;
@SlingObject. -- as @Self is giving error i am using @SlingObject
private SlingHttpServletRequest request;
private String launchEnabled;
public String getLaunchEnabled() {
if (request.getParameter("launchDisabled") == null)
return "true";
return "false";
}
HTML
<sly data-sly-test="${pageTrail.launchEnabled == 'true'}">
<p>Launch Enabled </p>
</sly>
not sure what is going wrong.. I tried almost all possible combinations
@Anudeep_Garnepudi- One observation if from Model i return false then in all cases i dont see the Launch Enabled . If i return true , i always see. Here is my code.
Please check similar question which is already answered at [1]
@Jaideep_Brar- No still not working. I tried as
Model code
@SlingObject
private SlingHttpServletRequest request;
private String launchEnabled;
public String getLaunchEnabled() {
if (request.getParameter("launchDisabled") == null)
return "true";
return "false";
}
html
<sly data-sly-test="${pageTrail.launchEnabled == 'true'}">
<p>Launch Enabled </p>
</sly>
This is getting displayed always
Views
Likes
Replies
Views
Like
Replies