A better way to do this without scriptlets?

I have an object passed to the JSP through the request.setAttribute(). I have to get a Collection from that object and use it in my custom tag. The problem is that it isn't elegant as I would like it (still too much scriptlets).
The scriptlet code below already existed and there were loops done with scriptlets which my custom tag has replaced. But I am not sure of the most elegant way to replace the scriptlet code that was there while at the same time getting the Collection from an object from the request and having that Collection available in an efficient scope accessible by my custom tag.
We are not currently using JSTL but I could possibly go in that direction.
<% SomeObject o = (SomeObject)request.getAttribute("abc");
       Collection c = o.getCollection();
       //This line I added to the scriptlet to work with my custom tag
       pageContext.setAttribute("theCollection", c);
%>
<%-- This was done with a scriptlet before and now the custom tag below --%>
<mycustom:select optionsCollection="theCollection" scope="page" ... />TIA

I have an object passed to the JSP through the
request.setAttribute(). I have to get a Collection
from that object and use it in my custom tag. The
problem is that it isn't elegant as I would like it
(still too much scriptlets).
The scriptlet code below already existed and there
were loops done with scriptlets which my custom tag
has replaced. But I am not sure of the most elegant
way to replace the scriptlet code that was there
while at the same time getting the Collection from an
object from the request and having that Collection
available in an efficient scope accessible by my
custom tag.
We are not currently using JSTL but I could possibly
go in that direction.
<% SomeObject o =
(SomeObject)request.getAttribute("abc");
Collection c = o.getCollection();
//This line I added to the scriptlet to work
to work with my custom tag
pageContext.setAttribute("theCollection", c);
%>
<%-- This was done with a scriptlet before and now
the custom tag below --%>
<mycustom:select optionsCollection="theCollection"
scope="page" ... />TIAUse JSTL's c:set:
This gets the attribute named "abc" from the request, as if request.get("abc") was called, then calles the method getCollection() on the object retrieved, and stores it in the page scope (pageContext)
<c:set var="theCollection value="${requestScope.abc.collection}" scope="page"/>
<mycustom:select optionsCollection="theCollection" scope="page" ... />

Similar Messages

  • Since updating an iphone5 to ios8.3, it is no longer recognized by my pc. An Apple tech suggested that I install itunes as the only way to assure that I have the latest driver. Any way to do this without installing itunes?

    Since updating an iphone 5 to ios 8.3, it is no longer recognized by my Windows 7 pc. An Apple tech suggested that I install itunes as the only way to assure that I have the latest driver. Any way to do this without installing itunes?

    Read this
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive

  • I have an ipod and an iphone. I would like to use both devices for my work and home computer. But it tells me that its installed to another library and will delete all items to sync to itunes. Is there a way to do this without deleting?

    OK....... I have an Ipod and an Iphone. Would like all the Movies and music i have on both. My computer broke and now the only music i have is on ipod. It wont let me transfer to itunes. It says this device is linked to a different library and if i want to sync to a new one and delete everything on it. UH....NO   Is there a way to do this without deleting ? All purchases were made though the same apple id.

    - An iPod can only sync with one iTunes library. Yu can however manage music and videos among different computers by:
    Using iPhone, iPad, or iPod with multiple computers
    - To change syncing computer, move all the media to compute r#2
    - Connect the iPod to #2 and make a backup by right clicking on the iPod under Devices in iTunes and select Back Up
    - Restore the iPod from that backup
    Note tha the iPod backup the iTunes makes does not include synced media like apps and music.

  • I'm new at this but I am hoping someone can help me.I have recently been away for 5 weeks and my Tom Tom required updating.When I clicked to update it required a pc.As I didn't have access to a pc it wouldn't work is there any way to do this without a pc?

    Hi, I'm new at this but I am hoping someone can help me.I have recently been away for 5 weeks and my Tom Tom required updating.When I clicked to update it, it required a pc. As I didn't have access to a pc it wouldn't work is there any way to do this without a pc?  I was without this app for 3 weeks!  Thanks, Lea

    The process to update your Tom Tom is a big data file, you will need to be connected to a Wi-Fi network for it to download.  If will take about an hour. 

  • I am having trouble transferring files from an old MacBook (2007) to a MacBook Air over a wireless network.  The connection was interrupted and the time was over 24 hours.  Is there a better way to do this?  I'm using Migration assistant.

    I am having trouble transferring files from an old MacBook (2007) to a MacBook Air over a wireless network.  The connection was interrupted and the time was over 24 hours.  Is there a better way to do this?  I'm using Migration assistant.  The lack of an ethernet port on MacBook air does not help.

    William ..
    Alternative data transfer methods suggested here > OS X: How to migrate data from another Mac using Mavericks

  • There's got to be a better way to do this (RAM preview frustration)

    I loaded a 1:20 second Full HD clip into after effects. I need to edit the video based on certain sounds in the video and see if I'm matching them up correctly by previewing it with sound.
    The problem is i'm getting frustrated due to After effects not behaving like Premiere. First who thought it was a good idea not to incorporate sound into after effects? Second, I have an i7 sandy bridge processor, and 16 gbs of ram, yet it still takes time to render the ram preview (with no effects on it yet).
    So ram preview is my only option for sound, but the problem is every time I hit ram preview it starts the video all the way from the beginning. This is frustrating as I want to start at a specific point. Imagine having a longer video where the editing needs to take place at the end.
    There are people out there doing a lot more complicated professional projects, what do you guys do to get around this?
    Why can't after effects do some basic things like premiere like render fast with sound? Is it due to Mercury engine and 64 bits?
    This is one of the best products on the market, surely there is a better way to do this right?

    but the problem is every time I hit ram preview it starts the video all the way from the beginning.
    Window --> Preview, enable the "From current time" option
    yet it still takes time to render the ram preview (with no effects on it yet).
    There is no magic button. If it is compressed, naturally it needs to be decompressed and decoded first. This can consume resources even on fast machines. Furthermore, drive speed matters a lot in such cases. This might actualyl multiply, if you use multiprocessing, so for this kind of simple setup it's usually better to not use it. If your harddrives are fragmented or simply generally slow, frames cannot be loaded as fast and neither will AE be able to use the disk cache. Ergo, convert the footage and move it to the fastest drive in your system.
    what do you guys do to get around this?
    We preview at reduced compo resolution to extend RAM previews and place markers while the RAM preview plays using the * key on the numpad.
    Mylenium

  • Better Way To Do This? Selector Operator...

    I'm currently writing the selection operator for the algorithm. The aim of it is
    to rate how the coursework block have been allocated and give there allocation
    a rating...
    How I have done it is have a method that searches through the one of the parent
    timetables. It looks for coursework time blocks. Once it finds one it notes
    this and looks at the next block along. If this is a coursework time block it
    notes this as well. I then perform an operation comparing these two coursework
    time blocks to find out if they are for the same Module. If they are not this
    is not a very effective coursework timetable strategy.
    Because of this I note in an array the the position of these two coursework time
    block and give them a fitness rating of 1000. I then go on to see if the next
    block is a coursework time block. If it is and its not of the same Module ID of
    the two previous then I not these 3 block down in an array and give them a
    fitness rating of 2000.
    My concern is that I am using allot of if and for loop's and the code is
    starting to look untidy at best. Is there any better way of doing this?
    Below Is my code:
          * @param parentOne
          * @param parentTwo
         public void selectionOperator(ArrayList parentOne, ArrayList parentTwo){
              // Store's the fitness rating of sections of the timetable...          
              ArrayList parentOneBlockFitnessRating = new ArrayList ();
              ArrayList parentTwoBlockFitnessRating = new ArrayList ();
              //Loops through the timetable's timeblocks...
              for (int i = 0; i < parentOne.size(); i++) {
                   //Checks to see if the current time block is of the class: CourseworkTimeBlock,
                   //if so it enters this statement...
                   if(parentOne.get(i).getClass().toString().equals("class Timetable.CourseworkTimeBlock")){
                        //A temp store for the current CourseworkTimeBlock...
                        CourseworkTimeBlock tempBlockOne = (CourseworkTimeBlock) parentOne.get(i);
                        System.out.println("Got Here!, Module ID...: " + tempBlockOne.getModuleId());
                        //Checks to see if the next time block along is of the class: CourseworkTimeBlock,
                        //if so it enters this statement...
                        if(parentOne.get(i+1).getClass().toString().equals("class Timetable.CourseworkTimeBlock")){
                             //A temp store for the next CourseworkTimeBlock...
                             CourseworkTimeBlock tempBlockTwo = (CourseworkTimeBlock) parentOne.get(i+1);
                             System.out.println("Got Here Aswell!");
                             //Checks to see if the current and next CourseworkTimeBlock module Id's
                             //are the same, if there arn't then this section is entered...
                             if(!tempBlockOne.getModuleId().equals(tempBlockTwo.getModuleId())){
                                  //Checks to see if the second time block along is of the class: CourseworkTimeBlock,
                                  //if so it enters this statement...
                                  if(parentTwo.get(i+2).getClass().toString().equals("class Timetable.CourseworkTimeBlock")){
                                       //A temp store for the second CourseworkTimeBlock along...
                                       CourseworkTimeBlock tempBlockThree = (CourseworkTimeBlock) parentTwo.get(i+2);
                                       //Checks to see if all 3 of the Module Id's of the CourseworkTimeBlocks match,
                                       //if they don't match this statement is entered...
                                       if(! tempBlockOne.getModuleId().equals(tempBlockTwo.getModuleId()) && (tempBlockTwo.getModuleId().equals(tempBlockThree.getModuleId()))) {
                                            //ArrayList to store the fitness rating of the current block
                                            //selection...
                                            ArrayList <Integer> blockFitness = new ArrayList<Integer>();
                                            //Position of first block.
                                            blockFitness.add(i);
                                            //Position of second block.
                                            blockFitness.add(i+1);
                                            //Position of second block.
                                            blockFitness.add(i+2);
                                            //Fitness Value
                                            blockFitness.add(2000);
                                            //Add block rating to main rating ArrayList...
                                            parentOneBlockFitnessRating.add(blockFitness);
                                       else{
                                            //ArrayList to store the fitness rating of the current block
                                            //selection...
                                            ArrayList <Integer> blockFitness = new ArrayList<Integer>();
                                            //Position of first block.
                                            blockFitness.add(i);
                                            //Position of second block.
                                            blockFitness.add(i+1);
                                            //Fitness Value
                                            blockFitness.add(1000);
                                            //Add block rating to main rating ArrayList...
                                            parentOneBlockFitnessRating.add(blockFitness);
              for (int o = 0; o < parentTwo.size(); o++) {
                   if(parentTwo.get(o).getClass().toString().equals("class Timetable.CourseworkTimeBlock")){
                        CourseworkTimeBlock tempBlockOne = (CourseworkTimeBlock) parentTwo.get(o);
                        System.out.println("Got Here!, Module ID...: " + tempBlockOne.getModuleId());
                        if(parentTwo.get(o+1).getClass().toString().equals("class Timetable.CourseworkTimeBlock")){
                             CourseworkTimeBlock tempBlockTwo = (CourseworkTimeBlock) parentTwo.get(o+1);
                             System.out.println("Got Here Aswell!");
                             if(!tempBlockOne.getModuleId().equals(tempBlockTwo.getModuleId())){
                                  if(parentTwo.get(o+2).getClass().toString().equals("class Timetable.CourseworkTimeBlock")){
                                       CourseworkTimeBlock tempBlockThree = (CourseworkTimeBlock) parentTwo.get(o+2);
                                       if(! tempBlockOne.getModuleId().equals(tempBlockTwo.getModuleId()) && (tempBlockTwo.getModuleId().equals(tempBlockThree.getModuleId()))) {
                                            ArrayList <Integer> blockFitness = new ArrayList<Integer>();
                                            //Position of first block.
                                            blockFitness.add(o);
                                            //Position of second block.
                                            blockFitness.add(o+1);
                                            //Position of second block.
                                            blockFitness.add(o+2);
                                            //Fitness Value
                                            blockFitness.add(2000);
                                            //Add block rating to main rating ArrayList...
                                            parentTwoBlockFitnessRating.add(blockFitness);
                                       else{
                                            ArrayList <Integer> blockFitness = new ArrayList<Integer>();
                                            //Position of first block.
                                            blockFitness.add(o);
                                            //Position of second block.
                                            blockFitness.add(o+1);
                                            //Fitness Value
                                            blockFitness.add(1000);
                                            //Add block rating to main rating ArrayList...
                                            parentTwoBlockFitnessRating.add(blockFitness);
         }As you can see there are allot if statements and some bad coding practice to boot. But I don't know what other ways to do it....
    Any directions of other ways how to do this?
    Many Thanks
    Chris

    Unfortunately, I think you're stuck with a bunch of if-statements.
    Fortunately, I have some things that may help you.
    First, I usually make sure something is of x class via this
    if (someObject instanceof SomeClass) {So, I'd adjust your 'class checking' conditionals from this
    if(parentOne.get(i).getClass().toString().equals("class Timetable.CourseworkTimeBlock"))to this
    if (parentOne.get(i) instanceof Timetable.CourseworkTimeBlock) {Secondly, your code logic is kind of confusing.
    Why do you have a for-loop that iterates through every CourseworkTimeBlock, if you then (within each possible iteration) check iteration+1 and iteration+2? What happens if those throw an ArrayIndexOutOfBoundsException, or are null?

  • Better Way to do this loop.

    I know there is better ways to do this so that I can merely have it loop infinitely until it hits the max password. I would also like to keep the spot where it has the print Statements because I tend to set some other code in front of it.
    If anyone also has some Ideas so I can have it stop and start in particular positions.
    Like lets say ?!!!!? to ?~~~~?
    Thanks a ton. Below is the code.
       char[] password = new char[20];
       int current_last_letter = 0;
       int max_password = 3;
       while(current_last_letter < max_password)
       for(int counter_gamma = 32; counter_gamma <= 126; counter_gamma++)
           for(int counter_beta = 32; counter_beta <= 126; counter_beta++)
                for(int counter_alpha = 32; counter_alpha <= 126; counter_alpha++) //alpha = increase last character by one
                    password[current_last_letter] = (char)counter_alpha;
                    System.out.print(password);
                    System.out.println("::null");
                if(current_last_letter > 0)
                    password[current_last_letter-1] = (char)counter_beta;
                else
                    counter_beta = 127;
            if(current_last_letter > 1)
                password[current_last_letter-2] = (char)counter_gamma;
            else
                counter_gamma = 127;
       current_last_letter++;
                   

    If I interpreted your code right, you simply want to count in radix '~'-' '+1 (read this carefully).
    Given a password, and a lo/hi value for the character range, the following method returns the
    lexicographically next password. The method returns null if no such password exists --    char[] nextPassword(char[] pw, char lo, char hi) {
          for (int i= pw.lenght; --i >= 0;)
             if (pw[i] < hi) { // next character possible here?
                pw[i]++;
                return pw;
             else // * no, reset to first value and continue;
                pw= lo;
    return null; // all pw-chars reached their hi value
    So, if you initialize a password char array as follows --    char[] pw= new char[20];
       Arrays.fill(pw, ' '); the following fragment handles every possible password --    do {
          handlePassword(pw); // do something with pw
          pw= nextPassword(pw, ' ', '~');
       } while (pw != null); kind regards,
    Jos

  • Better way to do this

    When selecting into a variable, is there a better way to do this? I want to make sure I don't get an error if there are no rows found. I think it's inefficient to count the number of occurrences before selecting into the variable. Can I use %NOROWSFOUND or something similar? If so, can you please provide an example? Thanks, Margaret
    Tzi := null;
    SELECT count(BUSINESS_tz)
    INTO Tzi_cnt
    FROM BUSINESS O
    WHERE ID = Fac_id AND BUSINESS_type = 'Store' AND O.Business_seq = (SELECT Business_seq
    FROM Org_lookup
    WHERE Store_seq = 0);
    IF Tzi_cnt > 0
    THEN
    SELECT BUSINESS_tz
    INTO Tzi
    FROM BUSINESS O
    WHERE ID = Fac_id AND BUSINESS_type = 'Store' AND O.Business_seq = (SELECT Business_seq

    the proper way to do this is to use an exception block;
    so
    begin
    Tzi := null;
    SELECT BUSINESS_tz
    INTO Tzi_cnt
    FROM BUSINESS O
    WHERE ID = Fac_id AND BUSINESS_type = 'Store' AND O.Business_seq = (SELECT Business_seq
    FROM Org_lookup
    WHERE Store_seq = 0);
    exception
    when no_data_found
    then
       null;   -- put any code to execute here or raise exception
    end;you can also use sql%rowcount to find out how many rows your sql statement affected:
    eg directly after your sql and before any rollback or commit
    declare
    v_rowcount number;
    begin
    insert into <table_name>
    select * from <other_table>;
    v_rowcount := sql%rowcount;
    end;

  • Is there a better way to do this? Interactive graphics on a PDF

    Hello
    Part of a PDF form I am planning requires the user to place several marks on a series of dots.
    I have partially achieved this using check boxes and many hidden objects.
    http://www.hoodoomayhem.com/example/Example.pdf focus on the small dots in the upper right.
    Is there a smarter way to achieve this without using thousands of hidden objects.
    I am quite new to scripting and do appreciate any suggestions.
    I look forward to some feedback
    Bonbeket

    That update should only be a single statement - not within a loop. The basic structure here should be something like:
    update central_printing_staging cps
       set sent_for_printing_date = trim(sysdate)
    where central_printing_staging_id in (select ...
                                             from <variation of complex query>);
    open p_centralprinting_refcursor
    for <complex query snipped>;The only question I have is whether the ref cursor is supposed to reflect the updated values or not, or if the two are even related or not - can't tell without seeing the query.

  • How to create a function with dynamic sql or any better way to achieve this?

            Hello,
            I have created below SQL query which works fine however when scalar function created ,it
            throws an error "Only functions and extended stored procedures can be executed from within a
            function.". In below code First cursor reads all client database names and second cursor
            reads client locations.
                      DECLARE @clientLocation nvarchar(100),@locationClientPath nvarchar(Max);
                      DECLARE @ItemID int;
                      SET @locationClientPath = char(0);
                      SET @ItemID = 67480;
       --building dynamic sql to replace database name at runtime
             DECLARE @strSQL nvarchar(Max);
             DECLARE @DatabaseName nvarchar(100);
             DECLARE @localClientPath nvarchar(MAX) ;
                      Declare databaselist_cursor Cursor for select [DBName] from [DataBase].[dbo].
                      [tblOrganization] 
                      OPEN databaselist_cursor
                      FETCH NEXT FROM databaselist_cursor INTO @DatabaseName
                      WHILE @@FETCH_STATUS = 0
                      BEGIN       
       PRINT 'Processing DATABASE: ' + @DatabaseName;
        SET @strSQL = 'DECLARE organizationlist_cursor CURSOR
        FOR SELECT '+ @DatabaseName +'.[dbo].[usGetLocationPathByRID]
                                   ([LocationRID]) 
        FROM '+ @DatabaseName +'.[dbo].[tblItemLocationDetailOrg] where
                                   ItemId = '+ cast(@ItemID as nvarchar(20))  ;
         EXEC sp_executesql @strSQL;
        -- Open the cursor
        OPEN organizationlist_cursor
        SET @localClientPath = '';
        -- go through each Location path and return the 
         FETCH NEXT FROM organizationlist_cursor into @clientLocation
         WHILE @@FETCH_STATUS = 0
          BEGIN
           SELECT @localClientPath =  @clientLocation; 
           SELECT @locationClientPath =
    @locationClientPath + @clientLocation + ','
           FETCH NEXT FROM organizationlist_cursor INTO
    @clientLocation
          END
           PRINT 'current databse client location'+  @localClientPath;
         -- Close the Cursor
         CLOSE organizationlist_cursor;
         DEALLOCATE organizationlist_cursor;
         FETCH NEXT FROM databaselist_cursor INTO @DatabaseName
                    END
                    CLOSE databaselist_cursor;
                    DEALLOCATE databaselist_cursor;
                    -- Trim the last comma from the string
                   SELECT @locationClientPath = SUBSTRING(@locationClientPath,1,LEN(@locationClientPath)-  1);
                     PRINT @locationClientPath;
            I would like to create above query in function so that return value would be used in 
            another query select statement and I am using SQL 2005.
            I would like to know if there is a way to make this work as a function or any better way
            to  achieve this?
            Thanks,

    This very simple: We cannot use dynamic SQL from used-defined functions written in T-SQL. This is because you are not permitted do anything in a UDF that could change the database state (as the UDF may be invoked as part of a query). Since you can
    do anything from dynamic SQL, including updates, it is obvious why dynamic SQL is not permitted as per the microsoft..
    In SQL 2005 and later, we could implement your function as a CLR function. Recall that all data access from the CLR is dynamic SQL. (here you are safe-guarded, so that if you perform an update operation from your function, you will get caught.) A word of warning
    though: data access from scalar UDFs can often give performance problems and its not recommended too..
    Raju Rasagounder Sr MSSQL DBA
          Hi Raju,
           Can you help me writing CLR for my above function? I am newbie to SQL CLR programming.
           Thanks in advance!
           Satya
              

  • I would like to duplicate the folders and apps that I have set up on my iPhone to my iPad.  Is there a quick way of doing this without going through the whole process again manually?

    I would like to duplicate the folders and apps that I have set up on my iPhone to my iPad.  Is there a quick way of doing this without going through the whole process again manually?

    You can restore your iPad with your iPhone backup but items that are iPhone only will not transfer.  It should recreate all your folders.  It can't hurt anything to try.

  • I am trying to import photo's on i photo.  It downloads all of the pictures on my camera, how do i only select the photos i want?  Is there a way to do this without selecting one photo at a time? is there a way to select multiple images?  thanks!

    I am trying to import photo's on i photo.  It downloads all of the pictures on my camera, how do i only select the photos i want?  Is there a way to do this without selecting one photo at a time? is there a way to select multiple images?  thanks!

    To select consecutive images click and drag the cursor over multiple thumbnails to select all at once.
    To select multiple images that are randomly located hold down the Command(⌘) key and click on those images you want to select.
    Or to select consecutive images from a list of images that are together hold down the Shift key and and click on the first photo you want to select and the on the last photo you want in the list.
    OT

  • HT1688 trying to "un"disable phone. Any way to do this without having to reset the phone?

    I'm trying to "un"disable an iPhone 4s. Any way to do this without having to reset the phone?

    Hi mark,
    Follow the instructions that best apply to your situation in this support article:
    http://support.apple.com/kb/HT1212
    Best of luck!
    Cheers,
    GB

  • I have 1,400 items in my in-box and would like to delete them en masse. Is there any way to do this without deleting them individually? Thank you

    I have 1,400 items in my in-box and would like to delete them en masse. Is there any way to do this without deleting them individually?

    Select the Inbox folder to see emails.
    click on first email to get focus.
    Hold down 'Ctrl' key and press 'A' key
    This will highlight /select all emails.
    they will appear as conversations in the Message Pane
    Clickon Delete.
    when it has finished - you do have a lot of emails :)
    Right click on Inbox and select 'compact' - this removes all marked as deleted emails.

Maybe you are looking for

  • Delivery report in sap sd

    what is the standared T.code to see the list of deliveries with the following fields. Sales order No, Sales order date, sales order quntity, Delivery quntity, DELIVERY DT SOLD TO PARTY DESCRIPTION TYPE OF ORDER Thanks, Tulasi

  • How do I delete multiple calendars?

    I am on a pc. I use an iPhone 4 and recently bought an iPad 2. Previously, i was syncing my old iphone 3G. I haven't sync my iPad 2 yet cos I am trying not to have 2 calendars on my iPad 2 if I were to sync it on my laptop and iPhone 4. I would like

  • IPhoto'09 version 8.1.2

    My MiniMac was bought the 7th of Oct 2010, but iLife was (to my surprice) not installed. So the 15th of Oct 2010 I bought iLife'09 and installed it in the new MiniMac. Now 2 weeks later I see in Apple Store that if you have a newly bought Mac (betwee

  • G4 MDD and Wireless

    So I'm completely new to MAC. I have here an old G4 MDD and I'd like to get a wireless card in there and use it for a movie machine. What kind of card do I need? Right now it has OS 10.3.9 - can/should I upgrade? I need to completely reformat this gu

  • How to use Runtime.getRuntime("command") in win?

    I dont know how to use this method in win entironment, for example about file opertions, where there is some documents on detail about it?