JSTL loop through Array to NOT display content - arrays

I'd like to use an "Array" in JSTL that looks like this
<c:set var="hideMe" value="${['A','B','C','D']}" scope="application" />
I also have a global VAR called ${checkPageName} which has the name of the current page I am on in it, so I can check against it, as part of the logic (e.g. <c:if test="${checkPageName != hideMe}"> ... </c:if>)
The logic behind this is that if A, B, C or D exist then I will prevent a specific piece of information from being displayed to the user.
Does anyone know how I loop through a JSTL array?
The logic should then decide that if A, B, C or D DO NOT exist, then we display specific information to the user.
I have tried;
<c:forEach items="${hideMe}">
<c:set var="hide" value="true" />
</c:forEach>
<c:if test="${hide != 'true'}">
<div class="showMe">
<h1>Hello Sweetie</h1>
</div>
</c:if>
Could someone please point me in the right direction?
UPDATE: I have now fixed this myself using <c:forTokens>, see the solution below

So I figured it out in the end;
<c:set var="hideMe" value="false" />
<c:forTokens items="A,B,C,D" delims="," var="excludeDisplay">
<c:if test="${checkPageName == excludeDisplay}">
<c:set var="hideMe" value="true" />
</c:if>
</c:forTokens>
<c:if test="${hideMe == 'false}">
DO SOMETHING
</c:if>
checkPageName is a global variable I am checking against in my code to validate well, page names...
So I set a default VAR called hideMe with a value of false, I then use forTokens to create a VAR called excludeDisplay for values A, B, C or D.
I then check these values against my global variable and if they match overwrite the var hideMe with a value of true, this is then used to trigger the content I want to show. If the VAR is false show the content, if it is true, do nothing.
I hope this helps someone else, and I am happy to elaborate on some of the murkier points if anyone wants any more information...

Related

bootsfaces selectMultiMenu don't show selected values

I want to pre-charge a selectMultiMenu with values I already have in the application.
For example:
<b:panelGrid colSpans="2,2,8">
<h:outputLabel value="Traffic light color" />
<b:selectMultiMenu value="#{semaphoreBean.color}" >
<f:selectItems value="#{semaphoreBean.colors}" var="c" itemValue="#{c}" itemLabel="#{c}"/>
</b:selectMultiMenu>
</b:panelGrid>
if var color = "green, red" before than I load the page, I don't see in my selectMultiMenu 2 items selected.
¿What do I have to do to pre-load that field with those values?
Maybe that's because of the space between the entries. I take it you've take the example from our showcase. So I've added this line to our showcase, and it works like charm:
private String color = "green,red";
Finally I found out data format was wrong so I fix it and works.
Thank you for helping.

Do anyone has the source caman js example on site?

I am trying to create the functionality like this page url : http://camanjs.com/examples/ for image filters.
I have tried with this code.
var img_map = Caman("#test-canvas", "../images/test1_640.jpg");
//update brightness
function update_brightness(value){
//img_map.revert();
img_map.brightness(value).render();
}
//update contrast
function update_contrast(value){
//img_map.revert();
img_map.contrast(value).render();
}
The changes on image are not like the site i am refering.
The main issue is when i increase any control then it works fine. But when I try to decrease the control value then it does not work.
To control the value for brightness or contrast i have used "range" input.
<img id="test-image" src="../images/test1_640.jpg" />
<canvas id="test-canvas"></canvas>
brightness
<input onchange="update_brightness(this.value);" type ="range" min ="-100" max="100" step ="10" value ="0"/>
contrast
<input onchange="update_contrast(this.value);" type="range" min="-100" max="100" step="" value="0">
EDIT: I just compiled the coffeescript out to JavaScript and put it in a repo of my own for (hopefully) easier use:
https://github.com/nbieber/CamanJS-example
You can find the original source here: https://github.com/meltingice/CamanJS-Site/blob/master/_assets/javascripts/examples.js.coffee
It's in coffeescript, though.
You can add
this.revert(true);
in your update_brightness and update_contrast functions.
function update_brightness(value){
//img_map.revert();
this.revert(true);
img_map.brightness(value).render();
}

c:foreach inside h:datatable to show two dimensional array

I am trying to use h:datatable tag to display values of two-dimensional int array. But cannot make it. Could help me with a solution?
So my backing bean is:
public class MC {
...........
public int[][] getAr() {
return ar;
}
public int getColCount(){
return ar[0].length;
}
}
I can display the array with code in foreach tag referring to the array size:
<h:dataTable value="#{mC.ar}" var="dt">
<c:forEach var="fe" begin="0" end="#{mC.colCount-1}">
<h:column>
<f:facet name="header">X</f:facet>
#{dt[fe]}
</h:column>
</c:forEach>
</h:dataTable>
But nothing is printed if I try to use variable from dataTable:
<h:dataTable value="#{mC.ar}" var="dt">
<c:forEach var="fe" items="#{dt}">
<h:column>
<f:facet name="header">XX</f:facet>
#{fe}
</h:column>
</c:forEach>
</h:dataTable>
Could you help me to make it work? Or perhaps you could suggest some better solution to display an array? Thank you
There is quite common mistake done in assumption that c:forEach is processed in the same time the iteration of dataTable is processed. c:forEach is processed once in build JSF tree, in this phase there is NO "dt" variable defined. h:dataTable defines the "dt" variable in JSF restore/render phases. Use the ui:repeat instead of c:forEach if you need to iterate in this phases.

Using Perl to get Checked and put VALUE in an array

I'm new to Perl and trying to check to see if a series of checkboxs on an HTML page are checked or not. Each checkbox has a different numeric value I want to add to an array in Perl. I keep getting an undef value. I've combed the web for a reason this is not working and finally broken down to ask for help. For now I just want to display the values retrieved in my log. I'm expecting to see (1, 2) in my results when the checkbox is checked. Can anyone see anything wrong with the code below or offer a suggestion as to why I'm getting an "undefined" array? Is there a way to test for connection to the checkbox in question from Perl?
HTML:
<input type="checkbox" name="Shipping" id="checkFXG" value="1" enabled />
<input type="checkbox" name="Shipping" id="checkFX2" value="2" enabled />
PERL:
use CGI;
...
sub updateShipping;
my $p;
my $self = shift;
my $cgi;
my $sIDquery = CGI->new;
my $param = $sIDquery->Vars;
my #sID = $param->{'Shipping'}; # Grab VALUE from checkbox
my $sID;
foreach $sID(#sID) { # Loop through array displaying each Shipping ID
warn "**** sID : [$sID]";
}
}
To get multiple parameters with the same name, don't use the Vars method, do:
my #values = $sIDquery->param('Shipping');
There are very few cases where you'd ever want to use Vars. It is especially unlikely to do what you want for parameters that may not be present (such as checkboxes) or may have more than one value.

JSTL <c:set> body content exact specification

can someone suggest how possible to interpret <c:set> body?
<c:set var="movieList">One,Two,Three</c:set>
<c:set var="movieList">"One","Two","Three"</c:set>
in the first case movieList is a string and in the second it is an array {"One", "Two", "Three"}
what is movieList in these examples:
<c:set var="movieList">"On"e","Tw"o","Thr"ee"</c:set>
<c:set var="movieList">"On\"e","Tw"o","Thr\"ee"</c:set>
There's no difference in the interpreted Java type of the c:set's body. It are in all cases just String.
Even when you set a non-String type as c:set's body using EL such as
<c:set var="foo">${bean.someInteger}</c:set>
it'll be converted to String anyway by String#valueOf().
Only when you process the variable afterwards, there may be difference, depending on how you processed it. For example,
<c:set var="movieList">One,Two,Three</c:set>
<c:set var="realMovieArray" value="${fn:split(movieList, ',')}" />
will result ${realMovieArray} being a String[] with values of One, Two and Three.
<c:set var="alphabet">A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z</c:set>
<c:forTokens items="${alphabet}" delims="," var="letter">
${letter}
</c:forTokens>

Resources