I'm new to Struts, but old at JSP / Java / Servlets. I cannot figure
out why this is happening.
When I run the page below, the struts tag does not output the value in
my bean. I added the standard JSP tags later to be sure the values are
being set, and the output there is fine.
-----------------------CounterpartyForm.jsp---------------------------
<[EMAIL PROTECTED] uri="/struts-logic" prefix="logic"%>
<[EMAIL PROTECTED] uri="/struts-bean" prefix="bean"%>
<[EMAIL PROTECTED] uri="/struts-html" prefix="html"%>
<jsp:include page="/struts-views/Heading.jsp">
<jsp:param name="heading" value="Counterparty Form"/>
</jsp:include>
<jsp:useBean id="counterpartyForm"
class="com.sam.trading.web.struts.forms.CounterpartyForm"
scope="request"/>
<html:form action="/viewCounterparty.do" name="counterpartyForm"
type="com.sam.trading.web.struts.forms.CounterpartyForm">
Name: <html:text property="counterparty.name"/><%=
counterpartyForm.getCounterparty().getName() %><br/>
Parent: <input type="text"><br/>
Fee Type: <input type="text"><br/>
Fee Amount: <input type="text"><br/>
Credit: <input type="text"><br/>
Credit Zero: <input type="text"><br/>
</html:form>
<[EMAIL PROTECTED] file="/struts-views/Footer.jsp"%>
-----------------------Page done----------------------------
In this line:
----
Name: <html:text property="counterparty.name"/><%=
counterpartyForm.getCounterparty().getName() %><br/>
----
The <html:text property="counterparty.name"/> tag outputs <input
type="text" name="counterparty.name" value="">
while the <%= counterpartyForm.getCounterparty().getName() %> outputs
"ABPN" (which is correct for this run of the page)
Any ideas?
For grins, here are my struts-config.xml, and all the supporting Java
code:
-----------------------struts-config.xml---------------------------
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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>
<form-beans>
<form-bean name="counterpartyForm"
type="com.sam.trading.web.struts.forms.CounterpartyForm"/>
</form-beans>
<action-mappings>
<action path="/viewCounterparty"
type="com.sam.trading.web.struts.actions.CounterpartyFormAction"
scope="request"
attribute="counterpartyForm"
validate="true">
<forward name="show"
path="/struts-views/CounterpartyForm.jsp"/>
</action>
</action-mappings>
</struts-config>
-----------------------CounterpartyForm.java---------------------------
/*
* CounterpartyForm.java
*
* Created on September 26, 2003, 3:06 PM
*/
package com.sam.trading.web.struts.forms;
import com.sam.trading.referencedata.Counterparty;
import com.sam.trading.referencedata.CounterpartyDAO;
import com.sam.trading.utils.DAOFactory;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
/**
*
* @author Daniel
*/
public class CounterpartyForm extends ActionForm {
private Counterparty counterparty;
private String name;
/** Creates a new instance of CounterpartyForm */
public CounterpartyForm() {
counterparty = new Counterparty();
}
public void reset(ActionMapping mapping, HttpServletRequest request)
{
counterparty = new Counterparty();
name = null;
}
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
return errors;
}
/** Getter for property counterparty.
* @return Value of property counterparty.
*
*/
public com.sam.trading.referencedata.Counterparty getCounterparty()
{
return counterparty;
}
/** Setter for property counterparty.
* @param counterparty New value of property counterparty.
*
*/
public void
setCounterparty(com.sam.trading.referencedata.Counterparty counterparty)
{
this.counterparty = counterparty;
}
/** Getter for property name.
* @return Value of property name.
*
*/
public java.lang.String getName() {
return name;
}
/** Setter for property name.
* @param name New value of property name.
*
*/
public void setName(java.lang.String name) {
this.name = name;
}
}
-----------------------CounterpartyFormAction.java----------------------
-----
package com.sam.trading.web.struts.actions;
import com.sam.trading.web.struts.forms.CounterpartyForm;
import com.sam.trading.referencedata.Counterparty;
import com.sam.trading.serviceLists.SearchServiceList;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
public class CounterpartyFormAction extends Action {
private Logger logger =
Logger.getLogger(CounterpartyFormAction.class.getName());
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
logger.debug("Made it to CounterpartyFormAction");
String name = request.getParameter("counterpartyName");
if (form == null) {
logger.debug("Constructing form");
form = new CounterpartyForm();
if ("request".equals(mapping.getScope())) {
logger.debug("setting form in request");
request.setAttribute(mapping.getAttribute(), form);
} else {
logger.debug("setting form in session");
request.getSession().setAttribute(mapping.getAttribute(), form);
}
logger.debug("form created");
}
logger.debug("checking input");
if (name != null) {
logger.debug("getting counterparty");
Counterparty counterparty =
SearchServiceList.getCounterpartyNamed(name);
CounterpartyForm cform = (CounterpartyForm)form;
cform.setCounterparty(counterparty);
logger.info(counterparty);
logger.debug("counterparty set");
}
logger.debug("Finished method call");
return mapping.findForward("show");
}
}
Statement of Confidentiality
This e-mail message, and any attachments, is confidential and is intended solely for
the addressees named above. If you are not a named recipient, an individual
specifically authorized to receive this communication, or if this message has been
addressed to you in error, do not read, disclose, reproduce, or otherwise use this
transmission in any manner. If you have received this transmission in error, please
alert the sender by replying to the e-mail or by contacting the sender by phone. We
also request that you immediately delete this message, and attachments, if any. This
disclaimer shall not be construed in any way to grant permission to transmit
confidential information via this firm's e-mail system.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]