?
Solved

Struts <html:options> Problems

Posted on 2003-03-25
5
Medium Priority
?
950 Views
Last Modified: 2013-11-18
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
Comment
Question by:nixj14
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:amit_chauhan
ID: 8205189
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
 
LVL 1

Author Comment

by:nixj14
ID: 8205878
Well, with that refactoring I got the message:

No getter method available for property shortDescription for bean under name null
0
 
LVL 1

Author Comment

by:nixj14
ID: 8206022
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
 
LVL 2

Accepted Solution

by:
amit_chauhan earned 150 total points
ID: 8206054
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
 
LVL 1

Author Comment

by:nixj14
ID: 8698637
Figured I'd clean up this question.  amit_chauhan, you helped as much as you could, so I appreciate it.
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 7 hours left to enroll

777 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