You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Wendy Smoak <We...@asu.edu> on 2003/03/15 01:59:58 UTC

JSTL okay with get method, but no set method?

I have a DTO that contains a List of objects.  Since you can add any Object
to a List, I would rather not have a 
  setAssistants( List asst ); 
method that would allow someone to add a list of inappropriate object types.

Instead, I want to only have:
  public List getAssistants();
  public void addAssistant( PersonView p);

I know that having two 'set' methods with the same name but different
parameters *really* confuses the introspection/reflection/whatever magic
happens with JavaBeans.  Learned that one the hard way. :(

But what about a 'missing' set method?  It _seems_ to be working:

<c:forEach items="${trackDto.assistants}" var="asst">
  <c:out value="${asst.assistant.preferredName}"/> <c:out
value="${asst.assistedDate}"/>
</c:forEach>

I gather that JSTL uses the 'get' method to determine the type of the
object, because I'm not specifying that here and it's having no problems.

Please stop me now if I'm doing something that's going to cause problems
later!

Thanks,

-- 
Wendy Smoak
Applications Systems Analyst, Sr.
Arizona State University PA Information Resources Management

Re: JSTL okay with get method, but no set method?

Posted by "David M. Karr" <dm...@earthlink.net>.
>>>>> "Wendy" == Wendy Smoak <We...@asu.edu> writes:

    Wendy> I have a DTO that contains a List of objects.  Since you can add any Object
    Wendy> to a List, I would rather not have a 
    Wendy>   setAssistants( List asst ); 
    Wendy> method that would allow someone to add a list of inappropriate object types.

    Wendy> Instead, I want to only have:
    Wendy>   public List getAssistants();
    Wendy>   public void addAssistant( PersonView p);

    Wendy> I know that having two 'set' methods with the same name but different
    Wendy> parameters *really* confuses the introspection/reflection/whatever magic
    Wendy> happens with JavaBeans.  Learned that one the hard way. :(

    Wendy> But what about a 'missing' set method?  It _seems_ to be working:

    Wendy> <c:forEach items="${trackDto.assistants}" var="asst">
    Wendy>   <c:out value="${asst.assistant.preferredName}"/> <c:out
    Wendy> value="${asst.assistedDate}"/>
    Wendy> </c:forEach>

    Wendy> I gather that JSTL uses the 'get' method to determine the type of the
    Wendy> object, because I'm not specifying that here and it's having no problems.

    Wendy> Please stop me now if I'm doing something that's going to cause problems
    Wendy> later!

>From a non-authoritative point of view, I can't see how that could be a
problem.  You could sort of verify this yourself, by writing some code using
Introspector and BeanInfo.  If you get the PropertyDescriptors for the class
and you find that the "assistants" property has a read method but a null write
method, and it did all this without bombing, then the EL will probably be fine
with it.

-- 
===================================================================
David M. Karr          ; Java/J2EE/XML/Unix/C++
dmkarr@earthlink.net   ; SCJP; SCWCD




---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: JSTL okay with get method, but no set method?

Posted by Shawn Bayern <ba...@essentially.net>.
On Fri, 14 Mar 2003, Wendy Smoak wrote:

> I gather that JSTL uses the 'get' method to determine the type of the
> object, because I'm not specifying that here and it's having no
> problems.
> 
> Please stop me now if I'm doing something that's going to cause
> problems later!

JSTL defers to the JavaBeans standard in this regard:  the introspector
finds a property, by default, if either a getter exists, a setter exists, 
or both exist and match.

-- 
Shawn Bayern
"JSTL in Action"   http://www.manning.com/bayern


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org