You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jim Crossley <jc...@ifleet.com> on 2001/04/09 21:15:43 UTC

questions

Two questions, please.

1) Why do I have to include the 'name' attribute of <logic:iterate> when
inside an <html:form> element?  It seems gross to have the same string
in both the JSP page and the <form-bean> element in struts-config.xml.

2) I have a bean that has a collection of Phone objects, accessible via
its getPhones() method.  Shouldn't I be able to return EITHER a Phone[]
or a java.util.Collection?  The following element works fine when a
Collection is returned, but I get an error ("No getter method for
property phones of bean myForm") when a Phone[] is returned.

    <logic:iterate id="phone" name="myForm" property="phones" >
    <tr>
      <td>
        <bean:write name="phone" property="type" />
      </td>
      <td>
        <html:text name="phone" property="number" />
      </td>
    </tr>
    </logic:iterate>

Thanks in advance.

Re: radio buttion checked

Posted by Jean-Noel Ribette <je...@improve.fr>.
<html:radio property="fd" value="aValue"/>

Your form bean must have a property "fd". If the value of this property is equals to "aValue" the button will be
checked.

Jean-Noel

----- Original Message -----
From: Sundaram Ramasamy <su...@percipia.com>
To: <st...@jakarta.apache.org>
Sent: Wednesday, April 18, 2001 3:24 PM
Subject: radio buttion checked


> Hello.
>
> How do I define the following radio button using htlm:radio tag. I don't
> find the checked attribute
> In  html:radio tag.
>
> <input type="radio" name="fd" value="" checked>
>
> Thank & regards
> sundaram
>
>


Re: radio buttion checked

Posted by Thierry Cools <th...@s1.com>.
This is done by checking the value of your radio tag and the value returned by your getter method.

e.g if you have

 <html:radio property='xxx'  value="1" />
 <html:radio property="xxx" value="2" />

if the getXxx method returns "2" the second radio button will be selected.

Thierry 


Thierry Cools
 
Senior Java Developer 
S1 Brussels 
Kleine Kloosterstraat, 23 
1932 st. Stevens-Woluwe 
Belgium 
Tel : +32 2 200 43 82 
Email : thierry.cools@s1.com 

  ----- Original Message ----- 
  From: Sundaram Ramasamy 
  To: struts-user@jakarta.apache.org 
  Sent: Wednesday, April 18, 2001 3:24 PM
  Subject: radio buttion checked


  Hello.

  How do I define the following radio button using htlm:radio tag. I don't
  find the checked attribute
  In  html:radio tag.

  <input type="radio" name="fd" value="" checked>

  Thank & regards
  sundaram



radio buttion checked

Posted by Sundaram Ramasamy <su...@percipia.com>.
Hello.

How do I define the following radio button using htlm:radio tag. I don't
find the checked attribute
In  html:radio tag.

<input type="radio" name="fd" value="" checked>

Thank & regards
sundaram


Re: Another bean:iterate question

Posted by Jim Crossley <jc...@ifleet.com>.
I've received that error before when I forgot to include the taglib
directive for the logic library.  That would prevent the "field" bean
from being created and result in the error you're seeing.

"Brett G. Palmer" wrote:
> 
> I've been working on this <bean:iterate ... > problem for some time now.  I
> finally had to use a scriplet to get it to work.  I am trying to get a list
> of FieldTypes from a record controller (PrimaryServer below) which implement
> an AbstractField object (this may be the entire problem ... let me know if
> Abstract objects will cause problems).  The controller has a method called
> getFieldList which returns an Iterator of these AbstractField objects.  I
> then want to get the name of each field using the property getFielName().
> The following is a snippet of my Jsp page.  Tomcat always returns with an
> error saying it "can't find bean 'field' in scope null".
> 
> <logic:iterate id="field" name="PrimaryServer" property="fieldList"
> type="com.iic.dbsync.IntField">
>   <tr>
>     <td align="center"> <jsp:getProperty name="PrimaryServer"
> property="fieldList"/>
>               <bean:write name="field" property="fielName"/> </td>
>     <td> <html:text property="field2" size="100"  /></td>
>   </tr>
> </logic:iterate>
> 
> Here is the scriplet that I wrote to finally get the results that I wanted.
> 
> <% Iterator iter = PrimaryServer.getFieldList();
>     while( iter.hasNext() ) {
>         AbstractField field = (AbstractField) iter.next();
>         String fieldName = field.getFieldName();
> %>
>   <tr>
>     <td align="center"> <%=fieldName%> </td>
>     <td> <html:text property="field2" size="100" /></td>
>   </tr>
> <%    }
> %>
> 
> The iterator tag still trips me up from time to time.  If anyone has any
> suggestions I would appreciate them.  I have enjoyed reading the previous
> postings concerning the iterator tag.
> 
> Thanks again,
> 
> Brett

Another bean:iterate question

Posted by "Brett G. Palmer" <pb...@qwest.net>.
I've been working on this <bean:iterate ... > problem for some time now.  I
finally had to use a scriplet to get it to work.  I am trying to get a list
of FieldTypes from a record controller (PrimaryServer below) which implement
an AbstractField object (this may be the entire problem ... let me know if
Abstract objects will cause problems).  The controller has a method called
getFieldList which returns an Iterator of these AbstractField objects.  I
then want to get the name of each field using the property getFielName().
The following is a snippet of my Jsp page.  Tomcat always returns with an
error saying it "can't find bean 'field' in scope null".

<logic:iterate id="field" name="PrimaryServer" property="fieldList"
type="com.iic.dbsync.IntField">
  <tr>
    <td align="center"> <jsp:getProperty name="PrimaryServer"
property="fieldList"/>
              <bean:write name="field" property="fielName"/> </td>
    <td> <html:text property="field2" size="100"  /></td>
  </tr>
</logic:iterate>

Here is the scriplet that I wrote to finally get the results that I wanted.


<% Iterator iter = PrimaryServer.getFieldList();
    while( iter.hasNext() ) {
        AbstractField field = (AbstractField) iter.next();
        String fieldName = field.getFieldName();
%>
  <tr>
    <td align="center"> <%=fieldName%> </td>
    <td> <html:text property="field2" size="100" /></td>
  </tr>
<%    }
%>

The iterator tag still trips me up from time to time.  If anyone has any
suggestions I would appreciate them.  I have enjoyed reading the previous
postings concerning the iterator tag.

Thanks again,

Brett



Serialize object to form.. class mismatch?

Posted by Michael Mok <mo...@hotmail.com>.
Hi

Young Wayne posted an previous in regards to getting version mismatch error
when serializing class.

I encountered similar problem when serializing my object as well. The errors
are

java.io.InvalidClassException: java.lang.Integer; Local class not
compatible: stream classdesc serialVersionUID=1360826667802527544 local
class serialVersionUID=1360826667806852920
at java.io.ObjectStreamClass.validateLocalClass(ObjectStreamClass.java:523)
at java.io.ObjectStreamClass.setClass(ObjectStreamClass.java:567) at
java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java:936)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:366) at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:236) at
java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1186) at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:386) at
java.io.ObjectInputStream.inputClassFields(ObjectInputStream.java:2262) at
java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:519) at
java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1411) at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:386) at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:236) at
org.teatimej.timesheet.dao.Project.setSerializeOrg(Project.java:355)
at java.lang.reflect.Method.invoke(Native Method)
at
org.apache.struts.util.PropertyUtils.setSimpleProperty(PropertyUtils.java:82
5)
at
org.apache.struts.util.PropertyUtils.copyProperties(PropertyUtils.java:209)
at org.teatimej.timesheet.form.ProjectForm.setProject(ProjectForm.java:59)


setSerializeOrg code is

   byte buf[] = sOrg.getBytes();
   ByteArrayInputStream bais =
       new ByteArrayInputStream(buf);
   ObjectInputStream ois = new ObjectInputStream(bais);
   this._organisation = (Organisation)ois.readObject();
   ois.close();


getSerializeOrg code is

        ByteArrayOutputStream baos =
                new ByteArrayOutputStream(100);
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(this._organisation);
        byte buf[] = baos.toByteArray();
        oos.close();
        return new String(buf);



Any idea or workaround?

TIA


Michael Mok

www.webappcabaret.com/teatimej


Re: questions

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Sat, 14 Apr 2001, Jim Crossley wrote:

> See below.
> 
> "Craig R. McClanahan" wrote:
> > 
> > > 2) I have a bean that has a collection of Phone objects, accessible via
> > > its getPhones() method.  Shouldn't I be able to return EITHER a Phone[]
> > > or a java.util.Collection?  The following element works fine when a
> > > Collection is returned, but I get an error ("No getter method for
> > > property phones of bean myForm") when a Phone[] is returned.
> > >
> > >     <logic:iterate id="phone" name="myForm" property="phones" >
> > >     <tr>
> > >       <td>
> > >         <bean:write name="phone" property="type" />
> > >       </td>
> > >       <td>
> > >         <html:text name="phone" property="number" />
> > >       </td>
> > >     </tr>
> > >     </logic:iterate>
> > >
> > > Thanks in advance.
> > >
> > 
> > Can you post the actual getPhones() method of your form bean in the case
> > where this fails?
> 
> It's pretty typical, in that it returns an actual Phone[] member:
> 
>   public Phone[] getPhones() { return this.phones; }
> 
> However, the "setter" was a little different:
> 
>   public void setPhones (Collection c) { ... }
> 
> I came to the conclusion that Struts wasn't too happy dealing one type
> for the getter's return and another for the setter's parameter.  I
> wasn't able to confirm that by looking at the source, though.
> 

Well, you are correct that Struts won't like that much ... but it's really
because Java won't either.  You are violating the JavaBeans Specification
on property names when you try this kind of thing.

Craig McClanahan



Re: questions

Posted by Jim Crossley <ji...@lads.com>.
See below.

"Craig R. McClanahan" wrote:
> 
> > 2) I have a bean that has a collection of Phone objects, accessible via
> > its getPhones() method.  Shouldn't I be able to return EITHER a Phone[]
> > or a java.util.Collection?  The following element works fine when a
> > Collection is returned, but I get an error ("No getter method for
> > property phones of bean myForm") when a Phone[] is returned.
> >
> >     <logic:iterate id="phone" name="myForm" property="phones" >
> >     <tr>
> >       <td>
> >         <bean:write name="phone" property="type" />
> >       </td>
> >       <td>
> >         <html:text name="phone" property="number" />
> >       </td>
> >     </tr>
> >     </logic:iterate>
> >
> > Thanks in advance.
> >
> 
> Can you post the actual getPhones() method of your form bean in the case
> where this fails?

It's pretty typical, in that it returns an actual Phone[] member:

  public Phone[] getPhones() { return this.phones; }

However, the "setter" was a little different:

  public void setPhones (Collection c) { ... }

I came to the conclusion that Struts wasn't too happy dealing one type
for the getter's return and another for the setter's parameter.  I
wasn't able to confirm that by looking at the source, though.

Re: questions

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Mon, 9 Apr 2001, Jim Crossley wrote:

> Two questions, please.
> 
> 1) Why do I have to include the 'name' attribute of <logic:iterate> when
> inside an <html:form> element?  It seems gross to have the same string
> in both the JSP page and the <form-bean> element in struts-config.xml.
> 

The <logic:iterate> tag is a general purpose tool that can iterate over
*any* bean or bean property (whether or not it is inside the form
bean).  It seems to me that having the bean behave so differently
depending on whether or not it is nested inside an <html:form> would be
very confusing.

> 2) I have a bean that has a collection of Phone objects, accessible via
> its getPhones() method.  Shouldn't I be able to return EITHER a Phone[]
> or a java.util.Collection?  The following element works fine when a
> Collection is returned, but I get an error ("No getter method for
> property phones of bean myForm") when a Phone[] is returned.
> 
>     <logic:iterate id="phone" name="myForm" property="phones" >
>     <tr>
>       <td>
>         <bean:write name="phone" property="type" />
>       </td>
>       <td>
>         <html:text name="phone" property="number" />
>       </td>
>     </tr>
>     </logic:iterate>
> 
> Thanks in advance.
> 

Can you post the actual getPhones() method of your form bean in the case
where this fails?

Craig