Hmmm. Didn't realise you were using session forms.

Best way to find out what is going on is to look at the HTML that your app produces.

Struts will save request parameters to nested beans, as long as the syntax is OK.

i.e.

<input type="checkbox" name="fag[0].ekstraTekst">

when checked will set your nested Fag bean extraTekst to true.



Adam

On 08/28/2003 01:10 PM Heather Buch wrote:
Hi Adam,

Thanks for the reply.

I tried setting the form to request scope and doing this:

        public void reset(ActionMapping mapping, HttpServletRequest request) {
                logger.info("calling reset, Fags has " + _fags.size() + " elements" ); 
             
                for(int i = 0; i < 106; i++) {
                        Fag myfag = new Fag();
                        FagDTO myfagdetail = new FagDTO();
                        myfag.setFagDetail(myfagdetail);
                        _fags.add(myfag);
                }
        }

But now, the form just submits blank "fags".

If I set my form to "session" scope and override reset, it keeps my list of
fags intact, but does not change their properties according to the changes I
make in the form one bit.

I am wondering, with this jsp code:

<logic:iterate name="fagtypeform" property="fags" id="fager" indexId="ctr"> <nested:text indexed="true" name="fager" property="fagDetail.navn" />

<nested:checkbox indexed="true" name="fager"

property="fagDetail.ekstraTekst" />
</logic:iterate>


which (if any) of these methods from FagTypeForm is being called when I hit
submit:

        public void setFags(List fags) {
                _fags = fags;
        }

        public void setFags(Fag[] fags) {
                for (int i = 0; i < fags.length; i++) {
                        _fags.add(i, fags[i]);
                }
        }

        public void setFags(int n, Fag fag) {
                _fags.add(n, fag);
        }


And I am wondering, CAN I even update a member of a bean directly via a form? Or do need to set Strings in my ActionForm, and then use my Action to pull the Strings out of the ActionForm and then set them into the beans. But it seems like other people have updated beans directly from their ActionForm.

I grew further confused when I read about "The Wrinkle with Indexed Tags" at
http://jakarta.apache.org/struts/faqs/indexedprops.html. Perhaps the "name" in
my checkbox needs to refer to the form, instead of the page scope bean (the
"id" from my iterate tag).

Geez I am confused!

Heather





Hi Heather, it sounds like you are not instantiating any nested beans to store the request parameters in. You should do this in your reset method.

Adam

On 08/27/2003 08:31 PM Heather Buch wrote:

I am trying to figure out what happens to the value of my nested checkbox when
I submit my form.

I have a bean:

public class FagDTO {

with setter/getter methods for a boolean:

   //for fagtypeform
   public void setEkstraTekst ( boolean ekstra_tekst ){
        logger.info("setting ekstra tekst to  " + ekstra_tekst +  " for  " +
this.getEkskode());
        _ekstra_tekst = ekstra_tekst;
   }

   public boolean getEkstraTekst (){
   return _ekstra_tekst;
   }

I have an ActionForm with setters/getters which return a collection of  "Fag"
beans (The above  "FagDTO" beans are nested one-to-one in the  "Fag" beans. Fag
means  "class" in Danish BTW):

public class FagTypeForm extends ActionForm {

protected List _fags = new ArrayList();

public void setFags(Fag[] fags) {
        for (int i = 0; i  < fags.length; i++) {
             logger.info("setting fag property  " +
fags[i].getFagDetail().getEkstraTekst() +  " for fag  " +
fags[i].getFagDetail().getNavn());
             _fags.add(i, fags[i]);
        }
   }

   public void setFags(int n, Fag fag) {
             logger.info("setting fag at  " + n);
        _fags.add(n, fag);
   }


public List getFags() { return _fags; }

       public void reset(ActionMapping mapping, HttpServletRequest request) {
   logger.info("calling reset");

Iterator fagiter = _fags.iterator();
while (fagiter.hasNext()) {
Fag myfag = (Fag)fagiter.next();
FagDTO myfagdetail = myfag.getFagDetail();
myfagdetail.setEkstraTekst(Boolean.FALSE);
} resetFields(); }
}


Then I have my jsp:

<html:form action="/fagTypeSave">
<!--   cycle over rows of ekskoder -->
  <logic:iterate property="fags" name="fagtypeform" id="fager" indexId="indx">
<nested:text indexed="true" name="fager" property="fagDetail.navn" />
<nested:checkbox indexed="true" name="fager"

property="fagDetail.ekstraTekst" />


</logic:iterate>

(submit button stuff...)

</html:form>

My html form gets populated from fagtypeform just fine, and reset seems to
work. But when I change some checkbox values and submit, nothing happens. At
least, the setters/getters of my  "FagDTO"
bean don't get hit and print out logging stuff, like I had hoped. And the
value in my bean doesn't change.

So my real question is: what is the  "property" of nested:checkbox doing? How
can I get nested:checkbox to set the value in my FagDTO when I submit it?

Thanks,

Heather Buch



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




Heather Buch

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



-- struts 1.1 + tomcat 4.1.27 + java 1.4.2 Linux 2.4.20 RH9


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



Reply via email to