Results 1 to 3 of 3
  1. #1
    alexalexander is offline Member
    Join Date
    Jan 2017
    Posts
    2
    Rep Power
    0

    Default Stop OR condition if returns true

    Hi, I'm a bit new working with velocity and I'm attempting to create an if/or condition where:
    User role is A or B or C = Icon 1 is displayed
    User role is D or E or F = Icon 2 is displayed

    The problem I am running into is that users can be in multiple roles:
    If user role is A & C = Icon 1 is displaying twice rather than just once because it continues through all conditions regardless of it returns true or false

    Does anyone have a solution to this? Am I going about this completely wrong?


    Java Code:
    			#foreach($role in $user.getRoles())
       			 	#if( $role.getName().toUpperCase() == "A" || $role.getName().toUpperCase() == "B" || $role.getName().toUpperCase() == "C"  )
      			 		<<<<<< Icon 1 >>>>>>
     				 #end
    			#end
    			#foreach($role in $user.getRoles())
       			 	#if( $role.getName().toUpperCase() == "D" || $role.getName().toUpperCase() == "E" || $role.getName().toUpperCase() == "F"  )
      			 		<<<<<< Icon 2 >>>>>>
     				 #end
    			#end
    Last edited by alexalexander; 01-26-2017 at 03:14 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Stop OR condition if returns true

    Velocity has a #break statement, so just break out of the loop at the end of the if statement.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    alexalexander is offline Member
    Join Date
    Jan 2017
    Posts
    2
    Rep Power
    0

    Default Re: Stop OR condition if returns true

    Thank you, Tolls. That seems to be working!

Similar Threads

  1. Replies: 5
    Last Post: 09-01-2015, 03:28 PM
  2. Accessing specific class if condition is true
    By Hash in forum New To Java
    Replies: 1
    Last Post: 02-24-2012, 03:43 AM
  3. Replies: 2
    Last Post: 01-21-2012, 05:34 PM
  4. Use stop button to stop moving (stop timers) on JPanel
    By mneskovic in forum New To Java
    Replies: 3
    Last Post: 07-23-2010, 12:50 PM
  5. How do I stop or kill a running thread when a condition is true
    By chikaman in forum Threads and Synchronization
    Replies: 3
    Last Post: 12-21-2009, 11:07 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •