Help with forEach loop
I have a JSTL forEach loop similar to below:
<c:forEach var="product" items="${sessionScope.products}">
<tr><td>${product.description}</td></tr>
</c:forEach>I would like to use a static class to format the description. Something like below, but I know I cannot do it this way. How can I accomplish this?
<tr><td>${ProductFormatter.getHtmlDescription(product)}</td></tr>thanks
The least change approach. If you have already have a static function to do this, then a function tag would be appropriate.
The function tag basically lets you call a static function from EL.
custom.tld
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-
jsptaglibrary_2_1.xsd" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1"
>
<tlib-version>1.0</tlib-version>
<short-name>my</short-name>
<uri>http://www.mytags.com/</uri>
<function>
<name>productFormatter</name>
<function-class>com.mypackage.ProductFormatter</function-class>
<function-signature>java.lang.String getHtmlDescription(com.mypackage.Product)</function-signature>
</function>
</taglib>If you include that tld in your WEB-INF directory, then the following in a JSP should work:
<%@ taglib uri="http://www.mytags.com/" prefix="my"%>
<c:forEach var="product" items="${sessionScope.products}">
<tr><td>${my:productFormatter(product)}</td></tr>
</c:forEach>Rather than putting the code in a static function, you might be better off encoding the logic into a custom tag. It depends on what your formatting function is like.
cheers,
evnafets
Similar Messages
-
do{
if((orderType != 'g') || (orderType != 'w')){
System.out.println("Please enter g or w only.");
}while((orderType == 'g') || (orderType == 'w'));
I need help with this loop... I have to make sure it will be able to pop the input back after the invalid input... i tried to fix it...wont stop and stay in same loop till it gets the valid before go to other loop... how? am i missing something?I know you've already been answered, but just a bit more...
if((orderType != 'g') || (orderType != 'w'))That would always be true. All characters are either not equal to 'g' or not equal to 'w'.
'x' : neither 'g' nor 'w'. Evaluates to true.
'g' : not 'w', still evaluates to true.
'w': not 'g', still evaluates to true. -
Im trying to create a while loop that outputs the revers of a string, eg nice one
would be "eno ecin" Assuming i already have declared a variable intital string that holds the string, how do i go about this does anyone have any problem solving techniques. The charAt method needs to be used.i have a exam on saturday and it was a previous exam question that im trying to get help with i need to understand the course material thanks, i know how to use while loops but have trouble getting my head around this question. ill show you my code however i know its completely wrong.
now i know i hvae to use the charAt method to return a character located at the integer i
so i must go down after each case has been tested true therefore i want i=i-1;
until i=0;
String initialString="tucan";
int i=initialString.length();
while(i>0)
return charAt();
i=i-1;
} -
Power-shell distribution list update Managedby with foreach loop
The script function is to find a user that is listed a a manager/owner on a distribution list and then replace that manager. The issue is I'm unable to replace the manager when they are a owner/manager of multiple distribution list. The script is successful
if I remove the foreach loop and just run the script on one distribution list. Please see error message below. Any help is appreciated.
$user = "eharris"
#$DLSimilarmgr = "harris, aaron m"
$username = (get-aduser $user).name
$listDLgroup = get-distributiongroup -resultsize unlimited | where {$_.managedby -like "*$username*"} |fl name
$Foreach ($GrpDL in $listDLgroup) {
$listDLManager = $GrpDL.ManagedBy
$NewDLManager = get-user -id "aharris"
$listDLManager+= $NewDlManager
set-distributiongroup $GrpDL -managedby $listDLManager -BypassSecurityGroupManagerCheck
Aaron Harris ExchangeSharePointGuyHaving issue combing the two scripts. The first scripts gets the DL managers. The second script will update the managed by field of the users and the previous managers of the DL. However, I don't know how to update a multiple DL when the user is listed as
a manager of more than 1 DL at a time. In script 2 I would like to update the multiple return value for script 1. Any help would be appreciated.
#script 1 list the dl's the users is a manager of
$user = "eharris"
$username = (get-aduser $user).name
$listDLgroup = get-distributiongroup -resultsize unlimited | where {$_.managedby -like "*$username*"} |fl name
#Script 2 working gets the dl and adds the new member and the previous members of that DL
$GrpDL = Get-DistributionGroup -id "#365DLTest"
$listDLManager = $GrpDL.ManagedBy $NewDLManager = get-user -id "eharris"
$listDLManager+= $NewDlManager set-distributiongroup "#365DLTest" -managedby $listDLManager -BypassSecurityGroupManagerCheck
Aaron Harris ExchangeSharePointGuy -
Need help with while loop format
I'm building a form - everything works but I would like to change the way the data is output into the table.
In other scripting languages, like PHP, you had 2 different ways of dealing with a loop:
<?
do while xyz
do something here
?>
- OR -
<? do while xyz:?>
do something here
<?end while ?>
I would like to do something similar to the 2nd example in .jsp but I'm not sure of the format or how to stop the loop. From the tutorial, I'm using
<%
while(SQLResult.next())
UId = SQLResult.getString("uid");
FName = SQLResult.getString("fname");
LName = SQLResult.getString("lname");
out.println("<tr><td>" + UId + "</td><td>" + FName + "</td><td>" + LName
+ "</td></tr>");
%>
Could anyone point me in the right direction? I'd prefer it if I didn't have to build the table like this if I don't have to but haven't found anything anywhere telling me otherwise.
Thanks so much.
BobSorry - the answer was in JSP:Java Server Pages by Barry Burd. I had just gotten the output format wrong.
-
Hi all, I have this annoying problem and I am looking for any suggestions.
I have 2 select boxes. One is for all available users, and second - for selected users (designated as admins). The list of all users is available in a collection (2 properties userId and userName displayed in the code below). The list of admins contains only userId (as strings).
I have no problem with populating selected users (admins) list, reusing pretty much the same logic below, but I cannot find a way to break out from the nested loop once the match is found, to avoid repetitions leading to incorrect display of results.
<select name=available>
<c:forEach items="${users}" var="user" varStatus="outer">
<c:forEach items="${adminIds}" var="adminId" varStatus="inner">
<c:if test="${user.userId!=adminId">
<option value="<c:out value="${user.userId}" />"><c:out value="${user.userFullName}"/></option>
</c:if>
</c:forEach>
</c:forEach>
</select>
<select name=selected>
<c:forEach items="${users}" var="user" varStatus="outer">
<c:forEach items="${adminIds}" var="adminId" varStatus="inner">
<c:if test="${user.userId==adminId">
<option value="<c:out value="${user.userId}" />"><c:out value="${user.userFullName}"/></option>
</c:if>
</c:forEach>
</c:forEach>
</select>Can anyone help, please? I am also restricted to JSP 1.2Double post: http://forum.java.sun.com/thread.jspa?threadID=707950&tstart=0
-
Please Help With A Loop Using Vectors?
I am developing a swing application and this loop has me completly stumped I have not worked with vectors alot, nut I have never seen this happen in a loop before:
I am just going to post the loop because that is where this problem is happening.
What I want to do is loop through CAT X amount of times and
have an inner loop for SUBCAT X amount of times.
fs is a formattedString class I have and eventually this text is appended to a JTextArea.
Here is the Loop:
Vector CAT = new Vector();
Vector SUBCAT = new Vector();
CAT = getCategories(Department);
for (int i=0; i<CAT.size(); i++){
String Category = CAT.elementAt(i).toString();
fs.append("\nCategory: ",11);
fs.append(Category,65);
SUBCAT = getSubCategories(Category);
}//End CATEGORY
The part where I am completely stumped is, if I comment out the SUBCAT= part then the Text displays fine. If I dont it will just display the first string in the CAT Vector I have done a try and catch to see if there is an exception being thrown but there is none. The getSubCategories() method works fine b/c it is working at other parts of my program. (It Returns a Vector BTW). So commenting it out should really make no difference.
Can anyone help me with this????
Thanks in advanceI will post what my output is in each scenario and maybe you can better understand what I am explaining:
SCENARIO 1::::::::::::::::::::::::::::
for (int i=0; i<CAT.size(); i++){
fs.append("\nCategory: ",11);
fs.append(CAT.elementAt(i).toString(),65);
}//End CATEGORY
Category: A Collars
Category: Access Door
Category: Aluminum
Category: Anchors Drop In
Category: Bits
Category: Blades
Category: Bolts, Nuts, Pins and Rivets
Category: Bolts, Nuts, Pins, and Rivets
Category: Canvas Connection
Category: Caps
Category: Caulking
Category: Copper
Category: Duct Mate
Category: Ells
Category: Flat Bar
Category: Flex Duct
Category: Galvanized
Category: Grills
Category: Insulation
Category: Iron
Category: Miscellaneous
Category: Pipe
Category: Reducers
Category: Return Air Panels
Category: Rings
Category: Rod
Category: Slide Gates
Category: Spin Ins
Category: Stainless Steel
Category: Stick On With Damper
Category: Tape
Category: TDC
Category: Tees
Scenario 2:::::::::::::::::::::::::::::::::
Category: A Collars
for (int i=0; i<CAT.size(); i++){
fs.append("\nCategory: ",11);
fs.append(CAT.elementAt(i).toString(),65);
SUBCAT = getSubCategories(CAT.elementAt(i).toString());
}//End CATEGORY
Now do you see:
The SUBCAT = getSubCategories(CAT.elementAt(i).toString()); should not be affecting the loop. It should just be assigning a new Vector to SUBCAT. I know that it is missing the inner loop in this example, but this is how I found out the loops where not working right. -
Hi
I've been at this for over 24 hours. I have a small video
clip which is embedded in DW and uploaded...
http://www.forpetsake.ca/about2.html
Originally I purchased this ,mov from istockphoto.com and
used QT pro to convert into a .flv. Once converted I brought it
onto the Flash stage. In published settings I selected the 'loop'
option and then exported out to a .swf. Once I embedded this .swf
into my DW page, I uploaded all to my server including the .html
created with the .swf, in fact I uploaded the .flv/.swf/.html into
a seperate folder on my server.
All I want to do is set this movie to loop, maybe pause for a
couple seconds before each loop.
I'm a simple person who only understands simple explanations.
Can someone please walk me through the steps in Flash CS3 to
get this short clip to loop.
ps" The Property Panel selectors (loop-autoplay) make no
changes whatsoever in DW CS3 with respect to this video.
Thanks in advance for any help you can provide.If you're importing the FLV file into a SWF file (which is
not recommended these days), then just add a gotoAndPlay(1) action
to a keyframe you add at the very end of your Flash timeline.
If, however, you use the FLVPlayback component, you can write
ActionScript to listen for the "complete" event and tell the video
to restart when that event is detected.
Also, use SWFObject (
http://blog.deconcept.com/swfobject)
to embed a SWF into your HTML document. Dreamweaver and Flash's
detection scripts aren't as good. (my two cents)
HTH. -
I'm a beginner. I'm trying to get this output
Initial number of stars:
7
Here's my program. What's wrong with it? Please help
import java.io.*;
class starWedge
public static void main (String[] args ) throws IOException
int numStars; // the number of stars
int row ; // current row number
int star; // the number of stars in this row so far
BufferedReader userin = new BufferedReader (new InputStreamReader(System.in));
String inputData;
// collect input data from user
System.out.println( "Initial number of stars:" );
inputData = userin.readLine();
numStars = Integer.parseInt( inputData );
row = 1;
while ( row <= numStars )
star = 1;
star = numStars - star;
System.out.print("*");
star = star + 1;
System.out.println(); // end each line
row = row + 1;Okay the one thing that I see immediately is that your while loop never actully exits. Not once. Why? Well simple your exit condition is the row <= numStars, yet nither numStars nor row actually change their values within the loop. In short row always equals 1 and thus never is equal to greater than numStars and the while loop does not terminate.
Second thing is that your star drawing logic is not correct. Meaning you have not told to draw the specific number of stars in one given line. For starters the System.out.println() command should be in the loop not outside it. For your purposes a for-loop nested within a while-loop is much better.
If you think you know what's wrong your program than read no further and go try it on your own. But if you still have no clue below is my modification of your code that actually produces the pattern you want, it might provide you with more hints.
import java.io.*;
class starWedge{
public static void main (String[] args ) throws IOException{
int numStars; // the number of stars
int row ; // current row number
int star; // the number of stars in this row so far
BufferedReader userin = new BufferedReader (new InputStreamReader(System.in));
String inputData;
// collect input data from user
System.out.println( "Initial number of stars:" );
inputData = userin.readLine();
numStars = Integer.parseInt( inputData );
row = 1;
while (numStars > 0){
for(star = 1; star<=numStars; star++){
System.out.print("*");
numStars = numStars - 1;
System.out.println(); // end each line
} -
Hello let me first explain what im trying to achive:
I want a moving square that you control with the arrow keys on the keyboard. It has to be smooth ie able to move fast without looking like its jumping and it has to be able to move diagonaly aswell. Think of that arcade game Raiden ...you know the birds-eye view plane flying game...another thing! I'd prefer if it didnt use timers - i made one already using 4 timers and it works great but 4 timers is a little extreme - SO NO TIMERS !
I was thinking while loops, but i cant seem to get it working. I dont want to put in all the code so ill just say that I have 4 booleans: up, down, left right and the following code:
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_UP) {
up = true;
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
down = true;
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
left = true;
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
right = true;
repaint();
For the KeyReleased part i have the same as above exept it sets the booleans to false.
Soooo in theory if i set up a while loop like this (using the up direction as an example) :
while (up == true) {
[move square up]
So therefore when i press and hold the up arrow the loop will keep going untill i realease it right? WRONG ! it just keeps repeating indefinatly and it doesnt even do the " [move square up] " bit. I put a System.out.print in the loop to test and it kept printing out the message but it still didnt do the actual " [move square up] " bit.
Im not sure if im putting the while loop in the right place either....If anyone has any idea on how to use while loops in this way please heeeelp ! Its so annoying because it just doesnt work ive tried so many ways...
any help would be greatly apreciated !!!!Maybe you want something like this? You have to pause during the loop to allow for other events to happen, like if y ou release a key or whatever.
while( true )
if( up ) moveUp();
else if( down ) moveDown();
if( left ) moveLeft();
else if( right ) moveRight();
try
Thread.currentThread().sleep(10);
catch( InterruptedException e )
System.out.println( "Thread interrupted!");
} -
Need help with while loop and shift registers
I have a large data set and need to read in the data at maybe 200 samples at a time, process these samples through my VI, and have it append and concatenate a separate lvm file. The part where I am confused is the shift registers. How do I limit the number of samples read in an iteration? How do I get the while loop to stop when all the data are read in?
I've attached my diagram, maybe there is something wrong with my technique?
Solved!
Go to Solution.
Attachments:
shiftreg.JPG 56 KBThis will give you an idea. There are plenty of other (probably more efficient) methods. This is a basic, quick and dirty solution to help you grasp the overall concept.
Using LabVIEW: 7.1.1, 8.5.1 & 2013
Attachments:
ShiftRegLoop.JPG 54 KB -
Need help with infinite loop in recovery mode in Creative Zen 20
hi,
I'm having this problem with my Creative Zen 20 GB:
When I turned it on, it goes immediately to the rescue/recovery mode. Not sure why. Will do that even when I reset the device.
So, I selected cleanup. After cleanup, it remained showing the menu of the recovery mode. I selected reboot. After reboot, it went back to the rescue/recovery mode. And it goes on and on like an infinite loop.
Finally, I decided to do a formatAll. Again, it remained in the recovery mode menu after the formatAll action. After reboot, it again went back to the rescue/recovery mode.
I have never updated the firmware. So, I thought maybe that will help. However, when I connected the device to my PC, the device went to rescue/recovery mode and the PC could not detect the device connected via USB. In short, I am currently not able to do anything at all with the device except charging it.
Would appreciate help/advise.
Tks in advance.huggiebear wrote:
I connected the device to the PC and after the PC tried to load the library, it said "Player is not connected".
What library are you loading? After you have run that reload os option, you need to connect the player to the computer and run the firmware update software. If you haven't download that, you can go to the download section and download it. If all else fail, the player is probably faulty and you would need to get in contact with Customer Support then.
Jason -
Weird Problem- Help With Logic Loops
Hi all,
I've been using Logic Express 8 for about 2 years and I've got a pretty good handle on things. However I keep having this small little problem and usually restarting the software fixes it, but not this time.
My problem is this: I'm trying to make some beats using software instruments. So I click on "Drums and Percussion" then "Ultrabeat" then choose my drum kit. I start punching in my beats but Logic is playing some Apple Loop on top of it! Theres no notes on the track and yet it still plays this random beat! I can adjust the tempo and the beat adjusts to it.
The problem is there is nothing there. Its a blank track, but this beat keeps playing.
I used to just restart the program when it happened and it usually took care of it, however it won't fix it this time.
I know it's probably some check box I don't have clicked or something but if someone could help me out, I'd be very appreciative.
Thanks,
JoshAh yes!
Thank you JG99!!!
I forgot to go into the Ultrabeat menu, and turn off the "example beat" that they give you. I knew it was some checkbox that I didn't unclick or click.
Thank you sir, you are a gentleman and a scholar. -
In the attached picture inside the red circle is where I need help. I'm trying to turn on 4 relays, it currently works but all the relays come on at the same time I need a 500ms pause between each relay and I can't seem to figure it out. I would assume some kind of for loop would work I'm just not sure how to index the "Fan 1 switch", Fan 2 switch","Fan 3 switch", Fan 4 switch" into an array.
Any help would be much appreciated
Thanks,
Attachments:
help1.jpg 251 KB
fanctrl_with_sound_detec1.vi 61 KBHere's one example, using just a numeric indicator as the state control. The State Machine is only slightly more involved.
This example also shows one way to use an array to set your booleans to True/False.
Good luck!
Message Edited by LabViewGuruWannabe on 01-28-2008 12:36 PM
Attachments:
RelaysON-OFF.vi 47 KB
RelaysON-OFF-BD.png 46 KB
RelaysON-OFF-FP.png 32 KB -
Sorry for the "Noob"-ness on this one. I am working on a program for class and I am having a problem with a while loop. So I opened a new document and began to code a while loop that is basic to test my while looping skill. Apparrently, I have none. Can anyone tell me why this While Loop will not work:
public class test
public static void main(String[] args)
int LoanTerm = 0;
while (LoanTerm < 3);
System.out.println (LoanTerm);
LoanTerm++;
Thanks.
FatherVicto explain, the ; means that the while loop body is empty, and you will just spin forever testing whether LoanTerm < 3, without doing anything else.
Maybe you are looking for
-
ITunes no longer links to photos?
I had a large photo library on an external hard drive - i followed itunes help and in the prefs i said: Don't caopy to itunes library when i imported serval gigs of photos to the app. everything was fine. now, i just hooked a camera to itunes for th
-
I can't play most of my games on Facebook because some of the feature buttons are covered up. Like the enlarge screen button, and I can't get to some of my neighbors because of this problem. It's like the box you play in, in the middle of the page is
-
Passing values to Dynamic where clause as IN parameter - ADF
Hi, I am trying to get the Dynamic where clause query output something like below, select * from EMP where emp_id IN(200,203,204) How to pass values from setWhereCluase(emp_id,????) Thanks,
-
Adding photos from email?
Hi, Is there a way to take a photo attached to an email and add it to the photo library? Thanks, Dan
-
Maxl to export/import partition xml
I have searched thru the tech ref at all the Maxl commands and I'm not seeing what I'm looking for. Is there a way to automate thru maxl (or esscmd) the exporting and importing of the xml file for partitions? TIA, Robert