aspose file tools*
The moose likes Struts and the fly likes How to populate html:select Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to populate html:select" Watch "How to populate html:select" New topic
Author

How to populate html:select

Govind Rajith
Greenhorn

Joined: Feb 15, 2007
Posts: 12
Hello,
Im a beginner in struts. My problem is to populate an html:select. Let me explain you in detail, I have table called "Documents" whose records are brought to the action class using a Data transfer object named documentDto. Now the values are assigned to an array list and then set to the jsp's form bean where it has to be populated. The problem is that iam not able to display it or rather populate it in the jsp. What should i do. Please help me.

Thanks in advance
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You will want to use a combination of the <html:select> and <htmlptionsCollection> tags. See the headings select and optionsCollection in this document to find out more about how to use them. Essentially, the <htmlptionsCollection> tag iterates over a collection of JavaBeans, allowing you to specify one of the bean properties for the label, and the other for the value of the option.
[ February 17, 2007: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Govind Rajith
Greenhorn

Joined: Feb 15, 2007
Posts: 12
Hello friend,

I did it using collection but got some error. Then i did it as shown below:

<html:select property="docTypeId">
<logic:iterate id="catFrm" name="catalogForm" property="doc_Type">

<bean efine id="docs" name="catFrm" property="documentType" />
<option value="<%=(String)docs%>"><%=(String)docs%></option>

</logic:iterate>
</html:select>

Now the problem is that the combo gets populated only when i click some buttton i.e its not populating dynamically. Also the values are not getting updated in the database either. Any sugggestions please.

Thanks in advance
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
From what you describe, your problem goes beyond the <html:select> tag. Please post relevant portions of:
  • your struts-config.xml file
  • The Action used to prepare to display this JSP, and the one used to process a submit from this JSP
  • the <html:form> tag from the JSP
  • The ActionForm Class

  • Govind Rajith
    Greenhorn

    Joined: Feb 15, 2007
    Posts: 12
    I solved that problem by simply rdirecting the index page to the corresponding action. Is it a good practice?
    Merrill Higginson
    Ranch Hand

    Joined: Feb 15, 2005
    Posts: 4864
    Yes, this is quite commonly done.
    Govind Rajith
    Greenhorn

    Joined: Feb 15, 2007
    Posts: 12
    Now a new problem has arised!! Actually there are four combo box in my jsp and i could populate only one.

    The code inside the action class is pasted below::

    public class IlsMasterEntryAction extends Action{
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    throws Exception{

    IlsCataloguingForm catalogForm=(IlsCataloguingForm)form;

    IlsCatalogueSerialDto catsDto=new IlsCatalogueSerialDto();
    //IlsCataloguingForm catlogForm=new IlsCataloguingForm();

    IlsMasterEntryDao masterDao=new IlsMasterEntryDao();
    ArrayList docType=masterDao.populateDocument();
    ArrayList authDetails=masterDao.populateAuthor();
    catsDto.setDoc_Type(docType);
    catsDto.setAuthorDetails(authDetails);
    PropertyUtils.copyProperties(catalogForm, catsDto);







    //IlsCataloguingForm catalogForm=new IlsCataloguingForm();
    //IlsCatalogueSerialDto catserDto=new IlsCatalogueSerialDto();
    //PropertyUtils.copyProperties(catserDto,catalogForm);
    //catserDto.setSerCtrlTitleId(0);

    //masterDao.saveCatalogDetails(catserDto);

    //catserDto=new IlsCatalogueSerialDto(); //Creating a new instance of IlsCatalogueSerialDto and copying its properties to
    //PropertyUtils.copyProperties(catalogForm, catserDto); // the object of IlsCataloguingForm to clear the contents from the text fields

    /*/IlsMasterEntryAction ilms=new IlsMasterEntryAction();
    //catalogForm=ilms.documentPop();
    //System.out.println("size of Doc_type is"+catalogForm.getdoc_Type().size());
    //IlsMasterEntryAction ilmObj=new IlsMasterEntryAction();
    catalogForm=ilmObj.authorPop();*/




    return(mapping.findForward("success"));



    }

    Is there any method to use the form bean object more than once?
    can anyone help me please?

    Thanks In advance
    GOVIND RAJITH
    Merrill Higginson
    Ranch Hand

    Joined: Feb 15, 2005
    Posts: 4864
    I'm afraid you haven't given us enough information to help. Please read this link on what to include in a well formatted question and try again.

    Showing us your Action class is a start, but we need you to tell us specifically what didn't work, and what error messages if any that you got. We also need you to post JSP code snippets of the select boxes that didn't work.
    Is there any method to use the form bean object more than once?

    I have no idea what you mean by this. Please rephrase and question and give us more details.
    Govind Rajith
    Greenhorn

    Joined: Feb 15, 2007
    Posts: 12
    I am really sorry. It was a great blunder made in initializing the array list object. Now it is solved. Also I am sorry for posting in a confusing manner. Actually i was not knowing how to explain it.

    Thanks
    Govind Rajith
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: How to populate html:select