request中有一个set假设是a ,问怎么访问它的第一个元素。

解决方案 »

  1.   

       <select name="newClassId" id="newClassId">
              <c:forEach var="ibClass" items="${ibClasses}">
              <option value="<c:out value="${ibClass.id}" />" 
               <c:if test="${ibClass.id eq agent.ibClasses[0].id}" > selected </c:if> 
              >
               <c:out value="${ibClass.className}" /> 
              </option>
              </c:forEach>
            </select>           >
    上面的代码报下面的错误
    javax.servlet.jsp.JspTagException: javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "test" with value "${ibClass.id eq agent.ibClasses[0].id}": Unable to find a value for "0" in object of class "org.hibernate.collection.PersistentSet" using operator "[]" (null)但是下面代码不报错
       <select name="newClassId" id="newClassId">
              <c:forEach var="ibClass" items="${agent.ibClasses}">
              <option value="<c:out value="${ibClass.id}" />" >
               <c:out value="${ibClass.className}" /> 
              </option>
              </c:forEach>
            </select>
      

  2.   

    试了一下<c:out value="${a[0]}"/>确实不行,用List的可以,用Set不行,想其它办法吧
      

  3.   

    谁可以给翻译一下el规范中的下面着段,不盛感激!
    Operators [] and .
    The EL follows ECMAScript in unifying the treatment of the . and [] operators.
    expr-a.identifier-b is equivalent to expr-a["identifier-b"]; that is, the
    identifier identifier-b is used to construct a literal whose value is the identifier,
    and then the [] operator is used with that value.
    To evaluate expr-a[expr-b]:
    ■ Evaluate expr-a into value-a.
    ■ If value-a is null:
    ■ If expr-a[expr-b] is the last property being resolved:
    ■ If the expression is a value expression and
    ValueExpression.getValue(context) was called to initiate this
    expression evaluation, return null.
    ■ Otherwise, throw PropertyNotFoundException.
    [trying to de-reference null for an lvalue]
    ■ Otherwise, return null.
    ■ Evaluate expr-b into value-b .
    ■ If value-b is null:
    ■ If expr-a[expr-b] is the last property being resolved:
    ■ If the expression is a value expression and
    ValueExpression.getValue(context) was called to initiate this
    expression evaluation, return null.
    ■ Otherwise, throw PropertyNotFoundException.
    [trying to de-reference null for an lvalue]
    Chapter 1 Language Syntax and Semantics 9
    ■ Otherwise, return null.
    ■ If the expression is a value expression:
    ■ If expr-a[expr-b] is the last property being resolved:
    ■ If ValueExpression.getValue(context) was called to initiate this
    expression evaluation, invoke elResolver.getValue(context,
    value-a, value-b).
    ■ If ValueExpression.getType(context) was called, invoke
    elResolver.getType(context, value-a, value-b).
    ■ If ValueExpression.isReadOnly(context) was called, invoke
    elResolver.isReadOnly(context, value-a, value-b).
    ■ If ValueExpression.setValue(context, val) was called, invoke
    elResolver.setValue(context, value-a, value-b, val).
    ■ Otherwise:
    ■ Invoke elResolver.getValue(value-a, value-b).
    ■ Otherwise, the expression is a method expression:
    ■ If expr-a[expr-b] is the last property being resolved:
    ■ Coerce value-b to String.
    ■ Find the method on object value-a with name value-b and with the set of
    expected parameter types provided at parse time. If the method does not
    exist, or the return type does not match the expected return type provided at
    parse time, throw MethodNotFoundException.
    ■ If MethodExpression.invoke(context, params) was called, invoke
    the found method with the parameters passed to the invoke method.
    ■ If MethodExpression.getMethodInfo(context) was called, construct
    and return a new MethodInfo object.
    ■ Otherwise:
    ■ Invoke elResolver.getValue(value-a, value-b).
      

  4.   

    这个问题是因为hibernate引起的。
    系统原来的数据库设计中,一对多关联还用了张连接表,我不知道怎么映射带连接表的多对一,所以只能用多对多来映射,于是出现了上面的问题。
    请谁知道怎么映射带连接表的多对一也行。
      

  5.   

    运算符[]和.
    EL遵循ECMAScript中对.和[]运算符的统一处理。
    expr-a.identifier-b 等价于 expr-a["identifier-b"]。也就是说,
    标识identifier-b是用来构造一个值为标识符的描述,而[]与这个值一起使用。计算expr-a[expr-b]的值:
    ■ 计算 expr-a 的值为 value-a.
    ■ 如果 value-a 为空:
    ■ 如果 expr-a[expr-b] 是最后一个要处理的属性:
    ■ 如果这个表达式是一个值表达式,
       并且调用ValueExpression.getValue(context)来启动表达式的计算,则返回 null。
    ■ 否则, 抛出 PropertyNotFoundException 异常
    [trying to de-reference null for an lvalue]
    ■ 否则, 返回 null.
    ■ 计算 expr-b 的值为 value-b .
    ■ 如果 value-b 为空:
    ■ 如果 expr-a[expr-b] 是最后一个要处理的属性:
    ■ 如果这个表达式是一个值表达式,
       并且调用ValueExpression.getValue(context)来启动表达式的计算,则返回 null。
    ■ 否则, 抛出 PropertyNotFoundException 异常
    [trying to de-reference null for an lvalue]
    ■ 否则, 返回 null.
    ■ 如果这个表达式是一个值表达式:
    ■ 如果 expr-a[expr-b] 是最后一个要处理的属性:
    ■ 如果调用ValueExpression.getValue(context)来启动表达式的计算, 唤醒 elResolver.getValue(context,
    value-a, value-b).
    ■ 如果 ValueExpression.getType(context) 被调用, 唤醒elResolver.getType(context, value-a, value-b).
    ■ 如果 ValueExpression.isReadOnly(context) 被调用, 唤醒elResolver.isReadOnly(context, value-a, value-b).
    ■ 如果 ValueExpression.setValue(context, val) 被调用, 唤醒elResolver.setValue(context, value-a, value-b, val).
    ■ 否则:
    ■ 唤醒 elResolver.getValue(value-a, value-b).
    ■ 否则, 这个表达式是一个方法表达式:
    ■ 如果 expr-a[expr-b] 是最后一个要处理的属性:
    ■ Coerce value-b 为字符串.
    ■ 在value-a对象中查找名为value-b的方法,它的参数类型列表是在解析时提供的。如果这个方法不存在,或者返回类型与解析时提供的期望类型不符,抛出MethodNotFoundException异常.
    ■ 如果 MethodExpression.invoke(context, params) 被调用, 用传入唤醒方法的参数来唤醒the found method 
    ■ 如果 MethodExpression.getMethodInfo(context) 被调用, 构建且返回 一个新的MethodInfo 对象
    ■ 否则:
    ■ 唤醒elResolver.getValue(value-a, value-b).