• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with html:select

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a problem with select box using struts
I have select statement like this

<html:select name="1095Form" property="callStatus" size="1">
<html ptions name="1095Form" property="callStatusIds" labelProperty="callStatusNames" />
</html:select>

with the above i can see callStatusIds in select box but i am not getting label proerty....


and i got getter and setter methods for corresponding variables too

** Call Status **/
public void setCallStatus(String callStatus) {
contactForm.setCallStatus(callStatus);
}

public String getCallStatus() {
return contactForm.getCallStatus();
}

/** Call Status Ids **/
public void setCallStatusIds(ArrayList callStatusIds) {
contactForm.setCallStatusIds(callStatusIds);
}

public ArrayList getCallStatusIds() {
return contactForm.getCallStatusIds();
}

/** Call Status Names **/
public void setCallStatusNames(ArrayList callStatusNames) {
System.out.println("1095Form --> set call Status");
contactForm.setCallStatusNames(callStatusNames);
}

public ArrayList getCallStatusNames() {
System.out.println("1095Form --> get call Status"+contactForm.getCallStatusNames());
return contactForm.getCallStatusNames();
}

Can anyone tell me what is the problem... Please...

Thanks,
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<html:select name="1095Form" property="callStatus" size="1">
<html ptions name="1095Form" property="callStatusIds" labelProperty="callStatusNames" />
</html:select>>

options name: needs to be a collection
options property: simple property in the form bean (creates html option's value)
options labelProperty: *simple property* in the form bean (creates html option's label)

The part in asterisks is where you're going wrong.
public *ArrayList* getCallStatusNames() <-- does not return a simple property

HIH,
Jamie
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My reading of the documentation doesn't agree with what Jamie said. Here's the relevant section:

The collection of labels displayed to the user can be the same as the option values themselves, or can be different, depending on the presence or absence of the labelName and labelProperty attributes. If this feature is used, the collection of labels must contain the same number of elements as the corresponding collection of values. The following combinations are allowed:
  • Neither labelName nor labelProperty is specified - The labels will be the same as the option values themselves.
  • Only labelName is specified - The value of this attribute is the name of a JSP bean in some scope that is the collection.
  • Only labelProperty is specified - The value of this attribute is the name of a property of the ActionForm bean associated with our form, which will return the collection.
  • Both labelName and labelProperty are specified - The value of the labelName attribute identifies a JSP bean in some scope. The value of the labelProperty attribute is the name of some property of that bean which will return the collection.


  • I'd try adding labelName="1095Form" and see if that changes anything.

    I never use this method, however. When the value and label are different for an options list, I code each value/label combination in a separate bean such as org.apache.struts.util.LabelValueBean and have the form getter return a collection of those beans.
     
    Srilakshmi Vara
    Ranch Hand
    Posts: 169
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Merill!! You are exactly on the point. I got it by adding labelName attribute.
     
    Jamie Jackson
    Ranch Hand
    Posts: 58
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Sorry for the bogus info. I thought I finally knew something, but alas...
     
    reply
      Bookmark Topic Watch Topic
    • New Topic