struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Caroline Holanda <spencercarol...@yahoo.com>
Subject Re: logic:Present tag
Date Fri, 23 May 2003 16:06:41 GMT
Hey all!

  How can I test if the collection property (in this
case "userContacts" of optionsCollection is not null?
I tried <logic:present property="propertyName"> and 
<logic:present name="formName"
property="propertyName">  but even if the property
object is null the tag body is executed.

  Please any idea?
  Caroline Holanda

 --- Kris Schneider <kris@dotech.com> escreveu: >
Actually, <html:optionsCollection> seems like a
> better fit:
> 
> <html:form action="/nextAction">
>   <html:select property="alertContacts"
> multiple="true">
>     <html:optionsCollection property="userContacts"
>                             value="contactId" 
>                             label="contactIdLabel"/>
>   </html:select>
> </html:form>
> 
> What you'll end up with in the form bean's
> "alertContacts" property is the set
> of selected "contactId" values. In other words,
> while a collection of beans is
> used to render the options, a String[] is used to
> hold the selections.
> 
> Quoting Denis Avdic <denis@betterway.net>:
> 
> > I am totally confused here.  Why do you need to do
> this?
> > 
> > If you prepopulate your form the items should be
> preselected for you.
> > 
> > Thus, if you have a multi-select populated by
> userContacts
> > and your selected contacts are stored into
> alertContacts
> > if you set the form in your setup action, they
> should be prepopulated.
> > 
> > IE.
> > 
> > class YourForm() {
> > 
> > ArrayList userContacts; (list of all possible
> contacts)
> > String[] alertContacts; (where multiselect will
> store multiple select
> > contacts>
> > 
> > getters, setters, validator etc.
> > 
> > }
> > 
> > Then your form could look something like this:
> > 
> > <html:form action="/nextAction.do">
> > <html:select property="alertContacts"
> multiple="true" >
> >     <html:options collection="userContacts"
> property="contactId" 
> > labelProperty="contactIdLabel" />
> > </html:select>
> > </html:form>
> > 
> > 
> > Thus, if put the form into the request in the
> setup action, then there 
> > will be something in alertContacts, and they will
> > be preselected.  Otherwise (if the formbean is
> empty, or if you do not 
> > put anything in alertContacts) nothing will be
> preselected.
> > 
> > Make sense?
> > 
> > (I believe this is right.  I know some people have
> problems with options 
> > but this (i think) worked before I switched to
> > optionsCollection tag.)
> > 
> > 
> > Mick.Knutson@ubsw.com wrote:
> > 
> > >Can you please verify this for me then:
> > >
> > ><bean:define id="allContacts" name="alertForm"
> property="userContacts" />
> > ><bean:define id="selectedContacts"
> name="alertForm" property="alertContacts"
> > />
> > >
> > ><c:forEach items="allContacts" var="contact">
> > >    <option name="${contact.contactId}"
> > >    <c:forEach items="selectedContacts"
> var="selected">
> > >        <c:if test="${contact.contactId} ==
> ${selectedContacts.contactId}"
> > >
> > >            &nbsp;SELECTED
> > >        </c:if>
> > >        />
> > >    </c:forEach>
> > ></c:forEach>
> > >
> > >I have a user that has a list of, say 10
> contacts. I want a multi-select
> > that shows all 10 contacts. The user will be able
> to select multiple contacts
> > to assign to this Alert. So say the user selected
> 5 contacts. Whe I redisplay
> > the select, I need those 5 to be pre-selected. Is
> the above what I would need
> > to get this to work?
> > >
> > >Thanks in advance for you help.
> > >
> > >
> > >-----Original Message-----
> > >From: Denis Avdic [mailto:denis@betterway.net]
> > >Sent: Friday, May 23, 2003 3:53 PM
> > >To: Struts Users Mailing List
> > >Subject: Re: logic:Present tag
> > >
> > >
> > >You should use JSTL to do that, much easier to
> do...
> > >
> > >It took me approx 1hr to get all the id's and
> names and properties right 
> > >when using logic.
> > >
> > >It takes me about 1 min to write up the
> <c:foreach> tag...
> > >
> > >
> > >
> > >Mick.Knutson@ubsw.com wrote:
> > >
> > >  
> > >
> > >>I have an iterate question as well, and nobody
> has responded to my first 3
> > emails, so maybe I will try here:
> > >>
> > >>I have a simiar issue that I can't resolve and
> was hoping you could help.
> > >>I have this logic iterate that does not print
> anything out even though
> > there are 3 beans in my UserContact[]:
> > >>
> > >><bean:define id="state" name="contactListForm"
> property="userContacts" />
> > >>
> > >>
> > >>   <logic:present scope="request"
> name="contactListForm" >
> > >>       <html:select property="userContacts" >
> > >>       <html:option value="" key="form.select"/>
> > >>           <logic:iterate id="contact"
> name="contactListForm"
> > property="userContacts">
> > >>               <html:options value='<bean:write
> name="contact"
> > property="contactId" />'>
> > >>           </logic:iterate>
> > >>       </html:form>
> > >>   </logic:present>
> > >>
> > >>   <logic:notPresent scope="request"
> name="contactListForm" >
> > >>       <b><font color="red">NO CONTACTS CREATED
> YET. PLEASE CREATE AT LEAST
> > ONE CONTACT!</font></b>
> > >>   </logic:notPresent>
> > >>
> > >>
> > >>
> > >>
> > >>-----Original Message-----
> > >>From: Caroline Holanda
> [mailto:spencercaroline@yahoo.com]
> > >>Sent: Friday, May 23, 2003 3:27 PM
> > >>To: Struts Users Mailing List
> > >>Subject: RE: logic:Present tag
> > >>
> > >>
> > >>Gandle,
> > >>
> > >>Thanks again for the reply, but I guess your
> code
> > >>tests if a property of a collection is not null.
> What
> > >>I need is really test if the collection object,
> that
> > >>is a DynaActionForm property, is null. Following
> is
> > >>the code where I use this:
> > >>
> > >> <html:select property="supplyList"
> multiple="true"
> > >>size="5" styleClass="Campos" style="width:150">
> > >>   <logic:present property="supplyColl" >
> > >>      <html:optionsCollection
> property="supplyColl" 
> > >>value="value" label="label"/>  
> > >>   </logic:present> 
> 
=== message truncated === 

=====
******************************
Cuide das pessoas que vc ama! 
Elas são presentes de Deus!

_______________________________________________________________________
Yahoo! Mail
O melhor e-mail gratuito da internet: 6MB de espaço, antivírus, acesso POP3, filtro contra
spam. 
http://br.mail.yahoo.com/

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


Mime
View raw message