2013-10-15 72 views
0

嘗試獲取對象值時發生異常。 它在我們的應用程序只有web應用程序入侵之前就工作過了,但是當我們在application.xml中添加包含APP-INF/lib的ejb包時出現異常:javax.el.PropertyNotFoundException:類java.lang.String沒有屬性「類型」。在我的調查中:item value是String,但不是由getItems方法返回的對象。爲什麼會發生這種異常。異常類java.lang.String沒有'type'屬性

感謝您的任何想法。

這裏是jsp頁面的代碼。

<div id="report_items"> 
<c:forEach items="#{repcatTree.items}" var="item"> 
    <div style="padding-top:7px; padding-bottom:7px; padding-right:15px;"> 
     <span class="report_item_category_class"> 
     <h:commandLink rendered="#{item.type == 'category'}" action="#{item.onNodeClicked}" 
       styleClass="default_link"> 
      <h:graphicImage url="/views/tree/images/folder_big.gif" /> 
      <h:outputText value="#{item.attributes.FILE_NAME}" style="font-size:14px; font-weight:bold; padding-left:5px" /> 
     </h:commandLink> 
     <h:commandLink rendered="#{item.type == 'report'}" styleClass="default_link" 
        action="action_report_run" title="#{item.cells['report_name'].toolTip}"> 
      <h:graphicImage url="/icon?rdd_path=#{item.attributes.RDD_PATH}" />    
      <h:outputText value="#{item.cells['report_name'].display}" 
          style="font-size:14px; font-weight:bold; padding-left:5px" /> 

      <f:param name="nodePath" value="#{item.attributes.RDD_PATH}" /> 
      <f:param name="nodePrettyPath" value="#{item.attributes.CAT_PATH}" /> 
      </h:commandLink> 
     </span> 
    </div> 
</c:forEach> 
</div> 

這裏是我的課。我刪除沒有需要的部分代碼。

public class RepcatTreeModel extends TreeModel implements Serializable { 

    public RepcatTreeModel() { 
     super(); 
    } 

    public Collection getItems() { 
     items = new ArrayList(); 
     items.addAll(getActiveNode().getChildren()); 
     items.addAll(getTableModel().getRows()); 
     Object[] _items = items.toArray(); 
     Arrays.sort(_items, new Comparator() { 
      public int compare(Object o1, Object o2) { 
       int result = 0; 
       if (o1 instanceof TreeNodeModel && o2 instanceof TreeNodeModel) { 
        TreeNodeModel nodeA = (TreeNodeModel)o1; 
        TreeNodeModel nodeB = (TreeNodeModel)o2; 
        String strA = (String)nodeA.getAttributes().get(RepcatTreeModel.ATTR_NAME); 
        String strB = (String)nodeB.getAttributes().get(RepcatTreeModel.ATTR_NAME); 

        if (strB.compareToIgnoreCase(strA) < 0) 
         result = 1; 
        else 
         if (strB.compareToIgnoreCase(strA) > 0) 
          result = -1; 
       } 
       else 
        if (o1 instanceof RowModel && o2 instanceof RowModel) { 
         RowModel nodeA = (RowModel)o1; 
         RowModel nodeB = (RowModel)o2; 
         String strTmp = (String)nodeA.getAttributes().get(RepcatTreeModel.ROW_ATTR_RDD_PATH); 
         String strA = strTmp.substring(strTmp.lastIndexOf('/')+1); 
         strTmp = (String)nodeB.getAttributes().get(RepcatTreeModel.ROW_ATTR_RDD_PATH); 
         String strB = strTmp.substring(strTmp.lastIndexOf('/')+1); 

         if (strB.compareToIgnoreCase(strA) < 0) 
          result = 1; 
         else 
          if (strB.compareToIgnoreCase(strA) > 0) 
           result = -1; 
        } 
       return result; 
      } 
     }); 
     items = new ArrayList(Arrays.asList(_items)); 
     return items; 
    } 

} 

回答

0

RepcatTree.getItems()返回字符串而不是類型的對象。這就是爲什麼你不能致電getType()項目。

+0

getItems預期收益類型,但我不明白爲什麼它的字符串。如果我將更改爲我將能夠獲得我的對象和它的工作,但我不能通過HTML標籤因爲它是空的。我只能通過$ {}表達式獲得jstl的值。 – Sergey

+0

當我試圖顯示項目它的輸出像一個字符串「repcatTree.items」 – Sergey

+0

你可以發佈你的'RecaptTree'類嗎? –

0

#{repcatTree.items}返回一個String對象列表。

在兩個<h:commandLink>組件,它們rendered屬性從

rendered="#{item.type == 'category'}" 

改變

rendered="#{item eq 'category'}" 
+0

#{repcatTree.items}返回我的類型對象,請參閱下面的註釋。 – Sergey

+0

僅供參考,以幫助我們:我們使用JFS1.2與\t \t <! - Glassfish V2 - > \t <! - Glassfish V3 - > – Sergey

+0

感謝您的建議,但我相信#{repcatTree.items}應該正確返回我的類型對象在即時表達$ {repcatTree.items}的情況下,它會返回正確的值,但在jsf標記中使用jstl變量是不可能的。我會非常感謝任何其他建議,有助於解決我的問題。非常感謝。 – Sergey

相關問題