• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 956
  • Last Modified:

Struts <html:options> Problems

I'm new to struts, and am trying to migrate my existing web applications over to the struts framework.  I'm also new to the idea of JavaBeans in the web environment.  What I'm trying to do is create a simple jsp that will prompt for 2 fields (1 being a select box), and the submission will send them on to the resulting page.  Well, I've defined 2 actions for this one JSP; one to pre-populate the form values, and the other to process the request.  Now, where I'm running into problems is the correct syntax that I should be utilizing to reference my form (bean) from the jsp page.  Complicate that with me trying to use a HashSet (defined in the form bean) to populate the <html:options> tag, and I've pretty much made a mess of things.  Any help would be appreciated.  Thanks in advance...

//_____JSP
<%@ taglib uri="/taglib/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/taglib/struts-html.tld" prefix="html"%>
<html:html>
      <head>
            <html:base/>
            <title>View Product</title>
      </head>
      <body>
            <html:errors/>
            <html:form action="/view/viewSelectedProduct">
            <table border="0" width="100%">
            <tr>
                  <th align="right"><bean:message key="view.viewProduct.orderID"/></th>
                  <td><html:text property="view.viewProduct.orderID"/></td>
            </tr>
            <tr>
                  <th align="right"><bean:message key="view.viewProduct.productID"/></th>
                  <td>
                        <html:select property="productID" size="10">
                              <html:options name="viewProductForm.products" property="productID" labelProperty="shortDescription"/>
                        </html:select>
                  </td>
            </tr>
            <tr>
                  <th align="center" colspan="2"/>
                        <html:submit/><html:cancel/>
                  </th>
            </tr>
            </html:form>
      </body>
</html:html>

//__________struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>

      <!-- ========== Data Source Configuration =============================== -->
      <data-sources />

      <!-- ========== Form Bean Definitions ================================== -->
      <form-beans>
            <!--View Product-->
            <form-bean name="view.viewProductForm" type="com.sfsltd.struts.form.ViewProductForm">
                  <form-property name="productID" type="java.lang.String" />
                  <form-property name="orderID" type="java.lang.String" />
            </form-bean>
            <!--END View Product-->
      </form-beans>

      <!-- ========== Global Exception Definitions ============================== -->
      <global-exceptions />

      <!-- ========== Global Forward Definitions =============================== -->
      <global-forwards />

      <!-- ========== Action Mapping Definitions =============================== -->
      <action-mappings>
            <!--View Product-->
            <action
                  attribute="viewProductForm"
                  input="/view/viewProduct.jsp"
                  name="view.viewProductForm"
                  path="/view/viewSelectedProduct"
                  type="com.sfsltd.struts.action.ViewSelectedProductAction" />
            <action name="view.viewProductForm"
                  path="/view/viewProduct"
                  scope="request"
                  type="com.sfsltd.struts.action.ViewProductAction"
                  validate="false">
                  <forward name="view.viewProduct" path="/view/viewProduct.jsp"/>
            </action>
            <!--END View Product-->
      </action-mappings>

      <!-- ========== Controller Configuration ================================ -->
      <controller />

      <!-- ========== Message Resources Definitions ============================ -->
      <message-resources parameter="com.sfsltd.struts.ApplicationResources" />

      <!-- ========== Plug Ins Configuration ================================= -->
      <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
            <set-property property="pathnames"
                  value="/WEB-INF/struts/validation.xml"/>
      </plug-in>
</struts-config>

//__________ViewProductForm.java
public class ViewProductForm extends ValidatorForm implements Serializable
{
      private String productID;
      private String orderID;
      private Set products;

      public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
      {
            ActionErrors errors = super.validate(mapping, request);
            return errors;
      }
      public void reset(ActionMapping mapping, HttpServletRequest request)
      {
            productID = "";
            orderID = "";

      }
      public String getProductID()
      {
            return productID;
      }
      public void setProductID(String productID)
      {
            this.productID = productID;
      }
      public String getOrderID()
      {
            return orderID;
      }
      public void setOrderID(String orderID)
      {
            this.orderID = orderID;
      }
      public Set getProducts()
      {
            return products;      
      }
      public void setProducts(Set products)
      {
            this.products = products;
      }
}

//____________ProductVO (whats in the set)
public class ProductVO implements Serializable
{
      private boolean m_active;
      private String m_definition;
      private String m_description;
      private String m_productCode;
      private int m_productID;
      private String m_shortDescription;

      public ProductVO()
      {
      }
      public ProductVO(int productID)
      {
            m_productID = productID;
      }
      public String getDefinition()
      {
            return m_definition;
      }
      public String getDescription()
      {
            return m_description;
      }
      public String getProductCode()
      {
            return m_productCode;
      }
      public int getProductID()
      {
            return m_productID;
      }
      public String getShortDescription()
      {
            return m_shortDescription;
      }
      public boolean isActive()
      {
            return m_active;
      }
      public void setActive(boolean active)
      {
            m_active = active;
      }
      public void setDefinition(String definition)
      {
            m_definition = definition;
      }
      public void setDescription(String description)
      {
            m_description = description;
      }
      public void setProductCode(String productCode)
      {
            m_productCode = productCode;
      }
      public void setProductID(int productID)
      {
            m_productID = productID;
      }
      public void setShortDescription(String shortDescription)
      {
            m_shortDescription = shortDescription;
      }
}

//____________error
org.apache.jasper.JasperException: Cannot find bean under name products

If anything else is needed, let me know
0
nixj14
Asked:
nixj14
  • 3
  • 2
1 Solution
 
amit_chauhanCommented:
Hi,
I think you should replace

<html:options name="viewProductForm.products" property="productID" labelProperty="shortDescription"/>

with

<html:options name="view.viewProductForm" property="products" labelProperty="shortDescription"/>

and see if it works

Thanks
Amit
0
 
nixj14Author Commented:
Well, with that refactoring I got the message:

No getter method available for property shortDescription for bean under name null
0
 
nixj14Author Commented:
Well, I fixed this myself, but here's the code that fixed it:

<html:select property="productID">
<html:optionsCollection name="view.viewProductForm" property="products" value="productID" label="shortDescription"/>
</html:select>

I was unable to figure out how to use the <html:options> tag, and honestly I found the <html:optionsCollection> tag a lot cleaner.  I appreciate your help
0
 
amit_chauhanCommented:
Hi,
I worked on it some while back, thats why couldnt remember the exact syntax.
Am not familiar with html:optionsCollection, but here is a link to html:options

http://jakarta.apache.org/struts/doc-1.0.2/struts-html.html#options

I know, html:options is a little confusing.

Thanks
Amit

0
 
nixj14Author Commented:
Figured I'd clean up this question.  amit_chauhan, you helped as much as you could, so I appreciate it.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now