> -----Original Message----- > From: Mike Elliott [mailto:[EMAIL PROTECTED] > Sent: Friday, August 13, 2004 9:33 AM > To: [EMAIL PROTECTED] > Subject: Read only iterate? > > > I've been totally defeated in my attempt to alter an html:text > element inside a logic:iterate tag. There must be a way to > accomplish this, but I've been beating my head against the wall > for three days now without making progress. > > I have simplified the problem substantially from the initial page. > What I have now looks like this:
from http://struts.apache.org/userGuide/struts-html.html#text I'm guessing that a List won't work and you need to have an array. > > --------------------------------------------------------- > [ Submit ] > Problematic Input [0 ] > Problematic Input [1 ] > Functioning Input [A Value ] > --------------------------------------------------------- > > The lines containing "Problematic Input" were generated by a > logic:iterate tag, which successfully fetched the list of objects from > the form bean. The last line, containing "Functioning Input", was > generated outside of the logic:iterate tag. Actual contents of the > jsp page, bean, etc., are attached. > > What happens at runtime is that when the JSP page is rendered, the > text fields for all three rows are successfully and correctly fetched > from the form bean, but only the last row can be changed. As the log > shows: > > <start> > INFO [org.apache.struts.util.PropertyMessageResources] > Initializing, > config='org.apache.struts.taglib.html.LocalStrings', returnNull=true > INFO [problem.ProblemBean] initializing entries > INFO [problem.ProblemBean$ProblemItem] setInteger_value to 0 > INFO [problem.ProblemBean$ProblemItem] setInteger_value to 1 > INFO [problem.ProblemAction] show > INFO [org.apache.struts.util.PropertyMessageResources] > Initializing, > config='org.apache.struts.taglib.logic.LocalStrings', returnNull=true > INFO [problem.ProblemBean] getEntries > INFO [problem.ProblemBean$ProblemItem] getInteger_value > INFO [problem.ProblemBean$ProblemItem] getInteger_value > INFO [problem.ProblemBean] getWorking_perfectly > <submit> > INFO [problem.ProblemBean] setWorking_perfectly to 'mutated' > INFO [problem.ProblemAction] update > INFO [problem.ProblemBean] getEntries > INFO [problem.ProblemBean$ProblemItem] getInteger_value > INFO [problem.ProblemBean$ProblemItem] getInteger_value > INFO [problem.ProblemBean] getWorking_perfectly > > The page is initialized properly. All three values are fetched from > the form bean via the expected get methods. The html form is properly > populated and displays the expected values (0, 1, and "A Value"). > > The three fields are then changed (to 5, 5, and "mutated") and the > submit button is selected at the point in the log file where I have > inserted the <submit> annotation. > > This causes the form to be submitted to the Action, causing the set > method for the field "working_perfectly" to be invoked (as it should > be), but the set method for the two fields in the logic:iterate tag is > not invoked. And I don't know why. And I can't seem to get them to > be invoked, either. > > So . . . the magic isn't working. Something must be needed to tell > the generated servlet not to treat these two properties (inside the > logic:iterate tag) as read-only. What should it be? How can I get > these properties to be updated in the form bean as the > "working_perfectly" property is? > > Like I said -- I've been beating my head against this problem for > three days now. There's just got to be a way! > > ---------------------------------------------------------------------- > struts-config.xml > ---------------------------------------------------------------------- > <?xml version="1.0" encoding="ISO-8859-1" ?> > > <!DOCTYPE struts-config PUBLIC > "-//Apache Software Foundation//DTD Struts > Configuration 1.0//EN" > > "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd"> > > <struts-config> > > <form-beans> > <form-bean > name="problemBean" > type="problem.ProblemBean"/> > </form-beans> > > <action-mappings> > <action > path="/problemPage" > type="problem.ProblemAction" > name="problemBean" > validate="false" > input="/pages/problem.jsp"/> > </action-mappings> > > </struts-config> > > ---------------------------------------------------------------------- > problem.jsp: > ---------------------------------------------------------------------- > <%@ taglib uri="/taglib/struts-logic" prefix="logic" %> > <%@ taglib uri="/taglib/struts-html" prefix="html" %> > <html> > <head> > <title>Problem page</title> > </head> > > <body> > <div style="text-align: center"> > <html:form action="/classicResultPage.do?arg=update" > method="post"> > <table summary="x" width="800" border="0" cellspacing="0" > cellpadding="0"> > <tr> > <td align="center" colspan="2"> > <html:submit/> > </td> > </tr> > <hr /> > <logic:iterate id="entry" name="problemBean" > property="items" > > <tr> > <td>Problematic input</td> > <td> > <html:text name="entry" > property="integer_value" indexed="true"/> > </td> > </tr> > </logic:iterate> > > <tr> > <td><b>Functioning input</b></td> > <td> > <html:text property="someValue"/> > </td> > </tr> > > </table> > </html:form> > <hr /> > </div> > </body> > </html> > > ---------------------------------------------------------------------- > ProblemAction.java > ---------------------------------------------------------------------- > package problem; > > import org.apache.log4j.Level; > import org.apache.log4j.Logger; > import org.apache.struts.action.ActionForm; > import org.apache.struts.action.ActionForward; > import org.apache.struts.action.ActionMapping; > import org.apache.struts.action.Action; > > import javax.servlet.http.HttpServletRequest; > import javax.servlet.http.HttpServletResponse; > > public final class ProblemAction extends Action { > > public ActionForward execute( ActionMapping mapping, > ActionForm form, > HttpServletRequest request, HttpServletResponse response ) { > > String arg = request.getParameter( "arg" ); > > if ("update".equals( arg )) { > log.info( "update" ); > } > > if ("show".equals( arg )) { > log.info( "show" ); > } > > return new ActionForward( mapping.getInput() ); > } > > private static Logger log; > static { > log = Logger.getLogger( ProblemAction.class ); > log.setLevel( Level.DEBUG ); > } > > } > > ---------------------------------------------------------------------- > ProblemBean.java > ---------------------------------------------------------------------- > package problem; > > import java.util.List; > import java.util.ArrayList; > > import org.apache.log4j.Logger; > import org.apache.log4j.Level; > import org.apache.struts.action.ActionForm; > > public class ProblemBean extends ActionForm { > > String someValue = "***"; > > public String getSomeValue() { > log.info( "getSomeValue" ); > return someValue; > } > > public void setSomeValue( String someValue ) { > log.info( "setSomeValue to '" + someValue + "'"); > this.someValue = someValue; > } > > private static Integer incrementing = new Integer( 0 ); > > public static class ProblemItem { > > public ProblemItem() { > this.integer_value = incrementing; > incrementing = new Integer( incrementing.intValue() + 1 ); > } > > private Integer integer_value; > > public Integer getInteger_value() { > log.info( "getInteger_value" ); > return integer_value; > } > > public void setInteger_value( Integer iValue ) { > log.info( "setInteger_value to " + iValue ); > this.integer_value = iValue; > } > > private static Logger log; > static { > log = Logger.getLogger( ProblemItem.class ); > log.setLevel( Level.DEBUG ); > } > > } > > private List items; > > public List getItems() { > if (items == null) { > log.info( "initializing items" ); > items = new ArrayList( 2 ); > items.add( new ProblemItem() ); > items.add( new ProblemItem() ); > } > log.info( "getItems" ); > return items; > } > > public void setItems( List items ) { > log.info( "setItems" ); > this.items = items; > } > > private static Logger log; > static { > log = Logger.getLogger( ProblemBean.class ); > log.setLevel( Level.DEBUG ); > } > > } > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]