2013-12-10 61 views
0

我按照產品規格或根據其配置顯示數據。如何刪除空白數據?

配置顯示頁面左側。當用戶選擇配置時,應該過濾相關數據。 我已經像屏幕尺寸,RAM,HDD,顏色,大小,處理器,光盤驅動器等 並根據它我顯示像2GB,4GB,2.2GHz的,藍,320GB等 enter image description here

數據屬性的類別

但我的問題是所有類別顯示,如果它的子數據存在與否。 我不想顯示類別如果子數據不存在像Screen Size是空白的,那麼它不應該顯示。

我的JSP代碼:

<% 
      List<String> attribNameList = (List<String>)request.getAttribute("attribName"); 
      List<String> attribValueList = (List<String>)request.getAttribute("attribValue"); 
      List<String> attribDataList = (List<String>)request.getAttribute("attribData"); 
      List<Integer> acfIDList = (List<Integer>)request.getAttribute("attribacID"); 

      List<Integer> acIDList = (List<Integer>)request.getAttribute("acID"); 
      List<String> acNAMEList = (List<String>)request.getAttribute("acNAME"); 


      String aname,aval,adata,acname; 
      Integer acfid,acid; 

      for(int i=0;i<acIDList.size();i++) 
      { 
       acid=acIDList.get(i); 
       acname=acNAMEList.get(i); 
       //Print Category 
       %> 
        <a style="color: black;"><%= acname %></a><br> 
       <% 

       for(int i1=0;i1<attribNameList.size();i1++) 
       { 
        aname = attribNameList.get(i1); 
        aval = attribValueList.get(i1); 
        adata = attribDataList.get(i1); 
        acfid = acfIDList.get(i1);       

        if(acid == acfid) 
        { 
         //Print Attribute 
         %><br> 
          <%-- <a><%= aname %></a> &nbsp; --%> 
          <a><%= aval %></a> &nbsp; 
          <% 
           if(adata == null) 
           { 

           } 
           else 
           { 
            %> 
             <a><%= adata %></a> 
            <% 
           } 

        } 
       } 
       %> 
       <br> 
       <% 
      } 

     %> 

Here `acIDList` is a attribute category id and `acnameList` is category name list and `acfIDList` is a `foreign key` in attribute_master table so I have put a if condition that when `acID` and `acfID` matches it creates List and under it sub data display. 

aval是屬性值是2,4,2.2, etc.adata is for GB, GHz, MP, etc.

所以我想刪除acName是空白。

我不想顯示的類別名稱,如果不存在的數據,所以應我必須把一些條件上

<a style="color: black;"><%= acname %></a><br> 

線。 任何建議,請..

+0

變化如果(酸== acfid)if(酸== acfid &&!aval.equals(「」)) – jsjunkie

+3

只是一個方面的說法,爲了得到一個可維護的應用程序考慮將視圖(即jsp)從應用邏輯。 – Henry

+0

我認爲檢查是否(酸 - acfid &&!aval.isEmpty()&&!aname.isEmpty()) – Neha

回答

1

我建議你嘗試的邏輯這樣..解決您的問題..

for(int i=0;i<acIDList.size();i++) 
     { 
      int acid=acIDList.get(i); 
      acname=acNAMEList.get(i); 
      //Print Category     
      int i = getIndex(acid); 
     if(i != -1)    
     {  aname = attribNameList.get(i); 
       aval = attribValueList.get(i); 
       adata = attribDataList.get(i); 
       //Print full data 
     if(!aval.equals("")) //add your cond to check empty .. 
      { %> 
       <a style="color: black;"><%= acname %></a><br> 
       <% 
        %><br> 
         <%-- <a><%= aname %></a> &nbsp; --%> 
         <a><%= aval %></a> &nbsp; 
         <% 
          if(adata == null) 
          {   /*add you msg or html in case of null*/     } 
          else //here all html with content and design 
          { %> <a><%= adata %></a> 
           <% 
          } 
       } } 
      %> <br> <% 
     } 

這個你可以自定義上或任何服務器的Util類..

function int getIndex(int acid) 
{ 
    for(int i1=0;i1<attribNameList.size();i1++) 
      { 
       if(acid == acfIDList.get(i1)) 
       { return il; } 
      } 
    return -1;  
} 
+0

下面的代碼片段呢?我必須在哪裏使用它? –

+0

你需要在cond ..中寫入html if(!aval.qquals(「」)){} ..如果你詢問getindex(),你可以在jsp開頭定義jsp <% %>。參考 - http://stackoverflow.com/questions/826932/declaring-functions-in-jsp – Neha

+0

它顯示我'功能'下的錯誤。 –

0

不知道如果我得到這個正確的,但如果你需要省略空白\空值,可以使用

<c:if test="${CONDITION}"> 
</c:if> 

標籤

1

更改您若條件爲低於

if(adata != null)         
{ 
    %> 
    <%-- <a><%= aname %></a> &nbsp; --%> 
    <a><%= aval %></a> &nbsp; 
     <a><%= adata %></a> 
    <% 
} 

將您的aname印在您的if子句內。

也刪除acname打印添加如果條件如下。

//Print Category 
if (attribNameList.size() != 0 
    %> 
     <a style="color: black;"><%= acname %></a><br> 
    <% 
} 

因此,您的最終代碼應該看起來像什麼。

String aname,aval,adata,acname; 
Integer acfid,acid; 

for(int i=0;i<acIDList.size();i++) { 

    .... 
    .... 

    //Print Category 
    if (attribNameList.size() != 0) 
    { 
    %> 
     <a style="color: black;"><%= acname %></a><br> 
    <%  
    } 
    for(int i1=0;i1<attribNameList.size();i1++) { 
     .... 
     .... 

     //Print Attribute 
     if(adata != null)   
     { 
     %>   
     <a><%= aval %></a> &nbsp; 
     <a><%= adata %></a>    
     } 
     %> 
    <br> 
<% 
} 
%> 
+0

我不想顯示類別名稱,所以我必須將'<%= acname %>
'處於狀態? –

+1

編輯回覆。只需在印刷'acname'時添加一個條件 – Jayamohan

+0

先生,我實際上沒有讓你知道你想告訴的是什麼? @我將不得不使用'attribNameList'條件代碼? –