facebook

dynamic beans

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #251809 Reply

    David
    Member

    I am trying to find information on how to have dynamically created beans on a form. I have a bean with several properties, and an associated form that has an ArrayList of these beans. What I need to do is when a button is pressed, the jsp adds another bean that will be populated and added to the form’s arrayList.

    JSP
    <logic:iterate index=”i” …>
    <bean:write name=”bean” property='<%= “bean.from[” + i + “]” %>’/>
    …>

    Bean
    String to ;
    String from;
    // setters & getters

    FormA {
    ArrayList beans
    getBean()
    setBean(Bean b)
    }

    I know how to iterate over a list on a form to display the bean, but what I don’t know is how to create the beans in the jsp. Also, I still have to figure out how each field on the bean could have an error message to be displayed.
    Has anyone seen or done this?

    I have tried searching around, but so far I haven’t found a solution.

    Thank you

    #251820

    Riyad Kalla
    Member

    Moving to OT > Soft Dev

    #251831

    David
    Member

    Ok, I think the answer is the use of DynamicForms. If I have one or two values on the page, that would go on the form, and the dynamically sized list would be a bean on that forms collection – I think. The problem is that I don’t see how to create a bean for a user to populate with values. All the examples show the action creating this list, and then the JSP merely showing how to view them – which is the opposite of what I need.

    Config:
    <form-bean name=”requestForm” type=”org.apache.struts.action.DynaActionForm”>
    <form-property name=”bean” type=”com.xxx.yyy.myBean[]” size=”4″ />
    <form-property name=”fieldA” type=”java.lang.String”/>
    <form-property name=”fieldB” type=”java.lang.String”/>
    <form-property name=”fieldC” type=”java.lang.String”/>
    </form-bean>

    Then in my JSP:
    c:forEach var=”airRequest” items=”${requestForm.map}”>
    <html:text indexed=”true” name=”airRequest” property=”fieldA”/>
    <html:text indexed=”true” name=”airRequest” property=”fieldB”/>
    <html:text indexed=”true” name=”airRequest” property=”fieldC”/>
    </c:forEach>

    Now this doesn’t do anything because it is trying to display – but there isn’t anything to display?

    If someone sees what I am doing wrong I would appreciate it.

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: dynamic beans

You must be logged in to post in the forum log in