Compare string in JSTL

Hi all,
I have   <c:set var="status" value="${found.studentStatus}"/> inside loopI want to call it outside the loop and compare string
<c:if test="${status.equals("A")}">
do something
</c:if>
But I get bug equals symbol expect, what is wrong?

EL is not java. The same rules don't apply. You actually do want to use the equals operator here. It ends up invoking the java .equals method in the end.
To make it explicit:
<c:if test="${status == 'A'}">
//or
<c:if test="${status eq 'A'}">Cheers,
evnafets

Similar Messages

  • Compare Strings using JSTL

    How can I compare strings with JSTL? One string is a stored date and the other is a generated date. My goal is to set the correct date in a dropdown menu with date values (yyyy-MM-dd) by comparing the current date with the stored.
    Code
    <%
    Calendar cal = Calendar.getInstance(timezone, locale);
    Format fm = new SimpleDateFormat("yyyy-MM-dd");
    String date2 = (String) fm.format(cal.getTime()); %>
    <c:set var="date1" value="${mb.date}" />   // from database lookup (MySQL Date)
    <p><c:out value="${date1}"/>=<%=date2%>:<c:out value="${date1 == '<%=date2%>' }" /></p>The result is:
    2004-08-03 = 2004-08-03 : false

    well, about this:
    <%
    Calendar cal = Calendar.getInstance(timezone, locale);
    Format fm = new SimpleDateFormat("yyyy-MM-dd");
    String date2 = (String) fm.format(cal.getTime());
    pageContext.setAttribute("date2",date2);
    %>
    <c:set var="date1" value="${mb.date}" />   // from database lookup (MySQL Date)
    <p><c:out value="${date1}"/> .equals <%=date2%>:<c:out value="${date1eq date2}" /></p>I try to use the EL 'eq' like you would use '.equals()' in regular java, and EL '==' like regular java '==' And since we are comparing Strings here, which are objects, we would use .equals rather than ==, since == compares refernce and .equals compares value...

  • C:choose for comparing strings

    Hi,
    I am trying to apply alternate styles to table rows using JSTL. When I am comparing strings it always falls into the 'otherwise' block. I guess I either have a silly error or there is something I am missing. When I output the string with the c:out it is set to the value 'data_row_white', which is what I find confusing as the test should prove true.
    I have also tried using the 'eq' operator to compare.
    Any help is appreciated.
    <c:set var="col_css" scope="page" value="data_row_white" />
            <c:forEach items="${requestScope['local_catalogue_list']}" var="item">
                <tr class="${col_css}">
                    <td class="no_top_no_right"><a href="javascript:viewCatalogue('${item.catalogueID}');">${item.catalogueName}</a></td>
                    <td class="no_top_middle">${item.status}</td>
                    <td class="no_top_no_left">${item.versionID}</td>
                </tr>
                <c:out value="${col_css}" />
                <c:choose>               
                    <c:when test="${col_css == 'data_row_white'} ">
                        <c:set var="col_css" scope="page" value="data_row_gray" />
                    </c:when>
                    <c:otherwise>                   
                        <c:set var="col_css" scope="page" value="data_row_white" />
                    </c:otherwise>
                </c:choose>
            </c:forEach>

    Using the ternary operator in EL which intercepts on the loop index is a much better/clearer/quickier way to alternate table rows.
    Basic example:    <table>
            <c:forEach items="${users}" var="user" varStatus="loop">
                <tr class="${loop.index % 2 == 0 ? 'even' : 'odd'}">
                    <td>${user.id}</td>
                    <td>${user.username}</td>
                    <td>${user.email}</td>
                    <td>${user.age}</td>
                </tr>
            </c:forEach>
        </table>

  • How to compare string in a case-insensitive manner using JavaScript?

    Hello everyone,
    Now I have a javascript to compare checkbox's value with user's input, but now seems it only can compare case-sensitively, does some one know if there is a function in javascript that it can compare string case-insensitively ?
    Here is my script :
    function findOffice(field)
    var name;
    name=prompt("What is the office name?");
    var l = field.length;
    for(var i = 0; i < l; i++)
    if(field.value==name)
    field[i].checked=true;
    field[i].focus();
    field[i].select();
    break;
    <input type="button" name="Find" value="Find And Select" onClick="findOffice(form1) >
    Thanks in advance !
    Rachel

    Thank you so much, I already solved the problem with your advice.
    You really have a beautiful mind, :-).
    I appreciate your help !
    Rachel

  • Comparing string in select query

    Hi,
    select single *
           from mara
           where <b>matnr = wa-matnr</b>.
    Here matnr is char18. Can we compare string like this?
    When <b>wa-matnr</b> is in <b>lower case</b> it is setting sy-subrc = 4, even though the matnr exists in mara. When converted to upper case and used it is setting sy-subrc = 0.
    Is there any other solution for the problem? I have checked out with matnr's conversion routine. It is also not working.

    just try  dat way...
    <b>ex...</b>
    data:wa_matnr like mara-matnr.
    data:wa_matnr1 like mara-matnr.
    data: gv_matnr like mara-matnr.
    wa_matnr = 'comptest'.
    CALL FUNCTION 'TERM_TRANSLATE_TO_UPPER_CASE'
      EXPORTING
       LANGU                     = SY-LANGU
        TEXT                     = wa_matnr
    IMPORTING
       TEXT_UC                   = wa_matnr1
    EXCEPTIONS
      NO_LOCALE_AVAILABLE       = 1
      OTHERS                    = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    select single matnr
    from mara into gv_matnr
    where matnr = wa_matnr or matnr = wa_matnr1.
    write : gv_matnr.

  • Public static final Comparator String CASE_INSENSITIVE_ORDER

    in this declaration..
    public static final Comparator<String> CASE_INSENSITIVE_ORDER
    what does <String> mean?
    thanks!

    what does the Comparator do. Look at the API and you would see the following description about the compare method.
    public int compare(Object o1,
    Object o2)Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
    The implementor must ensure that sgn(compare(x, y)) == -sgn(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)
    The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.
    Finally, the implementer must ensure that compare(x, y)==0 implies that sgn(compare(x, z))==sgn(compare(y, z)) for all z.
    It is generally the case, but not strictly required that (compare(x, y)==0) == (x.equals(y)). Generally speaking, any comparator that violates this condition should clearly indicate this fact. The recommended language is "Note: this comparator imposes orderings that are inconsistent with equals."
    Now your question is about what <String> is in your declaration. It is the type of the objects which are going to be compared.

  • Simple question - compare Strings with SSIS expression language

    SSIS variables - strOne = YES, strTwo = YES. I want to compare strings using ssis expression language (ie inside a variable's expression box, constraint of task flow arrow etc).
    Will @strOne == @strTwo be true ? I hope its not like programming languages where you need to do
    @strOne.Equals(@strTwo) instead of ==. Also is @strOne == "YES" true ?

    ([User::strOne] == [User::Strtwo] ? True : False)
    The third variable created should be of type boolean if you're using above expression. if its of type int return 0 and 1 instead of False and true
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Compare string in different line in text file

    I am new to java and I need a simple example to compare string in file text by for loop
    file.txt:
    A78802 D06VAIS060253113 WKNEUP751346577450
    A77802 D06VAIS060253113 WKNEUP751346577450
    A76802 D06VAIS060253925 WKNEUP751346577450
    A78802 D06VAIS075253698 WKNEGE226375082796
    A73802 D06VAIS116253222 WKNEFB227345305299
    dataString = TextIO.getln();
    A=dataString.substring(25,42);
    B=dataString.substring(195,203);
    C=dataString.substring(171,186);
    I WANT COPMPARE IN LINE 1 POSITION 20 TO LINE 2 POSITION 20 BY LOOPS ALL THE LINE IN TEXT FILE

    what have you tried so far?
    Also, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, either use the "code" button at the top of the forum Message editor or place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:
    &#91;code]
      // your code block goes here.
    &#91;/code]

  • Sort / compare Strings   SOS ... ___ ...

    Hi, sorry I'm novice in Java, and I'm trying to make kind of bubble sort on String MyArray[]. God ! I just found out that I can't compare Strings i.e. Objects like:
    if ( MyArray[i] > MyArray)...
    Can anybody recommend me a not too complicated solution, preferebly without imports..
    Thanks
    Mario

    Hi.
    String.compareTo(String anotherString) is what you need. Have a look at http://java.sun.com/j2se/1.4/docs/api/java/lang/String.html#compareTo(java.lang.String)
    Regards,
    Lance
    Lance Walton - [email protected]
    Team In A Box - Software without Tragedy
    http://www.teaminabox.co.uk

  • Compare string in java

    what function should i use to identify say :
    String str1="5C02";
    String str2="5B02";
    str1>str2 ????
    how to identify if string1 is greater than string2?

    are you sure you want to compare one string is
    greater than the another string?
    what do mean on greater than? is it the size of the
    string?
    or the value of the string?You can compare Strings lexicographically.
    For example "abcd" < "abd", in other words, the following line of code will return -1:int compared = "abcd".compareTo("abd");

  • [svn:bz-trunk] 21292: Fix BLZ-639 - avoid the use of "==" when comparing strings.

    Revision: 21292
    Revision: 21292
    Author:   [email protected]
    Date:     2011-05-25 12:09:39 -0700 (Wed, 25 May 2011)
    Log Message:
    Fix BLZ-639 - avoid the use of "==" when comparing strings.  Just check for null explicitly.
    Ticket Links:
        http://bugs.adobe.com/jira/browse/BLZ-639
    Modified Paths:
        blazeds/trunk/modules/common/src/flex/messaging/config/ClientConfiguration.java

    Adobe has donated BlazeDS to the Apache Flex community, and the source code is hosted on the Apache Flex website in a GIT repository.
    http://flex.apache.org/dev-sourcecode.html

  • How come the JRE uses == to compare Strings?

    I was looking through the source of javax.swing.plaf.basic.BasicComboBoxUI and came across this:        public void propertyChange(PropertyChangeEvent e) {
                String propertyName = e.getPropertyName();
             JComboBox comboBox = (JComboBox)e.getSource();
                if ( propertyName == "model" ) {
                else if ( propertyName == "editor" && comboBox.isEditable() ) {
                else if ( propertyName == "editable" ) {
                else if ( propertyName == "enabled" ) {
                else if ( propertyName == "focusable" ) {
                else if ( propertyName == "maximumRowCount" ) {
                else if ( propertyName == "font" ) {
                else if ( propertyName == JComponent.TOOL_TIP_TEXT_KEY ) {
                else if ( propertyName == BasicComboBoxUI.IS_TABLE_CELL_EDITOR ) {
             else if (propertyName == "prototypeDisplayValue") {
             else if (propertyName == "renderer") {
            }So
    1) Is there a valid reason for the developer to have used == instead of .equals(...) to compare Strings?
    2) How does the code work consistently with this anomaly?
    Similar use of == and not .equals(...) is seen in many other swing classes.
    Doesn't affect me, but I would be interested to know if anyone can throw some light on this.
    Thanks, Darryl

    Darryl.Burke wrote:
    DeltaGeek, thank you for your response.
    Paul, I think I understand what you are saying, but the String reference propertyNamein this case comes from e.getPropertyName() from the PropertyChangeEvent class, not from within the BasicComboBoxUI class.
    I gather that all loaded classes share the same String pool, and that's how this works correctly. But in that case any comparison of a String variable to a literal String using == should also work.
    Then why the brouhaha about never using == to compare Strings?The key thing here is that the String returned by getPropertyName() must have come from a String literal. For example, in javax.swing.JComboBox:
    firePropertyChange( "maximumRowCount", oldCount, maximumRowCount );This string literal will be the same instance as the string literal in the code you posted.
    If they had instead done something like
    String s = "RowCount";
    boolean isMaximum = true;
    firePropertyChange((isMaximum ? "maximum" : "minimum") + s, oldCount, maximumRowCount );In this case, the String literal "maximumRowCount" is not used, but rather created from a concatenation at runtime, so it's likely that the comparison would fail.
    Note that the following would be the same String literal because this concatenation would be done at compile-time, not runtime:
    "maximum" + "RowCount"As for why, I agree with DeltaGeek: performance.

  • Trying to ignore spaces when comparing strings

    I am writing a program where an answer entered by a user is compared to an answer held in a database. I have got it working but I can't get it to ignore 'spaces' or 'carriage returns'. Please can you have a look at my code and let me know what I can do to get this working.
    Thanks in advance
    Jes
    public class DBHandler {
    public DBHandler(String aQuestNum, String studentAnswer) {
    JOptionPane jop = new JOptionPane();
    JOptionPane jop2 = new JOptionPane();
    try {
    DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
    Connection aConnection = DriverManager.getConnection("jdbc:odbc:EnquiryTest", "", "");
    Statement aStatement = aConnection.createStatement();
    ResultSet aSet = aStatement.executeQuery ("SELECT * FROM EnquiryTestTable2 WHERE questionNum = '" + aQuestNum +"'");
    while (aSet.next()) {
    String tutorAnswer = aSet.getString("TAnswer");
    int test = tutorAnswer.compareTo(studentAnswer);
    if(test == 0)
    jop2.showMessageDialog(null,"Right Answer Well Done!");
    else
    jop.showMessageDialog(null,"Wrong Answer Try Again!");
    aConnection.close();
    catch (SQLException e) { System.exit(9);}
    }

    My suggestion is to loop through the student answer ( make a copy of it if you need it for other purposes ) and remove all the spaces and carriage returns and then compare them. Here's an example:
    StringBuffer tempBuffer( studentAnswer );
    while( tempBuffer.indexOf( " " ) != -1 )
    tempBuffer.deleteCharAt( tempBuffer.indexOf( " " ) );
    You could use this to also check for newline characters \t and carriage returns ( not sure what ascii character is used for that ). Also the String method .trim() will remove all whitespace before and after the string ( but not say, spaces between words ).

  • Read from file, compare string and return a part

    Hello, is there a reasonable good way to read text file containing information, and if string comparison is successfull, return a nother part of the string.
    What i have done so far:
    set file_name to (path to desktop as text) & "filename.txt"
    set F to open for access tiedosto with write permission
    set file_information to (read F)
    close access F
    (i will be moving this to Application Support/Appname/ when i figure it out).
    The data in the file is in following format
    12234567890Name1
    98765432123Name2
    92347928347Name3
    What im stuck now is:
    I need to compare each line the 10 numbers with search string, if match is found, the name part should be returned.
    Any idea's?

    You already read in the text file, so you need to put the data thru a repeat loop:
    repeat with name_part in paragraphs of file_information
    -- ((character 1 thru 10 of name_part) as string) is the first 10 digits of name part
    if ((character 1 thru 10 of name_part) as string) is search_string then return name_part
    end

  • Trying to compare string array using equals not working

    Hi,
    im prolly being really dumb here, but i am trying to compare 2 string arrays using the following code:
    if(array.equals(copymearray))
    System.out.println("they match");
    else
    {System.out.println("dont match");}
    the trouble is that even though they do match i keep getting dont match, can anyone tell me why?

    try
    if (Arrays.equals(array, copymearray))
    System.out.println("they match");
    else
    {System.out.println("dont match");}

Maybe you are looking for

  • Work with images in netBeans Help needed !

    Hai Guys, I have problem in inserting image in JFrame(In netBeans). Can any one tell me the way to insert an image to JFrame and save that image in my SQL database? Guys this is a very important task to me so please help me ! Thanks for watching / re

  • Best import settings for re-mastered Beatles CDs?

    I'm getting the Beatles remastered CDs, and am wondering what would be the best import settings in iTunes to really hear the difference. WAVE encoder? Apple lossless? AAC? And would there be a difference in what settings I choose if I were to get e m

  • Batch date change corrupts the dates

    I need some help with the batch name change in iPhoto. I recently tried to change some dates of an entire event to 12/25/2008. Once the batch change was done, the dates all appear as a corrupted year of 12/09/-2007 with the line in them. They then di

  • Cisco ISE authorization

    Hi I want to find out if its possible on ISE dot1x implementation to authenticate domain machines using EAP-TLS (certificate) and after successful authentication, authorize the user using AD domain users. I cant seem to get this to work, the ISE just

  • Nikon D2X NEF Raw file not recognized anymore...??

    Strange happenings... My projects which contain new and older .NEF friles from the nikon D2X are no longer readable by Aperture - What gives? I had been able to work them before, but not now... Haven;t used AA in a few weeks so not sure if the 10.4.5