kkjacks wrote:
I am teaching myself Struts 2 after using Struts 1.  In Struts 1 I would
access data from the action form in my jsp using the bean tag (ex.
<bean:define name="myForm" id="myForm" scope="session"/> ).  However Struts
2 seems to have merged the action class with the action form so I am not
sure how to access this now.  I know there is the <s:property/> tag but I
want to assign the value in the jsp such as this...

<!-- Example Struts.xml -->
<struts>
  <package name="default" namespace="">
    <action name="MyTestDisplay" class="mypackage.MyTestDisplay">
      <result>/web/mytest.jsp</result>
  </package>
</struts>

<!-- mypackage.MyTestDisplay.java -->
public class MyTestDisplay extends ActionSupport {
   List<Integer> list1 = new ArrayList<String>();

   public String execute() throws Exception {
      list1.add( 1 );
      list2.add( 2 );
list1.add( 3 ); list2.add( 4 );
      return SUCCESS;
   }

   public List getList1() {
      return list1;
   }
}

<!-- mytest.jsp -->
<html>
  <%@ taglib prefix="s" uri="/struts-tags" %>
  <table>
    <tr>
      <td>
<% List<Integer> myList = MyTestDisplay.getList1(); <!-- HOW DO I DO THIS --> for ( Integer i : myData ) { if ( (i % 2) == 0 ) { out.print( i );
            }
          }
      %>
    </td>
  </tr>
<html>


(I just threw together this example on the fly so sorry if there is a
mistake but I am only conserned with the line that has the bold comment)

I'm not sure what you mean by 'assign the value in the JSP' but accessing the list1 property is as simple as <s:property name='list1'/>. Try to avoid scriptlets and use JSP tags instead. Then, to achieve the effect of your example, you could do something like

  <c:forEach var='item' items='list' step='2'>
    <s:property name='#item'/>
  </c:forEach>

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to