Accessing array elements from the Faces EL

Someone had this question on email and I thought it best to share the answer here.
On Tue, 23 Mar 2004 16:25:23 +0800, zhang xinxin said:ZX> I want to ask you how can output array
ZX> for example
ZX> I define an array in SearchItemBean and bind value to it:
ZX> private String[] array=new String[2];
ZX> public String[] getArray() {
ZX> array[0]="a";
ZX> array[1]="b";
ZX> return array;
ZX> }
ZX> and I can output the array as following:
ZX> <h:output_text id="arra" value="#{SearchItemBean.array[0]}"/> <br>
ZX> but if I wang to output using parameter,it failed:
ZX> in jsp page it write as this:
ZX> <%
ZX> int i=0;
ZX> %>
ZX> <h:output_text id="arra" value="#{SearchItemBean.array[<%=i%>]}"/> <br>
ZX> Can you tell me how to use paremeter in output_text?thanks!
Sure,
The reason what you're doing doesn't work is that anything inside of
"#{}" is for deferred evaluation and is evaluated by the JSF engine,
while scriptlets are evaluated by the JSP engine. I have modified the
guessNumber demo included in the 1.0 release to do what you're trying to
do.
8<-------------------------------------
Index: greeting.jsp
===================================================================
RCS file: /export/cvs/jsf-demo/guessNumber/web/greeting.jsp,v
retrieving revision 1.22
diff -u -r1.22 greeting.jsp
--- greeting.jsp     9 Mar 2004 22:51:27 -0000     1.22
+++ greeting.jsp     23 Mar 2004 16:36:20 -0000
@@ -40,6 +40,7 @@
<HEAD> <title>Hello</title> </HEAD>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
+ <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<body bgcolor="white">
<f:view>
<h:form id="helloForm" >
@@ -54,6 +55,10 @@
     <h:commandButton id="submit" action="success" value="Submit" />
<p>
     <h:message style="color: red; font-family: 'New Century Schoolbook', serif; font-style: oblique; text-decoration: overline" id="errors1" for="userNo"/>
+          <hr />
+ <c:set value="1" var="i" scope="request" />
+
+ <h:outputText id="array" value="#{UserNumberBean.array[requestScope.i]}" />
</h:form>
</f:view>
8<-------------------------------------
What I'm doing here is to store the variable into request scope, then I
can access it using the implicit object requestScope.
This approach should give you what you need.
Ed (EG Member)

Thank you for your answer!
but I still have question.
I will output a array,but the size of array is dynamic,
and the size is passed by the SearchItemBean.
How can I control the i to increase to the specify number?
how can I pass the size parameter into the <c:set>?
How can I use a paratemer passed by size and control the "i" to increase to it?
thanks!

Similar Messages

  • How do I access array elements in one method from another method?

    Hi all!
    How do I access the array's elements from another method so that method 2 can have access to method 1's array elements? Thanks for any help!
    I am trying to create a simply program that will use a method to create an array and a SEPARATE method that will sort the array's elements (without using java's built in array features). I can create the program by simply having one method and sorting the array within that same method, BUT I want to sort the array from another method.
    Here's my code so far:
    public class ArraySort {
       public static void createArray(int size){
           double myArray[] = new double[size];    //create my new array
           for(int j=0; j < myArray.length; j++)
              myArray[j] = (200.0 * Math.random() + 1.0);   //fill the array with random numbers
       public static void sortArray(){
           // I WANT THIS METHOD TO ACCESS THE ARRAY ELEMENTS IN THE METHOD ABOVE, BUT DON'T KNOW
          //  HOW???? Please help!
        public static void main(String[] args) {
            createArray(4);    //call to create the array
    }Thanks again!
    - Johnny

    Thanks for the help all! I ve managed to get the program working, using java's built in array sort, but when i try to call on the array sort method from WITHIN my main method, nothing happens!
    Can somebody please tell me why I am not able to call on the sort method from within my main class???? Thanks!
    public class ArraySort {
       public void createArray(double[] arrayName, int size){
           double myArray[] = new double[size];  //create new array
           for(int j=0; j < myArray.length; j++)
              myArray[j] = (200.0 * Math.random() + 1.0);    //populate array with
           }                                                 //random Numbers
           sortArray(myArray); 
       } //Sort array(if I delete this & try to use it in Main method --> doesn't work???
       public void sortArray(double[] arrayName){
           DecimalFormat time = new DecimalFormat("0.00");
           Arrays.sort(arrayName);      //sort array using Java's built in array method
           for(int i = 0; i <arrayName.length; i++)
               System.out.println(time.format(arrayName)); //print arary elements
    public static void main(String[] args) {
    ArraySort newArray = new ArraySort(); //create a new instance
    double myArray[] = new double[0]; //create a new double array
    newArray.createArray(myArray,4); //build the array of indicated size
    //newArray.sortArray(myArray); //This will not work???? WHY?????//

  • Accessibility, exclude UI elements from the Tab-chain

    Hi,
    I have a complex UI which is very uncomfortable to access with the Tab key when using sap-accesssibility=true parameter. The main problem are the many transparent containers, which are necessary to create the refined composition of the UI. They get focused when the Tab key is pressed and this is completely useless. I there a way to exclude UI elements from the Tab-chain?
    Best regards,
    Krasimir

    Hi,
    I have same prolem here.
    In my UI I am using mastercolumn for expand /collapse functionality in parent - child node .
    The problem is the keyboard tab-chain is skipping the master column which makes it a accessibility issue.
    Is there any way we can include/exclude UI elements from tab chain.
    My NWDS version is 7.0.10.

  • Label TS array elements from LV

    Hi,
    How can I change the Label of a TS array element from my LabVIEW code??? Se picture added.
    It is done when you insert at ”Multiple Numeric Limit Test” step in a test sequence and select “Edit Limits…” you get the “Edit Multiple Numeric Limit Test” dialog box. When this is closed with OK the Names of the Measurement Set is applied to the elements in Step.Result.Measurement. How can I do this from LabVIEW???
    I am looking forward to hear from you.
    Best Regards,
    Morten Pedersen
    CIM Industrial Systems A/S
    Attachments:
    ArrayElementsNames.jpg ‏98 KB

    You can access the name of an object by using ActiveX to get to the step's Property Object. Once there, you can use a property node for the name and change it to write.
    Let me know if you need more information about this.
    Regards
    Anders M.
    National Instruments DK

  • How to set the value of an array element (not the complete array) by using a reference?

    My situation is that I have an array of clusters on the front panel. Each element is used for a particular test setup, so if the array size is three, it means we have three identical test setups that can be used. The cluster contains two string controls and a button: 'device ID' string, 'start' button and 'status' string.
    In order to keep the diagrams simple, I would like to use a reference to the array as input into a subvi. This subvi will then modify a particular element in the array (i.e. set the 'status' string).
    The first problem I encounter is that I can not select an array element to write to by using the reference. I have tried setting the 'Selection s
    tart[]' and 'Selection size[]' properties and then querying the 'Array element' to get the proper element.
    If I do this, the VI always seems to write to the element which the user has selected (i.e. the element that contains the cursor) instead of the one I am trying to select. I also have not found any other possible use for the 'Selection' properties, so I wonder if I am doing something wrong.
    Of course I can use the 'value' property to get all elements, and then use the replace array element with an index value, but this defeats the purpose of leaving all other elements untouched.
    I had hoped to use this method specifically to avoid overwriting other array elements (such as happens with the replace array element) because the user might be modifying the second array element while I want to modify the first.
    My current solution is to split the array into two arrays: one control and one indicator (I guess that's really how it should be done ;-) but I'd still like to know ho
    w to change a single element in an array without affecting the others by using a reference in case I can use it elsewhere.

    > My situation is that I have an array of clusters on the front panel.
    > Each element is used for a particular test setup, so if the array size
    > is three, it means we have three identical test setups that can be
    > used. The cluster contains two string controls and a button: 'device
    > ID' string, 'start' button and 'status' string.
    >
    > In order to keep the diagrams simple, I would like to use a reference
    > to the array as input into a subvi. This subvi will then modify a
    > particular element in the array (i.e. set the 'status' string).
    >
    It isn't possible to get a reference to a particular element within an
    array. There is only one reference to the one control that represents
    all elements in the array.
    While it may seem better to use references to update
    an element within
    an array, it shouldn't really be necessary, and it can also lead to
    race conditions. If you write to an element that has the
    possibility of the user changing, whether you write with a local, a
    reference, or any other means, there is a race condition between the
    diagram and the user. LV will help with this to a certain extent,
    especially for controls that take awhile to edit like ones that use
    the keyboard. In these cases, if the user has already started entering
    text, it will not be overwritten by the new value unless the key focus
    is taken away from the control first. It is similar when moving a slider
    or other value changes using the mouse. LV will write to the other values,
    but will not rip the slider out of the user's hand.
    To completely avoid race conditions, you can split the array into user
    fields and indicators that are located underneath them. Or, if some
    controls act as both, you can do like Excel. You don't directly type
    into the cell. You choose w
    hich cell to edit, but you modify another
    location. When the edit is completed, it is incorporated into the
    display so that it is never lost.
    Greg McKaskle

  • What are some ways to remove shine from the face in portraits?

    What are some different methods that people use to remove shine from the face while still leaving enough for a subtle highlight? I would love to hear all the different options I have. Thanks!

    Here is one:
    Open a blank layer above the background layer
    Access the Clone Stamp Tool.
    On the tool's option bar, enter Mode: Darken  Opacity: 30%  Aligned: Checked  Sample all layers: checked
    Zoom in on the shiny area, then ALT+left click a non-shiny skin area to sample the skin. Now, paint over the shiny area

  • HT204406 I am having a very difficult time with accessing my music from the cloud.  I need to have itunes open on my laptop in order for it to work.  And as soon as I close out itunes on my laptop, it gives me a warning that all users will be logged out. 

    I am having a very difficult time with accessing my music from the cloud.  I need to have itunes open on my laptop in order for it to work.  And as soon as I close out itunes on my laptop, it gives me a warning that all users will be logged out.  Help!!!

    Where are iTunes files located?
    No, I do not mean just the music.  Copying just the media/music files or the media folder creates problems.

  • The circuit of my macbook is dead yet the hard drive is fine.  I need to access a file from the hard drive, how can i do this? is there a cable i can connect to another mac that will let me transfer the file?

    The circuit of my macbook is dead yet the hard drive is fine.  I need to access a file from the hard drive, how can i do this? The mac turns on the screen freezes as bright blue.  Is there a cable i can connect to another mac that will let me transfer the file?

    There is another option if the Macbook will start up in Target Disk Mode.
    Restart the computer while holding down the T key. If you see the firewire symbol moving around on the screen you can connect this one to another one in TDM. You will need a suitable cable to connect the two Macs.
    http://support.apple.com/kb/ht1661
    Firewire symbol:

  • I have transferred my itunes library to an external drive. I then attached the external disk to a new computer. I can now access all songs from the new computer. But I can't access playlists. I can still  access all songs and playlists on the old computer

    I have transferred my itunes library to an external drive. I then attached the external disk to a new computer. I can now access all songs from the new computer. But I can't access playlists. I can still  access all songs and playlists on the old computer

    If you right mouse and select Get info it will show you the Apple ID used to purchase these songs.
    Usually the name of an apple id is based on the email. So knowing that you may have forgotten the Apple ID password.
    You can request a new password here http://www.apple.com/support/appleid/

  • I have a MacBook purchased in 2009 with Snow Leopard. I tried to access "special characters" from the Finder menu and an intermittent blank pop ups and will not stop. It also happens when I run Word or Pages.

    The blank pop up began as I tried to access "special characters" from the finder menu. I restarted, turned off and restarted and it did not work. It interferes with any application because I cannot work fast. Every new step takes a few seconds longer such as saving, finding text, check spelling and many more. I am desperate to solve this. Thanks in advance for any help given.
    Consuelo Corretjer

    Use the trackpad to scroll, thats what it was designed for. The scroll bars automatically disappear when not being used and will appear if you scroll up or down using the trackpad.
    This is a user-to-user forum and most people will post on here if they have problems. You very rarely get people posting to say there update went smooth. The fact is the vast majority of Mountain Lion users will not be experiencing any major problems with the OS, or maybe with apps which are not compatible, but thats hardly Apple's fault if developers don't update their apps.

  • Since installing Photoshop CC I can't access Camera Raw from the program Bridge.

    Since installing Photoshop CC I can't access Camera Raw from the program Bridge.  When I try, I get a message that says, "Camera Raw editing is not enabled. Camera Raw editing requires that a qualifying product has been launched at least once to enable this feature."  Is Photoshop CC a qualifying product?  It has been opened a number of times, but it doesn't solve this problem.

    I am having this exact same problem and just upgraded to Windows 7...many people are saying to update the Plug In for Camera Raw to 4.6, but that is not working for me to see it in Bridge or Camera Raw.

  • I recently synced my iphone4 on my iMac, but now I can't access my camera from the lock screen? It shows up but it doesn't open the camera? Does anyone know how to fix this? Thanks!

    I recently synced my iphone4 on my iMac, but now I can't access my camera from the lock screen? It shows up but it doesn't open the camera? Does anyone know how to fix this? Thanks!

    Can't believe it was that easy... I'm so dumb! Thanks for your help, I was getting so aggravated! I owe you... Thanks again!

  • HT204266 I live in China, have Dutch nationality, and no US address or Credit Card; how can I have access to products from the US iTunes store, in particular music, when such items are not available from the China iTunes store? In general, what are the di

    I live in China, have Dutch nationality, and no US address or Credit Card; how can I have access to products from the US iTunes store, in particular music, when such items are not available from the China iTunes store? In general, what are the differences between countries' iTunes offerings? Does one really need an address and a credit card for any country to be able to access that countries iTunes store? Why these restrictions?

    You cannot.
    You cannot use another countrys itunes store.
    You must be physically locates inside the borders of a country to use that countrys itunes store and a credit card issued in that country with a valid billing address in that country.
    The owners of the distribution rights of movies/music/etc differ by country.  These distributors decide who can sell their content in that country.
    Buy from another source if your countrys itunes store does not carry somehting that you want.

  • Can't access my desktop from the sidebar. Keeps going to terminal

    can't access my desktop from the sidebar. Keeps opening in terminal window. Also when trying to save from an email, I cannot save to desktop

    If you haven't already restart and test, if no joy then Repair Disk Permissions in Disk Utility. Open Disk Utilties (Applications - Utilities - Disk Utility) select the internal HD, select the First Aid tab and then click Repair Disk Permissions. To be safe run Repair Disk Permissions 2x.

  • I have installed iTunes Match on my iPhone & laptop. May I now safely delete the music files from my phone and still access my music from the phone? Thanks

    I have installed iTunes Match on my iPhone &amp; laptop. May I now safely delete the music files from my phone and still access my music from the phone? Thanks

    Read this
    http://support.apple.com/kb/PH12492

Maybe you are looking for

  • How to keep view column in a table

    Hi, I have two table and one view(I have same data in any other schema so I don't want to keep same data in both schema) I want to make primary key in first table based on one column from 2nd table and one column from view, but it's not looking possi

  • Setting up a local ftp server for wireless photo transfers

    I am a semi-professional photographer who recently purchased a wireless unit that connects to my camera to transfer my images to my Mac. I have turned on the ftp services under Sharing on my Powermac G5 and set up a user account for the camera to log

  • Migration from Flex 3 to Flex 4

    I've migrated my project from flex 3 to flex 4 and all it's ok, the new project work fine. But I created my custom TitleWindow MX style and I created a swc library from Flash builder 4, all it's ok. When I use my custom TitleWindow in new project (co

  • HT1937 How I can find carrier for iPhone 4

    Hi I want to activate iPhone 4 which I bought it from eBay I got no idea how to find carrier please help me with this matter thanks

  • How do I get my pics to my new phone

    I want to sync my iCloud info to new phone. How do I do it..