2013-12-10 62 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'条件代码? –