Solved

Struts logic-el match problem

Posted on 2004-10-22
2,279 Views
Last Modified: 2013-11-24
Hi,

I'm having trouble creating a match in my jsp using struts. I have the following line within an two iterate tages

 <logic-el:match name="CCStatus" property="person.areaCode.areaCode" value="${AreaCode.areaCode}">            

The first iterate tag is
<logic:iterate id="AreaCode" name="areaCodes">

which just itereates through an arraylist containing AreaCode objects. (the AreaCode object has a String attribute, areaCode, which is what is been called in the value element above)

the second iterate tag is
<logic:iterate id="CCStatus" name="cStatus">
this arraylist contains objects of CCStatus which has a person object as an attribute. The person object then has a AreaCode object attribute, hence the person.areaCode.areaCode property.

Can anyone think of a reason why there is no match coming up? I've done tested such as
<bean:write name="CCStatus" property="person.areaCode.areaCode"/>
<bean:write name="AreaCode" property="areaCode"/>
and the values are printed out, so its not that the object are null.

Any help would be great,
Thanks

0
Question by:fyness
    19 Comments
     
    LVL 35

    Expert Comment

    by:TimYates
    is

    <logic:iterate id="AreaCode" name="areaCodes">
        <logic:iterate id="CCStatus" name="cStatus">
            <logic:equal name="CCStatus" property="person.areaCode.areaCode" value="AreaCode.areaCode">
               
            </logic:equal>
        </logic:iterate>
    </logic:iterate>

    any better?
    0
     

    Author Comment

    by:fyness
    Nope, still just shows all the values in all the area codes, i.e. theres no seperation for persons in a different area code
    0
     
    LVL 35

    Expert Comment

    by:TimYates
    can you post the actual code?
    0
     

    Author Comment

    by:fyness
    Not really meant to post the code, but here is the basic jist of it
    Thanks

       <logic:present name="CCStatus">
          <logic:iterate id="AreaCode" name="areaCodes">
                    <table align="center" border="0" cellspacing="2" cellpadding="2" class="datatable">
                    <tr>
                      <td colspan="5" align="center">
                        <h2>
                          <bean:write name="AreaCode" property="areaCode" />
                        </h2>                      
                      </td>                
                    </tr>
                      <tr>
                        <td>
                          <h2>
                            <bean:message key="formdata.personname" />
                          </h2>
                        </td>
     </tr>
                <logic:iterate id="CCStatus" name="cStatus">
      <logic-el:match name="CCStatus" property="person.areaCode.areaCode" value="${AreaCode.areaCode}">               <tr>
                          <td class="SmallText">
                                  <bean:write name="CCStatus" property="perosn.name"/>
                         </td>       
      </logic-el:match>                 
                      </logic:iterate>
                    </table>
                    </logic:iterate>
                    </logic:present>      
                   
    0
     
    LVL 35

    Expert Comment

    by:TimYates
      <logic:present name="CCStatus">

    is that meant to be:

       <logic:present name="cStatus">

    ?

    As you have CCStatus defined twice by the looks of that...
    0
     

    Author Comment

    by:fyness
    yes sorry its cStatus
    0
     
    LVL 35

    Expert Comment

    by:TimYates
    Hmmm...I've never used the logic-el tags, but it looks like there is a logic-el:iterate tag...  Maybe you need to use this when you are using logic-el:match?

    Can you try:

    <logic:present name="cStatus">
        <logic-el:iterate id="AreaCode" name="areaCodes">
            <table align="center" border="0" cellspacing="2" cellpadding="2" class="datatable">
                <tr>
                    <td colspan="5" align="center">
                        <h2>
                            <bean:write name="AreaCode" property="areaCode" />
                        </h2>                      
                    </td>                
                </tr>
                <tr>
                    <td>
                        <h2>
                            <bean:message key="formdata.personname" />
                        </h2>
                    </td>
                </tr>
                <logic-el:iterate id="CCStatus" name="cStatus">
                    <logic-el:match name="CCStatus" property="person.areaCode.areaCode" value="${AreaCode.areaCode}">            
                        <tr>
                            <td class="SmallText">
                                <bean:write name="CCStatus" property="perosn.name"/>
                            </td>      
                        </tr>
                    </logic-el:match>                
                </logic-el:iterate>
            </table>
        </logic-el:iterate>
    </logic:present>  
    0
     
    LVL 35

    Expert Comment

    by:TimYates
    Obviously,

                                <bean:write name="CCStatus" property="perosn.name"/>

    should be

                                <bean:write name="CCStatus" property="person.name"/>

    ;)
    0
     

    Author Comment

    by:fyness
    the logic-el:iterate doesnt work, it cant find the session when i use it. I tried it without the el on the match so as logic:match and no joy.

    Not sure what the difference is with the above?
    0
     
    LVL 35

    Expert Comment

    by:TimYates
    It really is odd...

    I assume:

                <logic:iterate id="CCStatus" name="cStatus">
                    <% if( ((CStatusClass)CCStatus).getPerson().getAreaCode().getAreaCode().equals( ((AreaCodeClass)AreaCode).getAreaCode() ) )
                          { %>
                        <tr>
                            <td class="SmallText">
                                <bean:write name="CCStatus" property="perosn.name"/>
                            </td>      
                        </tr>
                    <% } %>
                </logic:iterate>
     
    works (if you replace CStatusClass and AreaCodeClass with the actual qualified classnames for those two)

    As I said, though I never used logic:match before...always logic:equal

    Tim
    0
     

    Author Comment

    by:fyness

    yeah the values are all there, the i tried using equal and i just get empty tables
    0
     
    LVL 35

    Expert Comment

    by:TimYates
                   <logic:equal name="CCStatus" property="person.areaCode.areaCode" value="<%= ((AreaCodeClass)AreaCode).getAreaCode() %>">            

    May work...

    What is:

    person.areaCode.areaCode

    and

    AreaCode.areaCode?  Are they both Strings?  Or an object of some sort or other?
    0
     

    Author Comment

    by:fyness
    person is an object attribute of CCStatus, and within perosn there is an AreaCode object attribute. The areacode class then has a string attribut areaCode.
    0
     
    LVL 35

    Expert Comment

    by:TimYates
    Cool, so it's two trings...

    That's bizarre that it doesn't work right... :-/

    Does that last logic:equal work (2 comments up from this one)?
    0
     
    LVL 35

    Expert Comment

    by:TimYates
    Hang on...the bit on this page http://struts.apache.org/faqs/struts-el.html which says;

    "The "logic:match" and "logic:notMatch" tags have an additional attribute named "expr", which can take any value, and will be used as the value to compare against, in addition to the choices of "cookie", "header", "name"/"property", and "parameter"."

    has got me thinking....it's not:

                    <logic-el:match name="CCStatus" property="person.areaCode.areaCode" expr="${AreaCode.areaCode}">            

    (expr instead of value)
    0
     

    Author Comment

    by:fyness
    Still no joy, am just getting all values regardless of wheather there is a match or not
    0
     
    LVL 35

    Accepted Solution

    by:
    How's this:

    <logic:present name="cStatus">
        <logic:iterate id="AreaCode" name="areaCodes">
            <bean:define id="code" name="AreaCode" property="areaCode" />
            <table align="center" border="0" cellspacing="2" cellpadding="2" class="datatable">
                <tr>
                    <td colspan="5" align="center">
                        <h2>
                            <bean:write name="AreaCode" property="areaCode" />
                        </h2>                      
                    </td>                
                </tr>
                <tr>
                    <td>
                        <h2>
                            <bean:message key="formdata.personname" />
                        </h2>
                    </td>
                </tr>
                <logic:iterate id="CCStatus" name="cStatus">
                    <logic:equal name="CCStatus" property="person.areaCode.areaCode" value="<%= code %>">            
                        <tr>
                            <td class="SmallText">
                                <bean:write name="CCStatus" property="person.name"/>
                            </td>      
                        </tr>
                    </logic:equal>                
                </logic:iterate>
            </table>
        </logic:iterate>
    </logic:present>  

    Notice the bean:define to define this current area code into the value "code", then the logic:equal with <%= code %> for the value...
    0
     

    Author Comment

    by:fyness
    thanks!
    0
     
    LVL 35

    Expert Comment

    by:TimYates
    :-)  It worked! :-)

    Cool!

    Good luck with it all :-)

    Tim
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    The viewer will learn how to implement Singleton Design Pattern in Java.
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    857 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now