Struts: nesting <bean:write>tag in a <logic:equal> tag (inside a javascript)

I have a javascript that makes a 'tree-view' for me. I managed to already get the tree-view to build trees whose values are taken from my db. The problem is, I want to be able to check the bean of the 'first' array such that if it equals the one located in the second array, it will print/iterate.

Here's a short explanation of my code: the changeItemProducts array is only used to get the 'subject' names. Inside each 'subject' are sub-entries. (For example, Paint has sub-entries like: watercolor, etc). Now, the changeItems array contains the sub-entries (I also added in this array from what 'subject' they come are from).

Now I want to check that if the value of the subject in the changeItems array = value of the subject in the changeItemProducts array, print all the sub-entries. If not, skip it (because it may not have any sub-entries yet in the db) and check the next entries.

Here's my Javascript code for it:

<logic:iterate id="changeItemProduct" name="changeItemProducts">

      folCA = insFld(foldersTree, gFld("<bean:write name="changeItemProduct" property="productName" />", ""))
            headCA = insDoc(folCA, gLnk("S", makeHeader("Title","#cccccc"), "",makeHeader("CR#","#cccccc"),makeHeader("Date Submitted","#cccccc"),makeHeader("Target Date","#cccccc"),makeHeader("Phase","#cccccc")))
            headCA.iconSrc = ICONPATH + "ftv2blank.gif"
               
            <logic:iterate id="changeItem" name="changeItems">
                <logic:equal name="changeItem" property="productName" value="<bean:write name="changeItemProduct" property="productName" /> ">
                    insDoc(folCA, gLnk("S", "<bean:write name="changeItem" property="title" />", "/ADM/GetWorkOrders.do?changeItemNumber=<bean:write name="changeItem" property="changeItemNumber" />", "<bean:write name="changeItem" property="changeItemNumber" />", "<bean:write name="changeItem" property="dateSubmitted" />", "<bean:write name="changeItem" property="targetDate" />", "<bean:write name="changeItem" property="phaseNumber" />"))
                </logic:equal>
            </logic:iterate>
               
</logic:iterate>

The error I get is: equal symbol expected

on this part of the code(at least I think it is this part of the code):

<logic:equal name="changeItem" property="productName" value="<bean:write name="changeItemProduct" property="productName" /> ">

I heard that nesting within a struts tag is not possible. Is there a way to do this? Thanks in advance!
cicoiiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kennethxuCommented:
you cannot use one tag as another tag's property value, try this:
<logic:equal name="changeItem" property="productName" value="<%=changeItemProduct.getProductName()%>">

let me know if you have further enquires

0
cicoiiAuthor Commented:
Hi kennethxu!

I tried the code you wrote but I'm getting an error when I load the page:


Generated servlet error:
    [javac] Compiling 1 source file

C:\tomcat\work\Standalone\localhost\ADM\jsp\Change Item\chi_list_jsp.java:133: cannot resolve symbol
symbol  : variable changeItemProducts
location: class org.apache.jsp.chi_list_jsp
              _jspx_th_logic_equal_0.setValue(changeItemProduct.getProductName());
                                              ^
1 error

Any ideas? Thanks again!
0
kennethxuCommented:
can you tell me how do you define your changeItemProduct bean? thanks.
0
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

znapsCommented:
Try this - It is similar to Kenneth's code and should work for all cases:

<bean:define id="prodName" name="changeItemProduct" property="productName/>

<logic:equal name="changeItem" property="productName" value="<%= prodName %>">

....rest of code...
0
znapsCommented:
Sorry, that should read:

<bean:define id="prodName" name="changeItemProduct" property="productName"/>

<logic:equal name="changeItem" value="<%= prodName %>">

....rest of code...
0
cicoiiAuthor Commented:
kennethxu,

When I try to use the bean:define or jsp:useBean with my code, I always end up getting an error. Am not quite sure how to use this though. I had always assumed that when I place my array in an logic:iterate it will be working ok. I also tried using znaps <bean:define> code but I also get an error (see below). Any help would be greatly appreciated. Thanks!

Znaps,

I tried out your code but am still getting an error similar to the one above:


Generated servlet error:
    [javac] Compiling 1 source file

C:\tomcat\work\Standalone\localhost\ADM\jsp\Change Item\chi_list_jsp.java:153: cannot resolve symbol
symbol  : method setValue (java.lang.Object)
location: class org.apache.struts.taglib.logic.EqualTag
              _jspx_th_logic_equal_0.setValue( prodName );
                                    ^
1 error

Any help would be greatly appreciated. Thanks!
0
kennethxuCommented:
can you post your full jsp page?
0
cicoiiAuthor Commented:
Hi kennethxu,

Thanks for all your replies. Hope you can help me with this one :-)

I've included the full jsp page as well as snippets of my java codes (in case this will be helpful in solving this problem)

Here's my full jsp page: (chi_list.jsp)

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ page import="com.hp.adm.changeItem.ListChangeItemsAction"%>
<%@ page import="com.hp.adm.changeItem.ChangeItem"%>
<%@ page import="com.hp.adm.changeItem.ChangeItemProduct"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML><HEAD><TITLE>Change Management portal</TITLE>

<!-- Code for browser detection -->
<script src="/ADM/doc_root/ua.js"></script>

<!-- Infrastructure code for the tree -->
<script src="/ADM/doc_root/ftiens4.js"></script>

<!-- Execution of the code that actually builds the specific tree.
     The variable foldersTree creates its structure with calls to
       gFld, insFld, and insDoc -->
<script>
// Decide if the names are links or just the icons
USETEXTLINKS = 1  //replace 0 with 1 for hyperlinks

// Decide if the tree is to start all open or just showing the root folders
STARTALLOPEN = 0 //replace 0 with 1 to show the whole tree

ICONPATH = '/ADM/images/' //change if the gif's folder is a subfolder, for example: '/ADM/images/'

foldersTree = gFld("", "")
foldersTree.iconSrc = ICONPATH + "s.gif"
<jsp:useBean id="changeItemProduct" type="com.hp.adm.changeItem.ChangeItemProduct"/>

<logic:iterate id="changeItemProduct" name="changeItemProducts">

      folCA = insFld(foldersTree, gFld("<bean:write name="changeItemProduct" property="productName" />", ""))
            headCA = insDoc(folCA, gLnk("S", makeHeader("Title","#cccccc"), "",makeHeader("CR#","#cccccc"),makeHeader("Date Submitted","#cccccc"),makeHeader("Target Date","#cccccc"),makeHeader("Phase","#cccccc")))
            headCA.iconSrc = ICONPATH + "ftv2blank.gif"
           
            <logic:iterate id="changeItem" name="changeItems">
                <logic:equal name="changeItem" property="productName" value="<%= changeItemProduct.getProductName%>">          
                    insDoc(folCA, gLnk("S", "<bean:write name="changeItem" property="title" />", "/ADM/GetWorkOrders.do?changeItemNumber=<bean:write name="changeItem" property="changeItemNumber" />", "<bean:write name="changeItem" property="changeItemNumber" />", "<bean:write name="changeItem" property="dateSubmitted" />", "<bean:write name="changeItem" property="targetDate" />", "<bean:write name="changeItem" property="phaseNumber" />"))
                </logic:equal>              
            </logic:iterate>
               
</logic:iterate>
                /*
<option selected>All Open Items</option>
<option>Fall 2003 Release</option>
<option>Spring 2004 Release</option>
<option>Fall 2004 Release</option>
*/

release = new Array("Fall 2003 Release","Spring 2004 Release","Fall 2004 Release");
monthly = new Array("January 2003","February 2003","March 2003","April 2003","May 2003","June 2003","July 2003","August 2003");
prodrel = new Array("R","M","R","M","R","R","R","R","R","M","M","M","M","M","M","M","M","M","M");

function changeRelease(select,charChWin,start){
      for (i = select.options.length; i >= start; i--) {
            select.options[i] = null;
      }
      chWinArray = (charChWin == "R") ? release : monthly;

      for (i = start; i < start + chWinArray.length; i++) {
            select.options[i] = new Option(chWinArray[i-start]);
      }
}

</script>


</HEAD>
<LINK rel="stylesheet" type="text/css" href="/ADM/doc_root/hpweb.css">
<BODY text=#000000 vLink=#660066 aLink=#003366 link=#003366 bgColor=#ffffff
leftMargin=0 topMargin=0 marginwidth="0" marginheight="0">

<%@ include file="/jsp/common/top_panel.jsp" %>

<!-- End Search Area --><!--startindex--><!-- Begin Page Title and Printable Version Area -->
<TABLE cellSpacing=0 cellPadding=0 width=740 border=0>
  <TBODY>
  <TR>
    <TD vAlign=center align=middle width=170><A
      href=""><IMG height=53
      src="/ADM/images/hpc60_topnav_hp_logo.gif"
      width=63 border=0></A><BR></TD>
    <TD width=10><IMG height=93 alt="" src="/ADM/images/s.gif"
    width=10></TD>
    <TD vAlign=top align=left width=406><BR><IMG height=6 alt=""
      src="/ADM/images/s.gif" width=1><BR>
      <H1>change items</H1><IMG height=4 alt="" src="/ADM/images/s.gif"
      width=1></TD><!--stopindex--><!--Start Print-->
    <TD vAlign=top align=left width=154><IMG height=10 alt=""
      src="/ADM/images/s.gif" width=1>&nbsp;</TD><!--End Print--></TR></TBODY></TABLE><!-- End Page Title and Printable Version Area --><!--End top inc--><!--End top inc--><!-- Begin Left Navigation and Content Area.  To increase width of content area, modify width of table below. -->
<TABLE cellSpacing=0 cellPadding=0 width=740 border=0 height=423>
  <TBODY>

<!--Start Left inc--><!--Start Left inc--><!-- Start Left Navigation -->

<%@ include file="/jsp/common/left_panel.jsp" %>
 
<!-- End Left Navigation -->



<!--startindex--><!--End Left inc--><!--End Left inc--><!-- Start Content Area.  To increase width of content area, modify width of table cell below. -->

    <TD vAlign=top align=left width=560><!--Start Top table-->

      <TABLE cellSpacing=0 cellPadding=0 width=560 border=0>
        <TBODY>
        <TR class=midheader>
          <TD width=10 class=rightheader><IMG height=20 alt="" src="/ADM/images/s.gif"
            width=10 border=0></TD>
          <TD width=550 class=rightheader>»&nbsp;list change items</TD></TR>
        <TR class=decoration>
          <TD colSpan=2><IMG height=10 alt="" src="/ADM/images/s.gif"
            width=10 border=0></TD></TR>
        <TR>
          <TD class=color003366 vAlign=top width=10>&nbsp</TD>
          <TD vAlign=top width=550>
<form>
<select name=products id="countrySelect" onChange="changeRelease(changeWindow,prodrel[this.selectedIndex],1)">
<option selected>Core Manufacturing</option>
<option>&nbsp;»&nbsp;Capital Management</option>
<option>&nbsp;»&nbsp;Contract Manufacturing</option>
<option>&nbsp;»&nbsp;Costing</option>
<option>&nbsp;»&nbsp;Maintenance and Storeroom</option>
<option>&nbsp;»&nbsp;Production Execution</option>
<option>&nbsp;»&nbsp;Purchasing</option>
<option>&nbsp;»&nbsp;Quality Management</option>
<option>&nbsp;»&nbsp;Cross-Row</option>
<option>Supplier Connectivity</option>
<option>&nbsp;»&nbsp;TDX ERP to ERP</option>
<option>&nbsp;»&nbsp;Supplier Portal</option>
<option>&nbsp;&nbsp;&nbsp;&nbsp;»&nbsp;Web Visibility</option>
<option>&nbsp;&nbsp;&nbsp;&nbsp;»&nbsp;Web Entry</option>
<option>&nbsp;&nbsp;&nbsp;&nbsp;»&nbsp;Document Collaboration</option>
<option>&nbsp;&nbsp;&nbsp;&nbsp;»&nbsp;REG</option>
<option>&nbsp;&nbsp;&nbsp;&nbsp;»&nbsp;eCOA</option>
<option>&nbsp;&nbsp;&nbsp;&nbsp;»&nbsp;RTIM</option>
<option>&nbsp;»&nbsp;Syncra</option>
<option>WOM</option>
</select>
<select name="changeWindow" id="countrySelect">
<option selected>All Open Items</option>
<option>Fall 2003 Release</option>
<option>Spring 2004 Release</option>
<option>Fall 2004 Release</option>
</select>
<INPUT type=image alt="List" src="/ADM/images/hpc60_arrow_submit.gif" border=0 name=submit></A>
</form>
          </TD></TR>
          </TBODY></TABLE>

      <TABLE cellSpacing=0 cellPadding=0 width=560 border=0>
        <TBODY>
        <TR class=midheader>
          <TD width=10 class=rightheader><IMG height=20 alt="" src="/ADM/images/s.gif"
            width=10 border=0></TD>
          <TD width=550 class=rightheader>»&nbsp;all open items</TD></TR>
        <TR class=decoration>
          <TD colSpan=2>


      <!--      <IMG height=10 alt="" src="/ADM/images/s.gif" width=10 border=0></TD></TR>      -->      
        <TR>
          <TD class=color003366 vAlign=top width=10>&nbsp</TD>
          <TD vAlign=top width=550>

<!-- Removing this link will make the script stop from working -->
<a href="http://www.treemenu.net/"></a>

<!-- Build the browser's objects and display default view of the
     tree. -->
<script>initializeDocument()</script>

          </TD></TR>
        <TR class=decoration>
          <TD colSpan=2><IMG height=10 alt="" src="/ADM/images/s.gif"
            width=10 border=0></TD></TR>
        <TR>
          </TBODY></TABLE>

<!-- END HumanTag Monitor. DO NOT MOVE! MUST BE PLACED JUST BEFORE THE /BODY TAG --><!--End bottom inc--></BODY></HTML>

ListChangeItemsAction.java:

//  ******************EXECUTE****************//
   
    public ActionForward execute(ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response)
            throws IOException, ServletException, Exception {
               
                ArrayList returnChangeItems = getChangeItems();
                ArrayList returnChangeItemProducts = getChangeItemProducts();
                request.setAttribute("changeItems", returnChangeItems);
                request.setAttribute("changeItemProducts", returnChangeItemProducts);
                //Forwards to the appropriate View
                return (mapping.findForward("continueToListChangeItems"));
            }

ChangeItem.java: (shows the variables I set and get)

    protected int changeItemNumber;
    protected String title;
    protected String dateSubmitted;
    protected String targetDate;
    protected int phaseNumber;
    protected String productName;ChangeItemProduct.java:

ChangeItemProduct: (shows the variables I set and get)

    protected int changeItemProductNumber;
    protected String productName;
0
znapsCommented:
My last post contained one more mistake (I left out the property="productName" attribute)....sorry! This works fine in my code so I'm not sure why it wouldn't work for you:

<bean:define id="prodName" name="changeItemProduct" property="productName"/>

<logic:equal name="changeItem"  property="productName" value="<%= prodName %>">

....rest of code...
0
kennethxuCommented:
1. I think you might not need the <jsp:useBean>, but this is the right why to use it:
<jsp:useBean id="changeItemProducts" type="java.util.List" scope="request"/>
<jsp:useBean id="changeItems" type="java.util.List" scope="request"/>

2. you should specify the type in <logic:iterate>
<logic:iterate id="changeItemProduct" name="changeItemProducts" type="com.hp.adm.changeItem.ChangeItemProduct"/>

3. you missed the parentheses for your get method:
<logic:equal name="changeItem" property="productName" value="<%=changeItemProduct.getProductName()%>">

I think znaps' code will also work.
Let us know.
0
cicoiiAuthor Commented:
Hi again,

I tried what you guys said, but I'm still getting the same error: (below for your reference - this is while using kennethxu's code). I also tried znaps' code but am getting a similar error as well. Can this be caused by an error with java or tomcat? I'm not sure why I'm getting this error...

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 30 in the jsp file: /jsp/common/left_panel.jsp

Generated servlet error:
    [javac] Compiling 1 source file

C:\tomcat\work\Standalone\localhost\ADM\jsp\Change Item\chi_list_jsp.java:137: cannot resolve symbol
symbol  : variable changeItemProduct
location: class org.apache.jsp.chi_list_jsp
          _jspx_th_logic_equal_0.setValue(changeItemProduct.getProductName());
                                          ^
1 error

Using this code in jsp:

<logic:iterate id="changeItemProduct" name="changeItemProducts" type="com.hp.adm.changeItem.ChangeItemProduct"/>

      folCA = insFld(foldersTree, gFld("<bean:write name="changeItemProduct" property="productName" />", ""))
            headCA = insDoc(folCA, gLnk("S", makeHeader("Title","#cccccc"), "",makeHeader("CR#","#cccccc"),makeHeader("Date Submitted","#cccccc"),makeHeader("Target Date","#cccccc"),makeHeader("Phase","#cccccc")))
            headCA.iconSrc = ICONPATH + "ftv2blank.gif"
           
            <logic:iterate id="changeItem" name="changeItems">
                <logic:equal name="changeItem" property="productName" value="<%=changeItemProduct.getProductName()%>">          
                    insDoc(folCA, gLnk("S", "<bean:write name="changeItem" property="title" />", "/ADM/GetWorkOrders.do?changeItemNumber=<bean:write name="changeItem" property="changeItemNumber" />", "<bean:write name="changeItem" property="changeItemNumber" />", "<bean:write name="changeItem" property="dateSubmitted" />", "<bean:write name="changeItem" property="targetDate" />", "<bean:write name="changeItem" property="phaseNumber" />"))
                </logic:equal>              
            </logic:iterate>
               
</logic:iterate>




0
kennethxuCommented:
Strange! which version of Struts r u using?
0
cicoiiAuthor Commented:
I use struts 1.1 along with jdk 1.3.1_06.

At first, I had problems also with this while using <bean:write> but it worked after later on....this is getting rather strange...

0
kennethxuCommented:
can you send the jsp file and  2 bean java file to kennethxu at yahoo.com? I'll try to test.
0
cicoiiAuthor Commented:
kennethxu,

sent you the files. Hope you can see if it works at your end. Thanks
0
kennethxuCommented:
Hmm, this should get it fixed:

foldersTree = gFld("", "")
foldersTree.iconSrc = ICONPATH + "s.gif"

<logic:iterate id="changeItemProduct" name="changeItemProducts"/>
<jsp:useBean id="changeItemProduct" type="com.hp.adm.changeItem.ChangeItemProduct"/>

     folCA = insFld(foldersTree, gFld("<bean:write name="changeItemProduct" property="productName" />", ""))
          headCA = insDoc(folCA, gLnk("S", makeHeader("Title","#cccccc"), "",makeHeader("CR#","#cccccc"),makeHeader("Date Submitted","#cccccc"),makeHeader("Target Date","#cccccc"),makeHeader("Phase","#cccccc")))
          headCA.iconSrc = ICONPATH + "ftv2blank.gif"

           
            <logic:iterate id="changeItem" name="changeItems">
                <logic:equal name="changeItem" property="productName" value="<%=changeItemProduct.getProductName()%>">
                    insDoc(folCA, gLnk("S", "<bean:write name="changeItem" property="title" />", "/ADM/GetWorkOrders.do?changeItemNumber=<bean:write name="changeItem" property="changeItemNumber" />", "<bean:write name="changeItem" property="changeItemNumber" />", "<bean:write name="changeItem" property="dateSubmitted" />", "<bean:write name="changeItem" property="targetDate" />", "<bean:write name="changeItem" property="phaseNumber" />"))
                </logic:equal>              
            </logic:iterate>
               
</logic:iterate>

the trick is this line:
<jsp:useBean id="changeItemProduct" type="com.hp.adm.changeItem.ChangeItemProduct"/>
0
kennethxuCommented:
BTW, you'd better start to use JSTL now, those struts logic, bean taglibs will soon be obsoleted.
0
cicoiiAuthor Commented:
Well, I got it to work...somewhat. I had to get rid of one of the <logic:iterate> tags (in kennethxu's code) because the first line:

<logic:iterate id="changeItemProduct" name="changeItemProducts"/>

is already 'ended'. Unfortunately, now, I can't loop thru my array anymore. Only the first item is shown. Any remedies for this? =) (Take note that if I simply remove the backslash in the logic:iterate code above, I get an error already). Thanks.

This is how my code went:

<logic:iterate id="changeItemProduct" name="changeItemProducts"/>
<jsp:useBean id="changeItemProduct" type="com.hp.adm.changeItem.ChangeItemProduct"/>

     folCA = insFld(foldersTree, gFld("<bean:write name="changeItemProduct" property="productName" />", ""))
          headCA = insDoc(folCA, gLnk("S", makeHeader("Title","#cccccc"), "",makeHeader("CR#","#cccccc"),makeHeader("Date Submitted","#cccccc"),makeHeader("Target Date","#cccccc"),makeHeader("Phase","#cccccc")))
          headCA.iconSrc = ICONPATH + "ftv2blank.gif"
           
            <logic:iterate id="changeItem" name="changeItems">
                <logic:equal name="changeItem" property="productName" value="<%=changeItemProduct.getProductName()%>">
                    insDoc(folCA, gLnk("S", "<bean:write name="changeItem" property="title" />", "/ADM/GetWorkOrders.do?changeItemNumber=<bean:write name="changeItem" property="changeItemNumber" />", "<bean:write name="changeItem" property="changeItemNumber" />", "<bean:write name="changeItem" property="dateSubmitted" />", "<bean:write name="changeItem" property="targetDate" />", "<bean:write name="changeItem" property="phaseNumber" />"))
                </logic:equal>              
            </logic:iterate>
0
kennethxuCommented:
this time, I toke the code you initially posted and did following:

1. remove 2 include, because I don't have those jsp files.
2. removed jsp:useBean
3. change first iterate to:
<logic:iterate id="changeItemProduct" name="changeItemProducts" type="com.hp.adm.changeItem.ChangeItemProduct" >
4. change the equal to:
<logic:equal name="changeItem" property="productName" value="<%= changeItemProduct.getProductName()%>">

and it worked!

I'll also send you the file by email.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cicoiiAuthor Commented:
It works! Finally works! :-)

Thanks kennethxu for everything. Znap's as well!

0
znapsCommented:
Glad to hear
0
kennethxuCommented:
As always, my pleasure.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.