facebook

myeclipse quirk with &&

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #261758 Reply

    Bob
    Member

    I have: if (reqMonth == null && reqYear == null) {
    but myeclipse keeps reporting:
    Invalid character used in text string &&

    Is there a setting missing to make myeclipse it recognize && as both reqMonth and reqYear are true?

    #261787 Reply

    Riyad Kalla
    Member

    Bob,
    I need a bit more information from you. What kind of file is this code in? A normal Java file? A JSP? A JavaScript file? Also can you paste the whole file so I can try and duplicate this locally?

    #262846 Reply

    Adam Cohen
    Member

    We noticed the same warning after upgrade to MyEclipse 5.10

    The use of && is in some Javascript that is inside a JSP

    In our setup, we have some JSP’s that are includes as Tiles. These fragments mostly contain Javascript but invoke some JSTL and EL. The && operator is actually a Javascript operator that the JSP validator seems to be getting caught on.

    Here’s a chunk of the JSP:

    
    <%@ page language="java"%>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-template" prefix="template" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-nested" prefix="nested" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
    <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
    
    // Javascripts used by all pages in the ERS system
    
    // Display help
    
    
    function ers_displayHelp(whichPage) {
         smallWindow = window.open(whichPage,"help","width=360,height=480,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1");
         //to debug comment out the line above and uncomment the line below
         //smallWindow = window.open(whichPage,"help","width=360,height=480,toolbar=1,location=1,directories=0,status=0,menubar=1,scrollbars=0,resizable=1");
        window.smallWindow.focus();
        return false;
    }
    
    //init the pageErrors array
    var pageErrors = new Array() ;
    var pageErrorAlertHeader = 'Status' ;
    
    function alertErrors() {
        errorMsg = '';
        for (count in pageErrors) {
            errorMsg += '<p><b>' + pageErrors[count] + '</b><br/>';
        }
        ersAlert(errorMsg + '</p>');
    }
    
    // Event handling scripts
    
    function attachEvent(eventName, element, funcName) {
        // make sure that we have an element
        if( !element ) return;
        // if the element isn't already an object then make it so
        if( typeof element == "string" ) element = document.getElementById( element );
        // cover all the various event addition methods
        if( element.addEventListener )
            element.addEventListener( eventName, funcName, true );
        else if( element.attachEvent )
            element.attachEvent( "on" + eventName, funcName );
        else
            element[ "on" + eventName ] = funcName;
    }
    
    function detachEvent(eventName, element, funcName) {
        // make sure that we have an element
        if( !element ) return;
        // if the element isn't already an object then make it so
        if( typeof element == "string" ) element = document.getElementById( element );
        // cover all the various event addition methods
        if( element.removeEventListener )
            element.removeEventListener(eventName, funcName, true)
        else if( element.detachEvent )
            element.detachEvent( "on" + eventName, funcName );
        else
            element[ "on" + eventName ] = null;
    }
    
    function parentRow(element) {
        //if (element.tagName.toLowerCase() == 'tr') return element;
        var parent = element.parentNode;
        while( parent ) {
            if( parent.tagName && parent.tagName.toLowerCase() == 'tr' )
                return parent;
            parent = parent.parentNode;
        }
        return null;
    }
    

    The warning is raised in function parentRow where the && operator is used.

    #262854 Reply

    Riyad Kalla
    Member

    Thank you for the additional post, I’m adding that information to an existing report that we need to investigate in the HTML/JS parser.

    #270833 Reply

    Bob
    Member

    if(tmo >= && tmo <= 12) {
    mo = tmo -1;
    yr = tyr;
    ourDay = 0;
    }

    #271396 Reply

    Bob
    Member

    This works: </tr>
    <%
    for (int i = 1; i<= 6 && day <= maxDay; i++) {
    %>
    <tr>

    and this is reported as [ Syntax error on token “&&”, delete this token ] error:

    if (tmo >= && tmo <= 12)

    #271406 Reply

    Riyad Kalla
    Member

    bobparis,
    I couldn’t get that construct to validate in 2 other IDEs I tried either… what IDE or JS editor have you used that validated that statement?

    #272520 Reply

    Bob
    Member

    private void setup() {
    GregorianCalendar now = new GregorianCalendar();
    int yr = now.get(Calendar.YEAR);
    int mo = now.get(Calendar.MONTH);
    ourDay = now.get(Calendar.DAY_OF_MONTH);

    if (reqMonth == null && reqYear == null) {
    HttpServletRequest request =
    (HttpServletRequest)pageContext.getRequest();
    reqMonth = request.getParameter(“month”);
    reqYear = request.getParameter(“year”);
    }

    #272521 Reply

    Bob
    Member

    package test.jsp.taglibs;

    import java.util.Calendar;
    import java.util.GregorianCalendar;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.jsp.tagext.TagSupport;
    import javax.servlet.jsp.JspWriter;

    public class CalendarTag extends TagSupport {
    private int maxDay;
    private int ourDay;
    private int dayOfWeek;
    private int day;
    private int year;
    private String monthName;
    private String reqMonth = null;
    private String reqYear = null;

    public CalendarTag() {
    System.out.println(“Calendar tag initializing”);
    }

    private void setup() {
    GregorianCalendar now = new GregorianCalendar();
    int yr = now.get(Calendar.YEAR);
    int mo = now.get(Calendar.MONTH);
    ourDay = now.get(Calendar.DAY_OF_MONTH);

    if (reqMonth == null && reqYear == null) {
    HttpServletRequest request =
    (HttpServletRequest)pageContext.getRequest();
    reqMonth = request.getParameter(“month”);
    reqYear = request.getParameter(“year”);
    }

    if (reqMonth != null && reqYear != null) {
    try {
    int tmo = new Integer(reqMonth).intValue();
    int tyr = new Integer(reqYear).intValue();
    if (tmo >= 1 && tmo <= 12) {
    if ((tmo-1) != mo || tyr != yr) ourDay = 0;
    mo = tmo – 1;
    yr = tyr;
    }
    } catch (Exception e) {
    System.err.println(“Badly formatted month or year”);
    }
    }

    GregorianCalendar start = new GregorianCalendar(yr, mo, 1);

    int month = start.get(Calendar.MONTH);
    year = start.get(Calendar.YEAR);
    monthName = “”;

    if (month == Calendar.JANUARY) monthName = “January”;
    else if (month == Calendar.FEBRUARY) monthName = “Febuary”;
    else if (month == Calendar.MARCH) monthName = “March”;
    else if (month == Calendar.APRIL) monthName = “April”;
    else if (month == Calendar.MAY) monthName = “May”;
    else if (month == Calendar.JUNE) monthName = “June”;
    else if (month == Calendar.JULY) monthName = “July”;
    else if (month == Calendar.AUGUST) monthName = “August”;
    else if (month == Calendar.SEPTEMBER) monthName = “September”;
    else if (month == Calendar.OCTOBER) monthName = “October”;
    else if (month == Calendar.NOVEMBER) monthName = “November”;
    else if (month == Calendar.DECEMBER) monthName = “December”;

    dayOfWeek = start.get(Calendar.DAY_OF_WEEK);
    maxDay = start.getActualMaximum(Calendar.DAY_OF_MONTH);

    day = 1;
    }

    public void setMonth(String month) {
    this.reqMonth = month;
    }

    public void setYear(String year) {
    this.reqYear = year;
    }

    public int doStartTag() {
    setup();

    try {
    JspWriter out = pageContext.getOut();
    out.println(“<table border=\”1\”>”);
    out.println(” <tr bgcolor=\”lightGrey\””);
    out.println(” <td align=\”center\” colspan=\”7\”>”);
    out.println(” <b>” + monthName + ” ” + year + “</b>”);
    out.println(” </td>”);
    out.println(” </tr>”);
    out.println(” <tr bgcolor=\”lightGrey\”>”);
    out.println(” <td align=\”center\” width=\”50\”>SUN</td>”);
    out.println(” <td align=\”center\” width=\”50\”>MON</td>”);
    out.println(” <td align=\”center\” width=\”50\”>TUE</td>”);
    out.println(” <td align=\”center\” width=\”50\”>WED</td>”);
    out.println(” <td align=\”center\” width=\”50\”>THU</td>”);
    out.println(” <td align=\”center\” width=\”50\”>FRI</td>”);
    out.println(” <td align=\”center\” width=\”50\”>SAT</td>”);
    out.println(” </tr>”);

    for (int i = 1; i <= 6 && day <= maxDay; i++) {
    out.println(“<tr>”);
    for (int j = 1; j <= 7; j++) {
    if (day == ourDay) out.println(“<td bgcolor=\”red\”>”);
    else out.println(“<td>”);

    if (i == 1 && j < dayOfWeek) out.println(” “);
    else if (day <= maxDay) out.println(day++);

    out.println(“</td>”);
    }
    out.println(“</tr>”);
    }

    out.println(“</table>”);
    } catch (Exception e) {
    throw new Error(“Unable to generate calendar”);
    }

    return SKIP_BODY;
    }

    }

    #272542 Reply

    Riyad Kalla
    Member

    Bob,
    If you want to post a huge code dump I need some sort of context as to what it’s for, why you are posting it, any questions you have, etc.

    If this was in reference to my previous post, this code dump doesn’t contain the construct anywhere that you were complaining about not working, specifically:

    
    if (tmo >= && tmo <= 12)
    

    But if you just wanted to post a ton of code, that’s fine too I suppose.

    #273903 Reply

    Bob
    Member

    Ok so we are both frustrated.

    I am working on a scheduler/calendar app from “Tomcat 5 Unleashed” by Moczar. in it there is the “huge code dump” as a example. I tried to take that and expand it.

    MyEclipse chokes on “if (reqMonth == null && reqYear == null) { ” because of the && in it. This happened as well in the file I was working on in the original post. Other people have seen the error to in other instances so I am not crazy at least.

    I just odn’t undserstand why MyEclipse has a problem with it.

    #273906 Reply

    Riyad Kalla
    Member

    Bob,
    I’m not sure why you are seeing an error or warning, the file you posted is fine. I just imported it into a Web Project, and saved it. It compiles without any errors and the only warning is to add a SERIAL UID variable which is optional.

    Please see my attached filed for the project I created to test it.

    Attachments:
    You must be logged in to view attached files.
Viewing 12 posts - 1 through 12 (of 12 total)
Reply To: myeclipse quirk with &&

You must be logged in to post in the forum log in