Dynamic forms in struts

Hi,
I have a pretty difficult problem that I don't know how to solve using struts. I need to generate dynamic surveys from a database. The structure of the survey can be different for every different user. I really want to use the struts Form classes but I'm not sure how to do this. The only way I can think of is messy...
For every new type of survey generated from the database...
1. Generate a new class definition for the struts Form object and compile that.
2. Every struts Action class that interacts with the new dynamic Form classes will need to use reflection on the dynamic Form object to be able to pull all of the data from that form.
I'm sure there are many web sites where forms are dynamically generated and I would think this problem has already been solved. Does anyone out there have any ideas?

Try to follow this way:
1 provide actions chain in your configuration file like this:
         <form-bean
              name="addFlatForm"
              type="app.owner.forms.AddFlatForm">
            </form-bean>
        <action
             path="/InitAddFlatForm"
             type="app.owner.actions.InitAddFlatFormAction"
             attribute="addFlatForm"
             validate="false"
             parameter="owner.extendedplace;place;/pages/AddFlat.jsp">             
        </action>
        <!-- "/pages/AddFlat.jsp" - jsp page with html:form on it-->     
        <action
             path="/AddFlatForm"
             type="app.owner.actions.AddFlatAction"
             name="addFlatForm"
             validate="true"
             input="/pages/AddFlat.jsp">
             <forward
                  name="success"
                  path="/shortinfo/Welcome.do"></forward>
        </action>2 first action(InitAddFlatFormAction) will be "prepare" action, where you must create new instance of the ActionForm descendant with Map, List, array etc definition. where your dynamic fields will be located , and fill the keys value from your database.
public class InitAddFlatFormAction extends Action{
     public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response){
          //obtain parameters
          String[] params = ActionHelper.parseParameter(mapping, 3, Constants.PARAMETER_SEPARATOR);
          //get extended place from session attribute
          ExtendedPlace currPlace = (ExtendedPlace)ServletUtils.getAttribute(
                    request, params[0], ServletUtils.SESSION_SCOPE);
          //create form if form == null
         if (form == null) {
              System.out.println("InitAddFlatFormAction::execute method: create new instance of action form.");
              //create new form instance
              form = new AddFlatForm(new HashMap<String, Object>());
              //set form to selected scope attribute
            if ("request".equals(mapping.getScope()))
                 ServletUtils.setAttribute(request,
                           form, mapping.getAttribute(), ServletUtils.REQUEST_SCOPE);   //just set the value to selected scope
            else
                 ServletUtils.setAttribute(request,
                           form, mapping.getAttribute(), ServletUtils.SESSION_SCOPE);   //just set the value to selected scope
         //fill the form
         AddFlatForm flatForm = (AddFlatForm) form;
         flatForm.setValue(params[1], currPlace);
         return URIUtils.forwardAction(params[2]);
     }3 second action(AddFlatAction) will be "process" action. This action can be used when your data are successful validated.
//any your actions4 form bean(ActionForm desctndant)
public class AddFlatForm extends ActionForm{
     public AddFlatForm(Map<String, Object> map){
          super();
          //check input arguments
          AssertHelper.notNullIllArg(map);
          setMap(map);
     private Map<String, Object> map = null;
     public void setMap(Map<String, Object> map) {
          this.map = map;
     public Map<String, Object> getMap() {
          return this.map;
     public void setValue(String key, Object value){
          getMap().put(key,value);
     public Object getValue(String key){
          return getMap().get(key);
    public ActionErrors validate(ActionMapping mapping,
            HttpServletRequest request) {
        return (null);
}And than in your jsp page you can use something like this:
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
                                        <c:set var="placeId">
                                             <bean:write name="extPlace" property="placeInfo.id"/>
                                        </c:set>
                                        <c:set var="groupId">
                                             <bean:write name="groups" property="filterGroupInfo.id"/>
                                        </c:set>
                                        <c:set var="filterId">
                                             <bean:write name="filters" property="filter.id"/>
                                        </c:set>
                                        <bean:message name="filters" property="filter.filterDescription"/>
                                        <html:text property="value(${placeId};${groupId};${filterId})"/>                                                                 Something like this are displayed in struts-example.war (example application for struts1.1)
pay attention for classes
EditRegistrationAction.java and SaveRegistrationAction.java
sorry for bad english... :)

Similar Messages

  • Dynamic forms struts

    I need to display a page with dynamic form elements. i.e I will not be aware of the form content...how many text boxes, drop downs while writing the concrete form bean.
    Can anyone let me know how to achieve this using struts.

    I'm not sure struts will work for you as you do not know what fields will be on the form until run-time.
    You may be stuck with working with the Action's request object:
    mRequest.getAttribute(mFieldName[1]);
    Where mFieldName is 1 or more form fields with the same name...
    I'm looking into this myself and will let you know if I come up with something better.

  • Dynamic form processing in struts

    Hi all,
    I need your help regarding dynamic form elements form processing.
    Here is my JSP Script,
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
    <html:html>
    <HEAD>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
         pageEncoding="ISO-8859-1"%>
    <TITLE>Processing Dynamic Forms</TITLE>
    <script type="text/javascript">
    //function which adds new row
    function AddRow()
         tb=document.getElementById("demo");
         // attach counter
         lnrows = tb.rows.length;
         //alert(lnrows);
         newrow = tb.insertRow(lnrows);
         var fourth_col = "amt"+lnrows;
         cell3=newrow.insertCell(0);
         cell3.innerHTML="<center><input type='text' id='"+fourth_col+"' name='"+fourth_col+"' size='10'/></center>";
         document.getElementById("cntr").value = lnrows;
    // function to delete row
    function DeleteRow()
         tb=document.getElementById("demo");
         lnrows = tb.rows.length;
         //alert(lnrows);
         if(lnrows > 2)
              tb.deleteRow(lnrows-1);
              document.getElementById("cntr").value = tb.rows.length - 1;
    </script>
    </HEAD>
    <BODY>
    <html:form action="/dynaActions">
    <TABLE id='demo' align='center' width='80%' border='1'>
    <TR>
         <TH width='25%'>Party Name</TH>
    </TR>
    <TR>
         <TD align='center'><input type='text' id="party1" name="party1" size="30" /></TD>
    </TR>
    </TABLE>
    <TABLE align='center' width='80%' border='0'>
    <TR align="right">
    <td>
         <html:button property="Add" value="Add" onclick="AddRow();" ></html:button>
         <html:button property="Remove"  value="Remove" onclick="DeleteRow();"></html:button>
    </td>
    </TR>
    <TR align="center">
    <td>
         <input type='hidden' id="cntr" name="cntr" value="1" />
         <html:submit/>
    </td>
    </TR>
    </TABLE>
    </html:form>
    </BODY>
    </html:html> As you seen there is dynamically form elements generated as many as required. Now how do I process this with ActionForm & Action?
    Regards,
    Mahesh

    Hi rrhegde,
    Thanks for response.
    Ok, So instead of making it party1, party2, party3, party4, .............................
    if I make it party[1], party[2], party[3], party[4],.............................
    But then how do I process this array. Since the array length will not be fixed, it depends upon users.
    If possible pls provide me some example code on this.
    Thanks & Regards,
    bonzy

  • How To add dynamic field using struts?

    Hi All,
    I new to the struts. I wanted to add dynamic form field .

    Why do so many people ask struts questions here? It's an Apache project and it has a mailing list. Why not go directly to the source? [http://struts.apache.org/]
    Kaj

  • Create a dynamic form where selected text boxes appears, based on options chosen in a drop-down box

    HELP!!! Can anyone please provide some guidance on how to create a dynamic form where selected text boxes appears, based on options chosen in a drop-down box.
    I have a form which – based on the department that's selected from a drop-down box – will have different form fields/text boxes, etc, made available.
    Is this possible in LiveCycle, if so, can you please provide the script/info - as needed.
    Thanks,

    In the preOpen event of the second dropdown list you put something like (in formCalc):
    if (dropdown1 == 1) then
    $.clearItems()
    $.setItems("Year, 2 Year,  3 Year")
    elseif (dropdown1 == 2) then
    $.clearItems()
    $.setItems("3 Year,  4 Year")
    endif

  • Get values from dynamic form items

    Hi All,
    I create a dynamic form with text input component
    private function buildForm():void{
                    var numberOfColumns:Number = 5
                    var formItem:FormItem = new FormItem();
                    var hBox:HBox = new HBox();
                    for(var i:Number=0; i< numberOfColumns; i++) {
                        var formInput:TextInput = new TextInput();
                        formInput.text = "test";
                        formInput.id = "txt_" +i;
                        hBox.addChild(formInput);
                    formItem.addChild(hBox);
                    loansForm.addChild(formItem);
    I can see the text input components, update the values.
    How can I get the updated values from the input components?
    I try  this["txt_" + i].text  but not working. It's not finding the component with the dynamic value.
    Any ideas?
    Thanks
    Johnny

    Hi,
    Here is the related thread, u will get some help
      http://forums.adobe.com/message/3075226
    Thanks and Regards,
    Kanchan Ladwani | [email protected] | www.infocepts.com

  • How to create a dynamic form with bind variables :schema & :table_name

    My application has two LOV's, one to select a schema, and the next to select a table within that schema. I then have a button which passes me to a report which displays the data in that table.schema.
    I now want to create a link to a form where I can edit the record based on the rowid of that table.schema, but it doesn't appear that I can create a dynamic form where I pass the schema.table_name and rowid. Is this possible? Can anyone advise how I can do this? The form builder only wants a fixed schema/table name.
    Thanks in advance.
    Stuart.

    Hi Stuart,
    In this sort of situation, you will need to be a bit creative.
    I would suggest a pipeline function called as if it was a report.
    Then you can pipe out the required fields.
    Since you will have a variable number of fields, you could use two of the multi row field names for your field names and values.
    Then after submit, you can create your own procedure to loop through the fields (stored for you in the Apex package) and update the table as required.
    Not very specific I'm afraid, but it should work.
    Regards
    Michael

  • Dynamic Forms and WF

    Hello,
    I have designed a dynamic form, where user can add rows dynamically by clicking a button on the form, the form is working fine in preview in designer.
    this form is initiating a LC WF process, but, if I deploy this form to form manager as an XDP and choose to render it to PDF, adding rows function does not work, however if I save this as dynamic PDF from LC designer and deploy it again to form manager, it works !!
    However, I can not use PDF generated from LC Designer since I found that commenting and annotations are not working ( I am using acrobat ) which is an important feature, also, web services calls are not working even, again from Acrobat!
    How can I set the form server installed with workflow server to render XDP templates into dynamic PDF forms ?
    Or alternatively how to enable commenting and fix web service calls in PDF rendered form ?
    Thank you for help,
    Greetings,

    By default Forms and Form Manager are configured to render a PDF as either static or dynamic based on some values in the XDP. By default those values will tell it to render a static PDF. What you can do, in Designer save as a dynamic PDF, then open the dynamic PDF in Designer and save as an XDP. Upload that XDP to Form Manager, the tags will be present to tell it to be rendered as a dynamic PDF. There's a better way if you are using Designer 7.1 and Forms 7.1, but since I don't know your environment this is a way that will work regardless of versions.
    Annotations will not work in dynamic PDF's though. Currently annotations make no sense in dyanmic PDF's since the template of the PDF can dynamically change while annotations are bound to a specific location. IE: You have a dynamic PDF that is initial 4 pages and add an annotation to page 4. Later the template of the PDF changes based on data and user interaction and it is now a 2 page PDF, but the annotation is still on page 4 which no longer exists...
    Chris
    Adobe Enterprise Developer Support

  • Remove scroll bars in dynamic form

    Hi all,
    I'm starting to kick myself every time I put a post here.  Apologies and thank you for everyone's help - slowly but shortly I'll be one of the people answering the questions.
    Really easy one (I think).  A have a dynamic form, which updates a dynamic list.  Is there a way to alter a text area in the dynamic form, so that it is a fixed area  i.e. when you get to the end of the line/characater usage, the cursor goes down to the next line rather than creating a horizontal scroll bar and running forever into the distance.  I have played around with Wrap options without luck, the css doesn;t seem to play much of a part as this is an actual text area in Dreamweaver as opposed to a CSS clipping in the list.
    Thanks again,
    Nathan

    NJFuller wrote:
    Perfect! Thank you Albert.  Is it possible to add virtual wrap to a box in a dynamic list?  As that is not presented in a normal html form'ish style way.....?
    Hi Nathan,
    as a Dynamic List displays pure text only, you´ll need to help yourself by formatting the displayed column using PHP. There are several ways to add "virtual" line breaks, and the most straightforward (though certainly not the most elegant) solution would be to apply the PHP function wordwrap which wraps a string to a given number of characters.
    The following example will wrap the text after 40 chars, and the "wordwrap" function will - as always - have to replace ADDT´s default "KT_FormatForList" function:
    <?php echo wordwrap($row_rsqueryname1['columnname'], 40, "<br />\n"); ?>
    Cheers,
    Günter

  • How to make my dynamic form pages flow correctly?

    I have created a dynamic form which has multiple questions with expandable text fields that will take multiple pages once completed.  I do not know how to make the form flow correctly past the first page.  I can attach the form if I knew how to do that.

    Thank you Paul.  Your editing assistance was greatly appreciated. I think I now understand that there should be only one page subform that is flowed, regardless of how many text box objects I have in my questionnaire. This did the trick.

  • Is it possible to update multiple tables with a dynamic form?

    I have columns from two tables populating a dynamic form. I am trying to have the form update both tables on submit. I have tried both a linked transaction and a custom transaction but I am not making progress. Only the master table is being updated. Is it possible with ADDT to update two tables with a dynamic form?

    I meant
    SXMSMSTAT
    SXMSSYERR
    Thanks.

  • My dynamic form - issue with saving data (urgent-i would greatly appreciate any help)

    Hello,
    I have some problems with this dynamic form (created in livecycle)  http://www.pathology.ubc.ca/Academic_Activity_Data_Form_Jan_4_2013.pdf .  It doesn't save data unless I add a' new row' to any of these tables.   There are a few text fileds and if I type anything in there data won't be saved unless I trigger it by adding randomly a table row.  This is big problem as this form will be used for updates and if I want to change any of my entered records I will always have to remember to 'add a new row' otherwise just adding/changing text won't be saved. This might sound confusing but you will understanding what is going on if you type in your name and save the form and then type in your name, add a table row and save the form (first case won't be saved second will).
    I would greatly appreciate any help.
    Debbie

    Hi Marco Russo ,
    = CALCULATE (
        SUM ( [measure] ),
        PARALLELPERIOD (
            SAMEPERIODLASTYEAR ( DateTime[DateKey] ),
            0,
            QUARTER
    I have used the above DAX function it is working fine and i have applied same for Year , Quarter and Month 
    But when i remove month filters (Slicer) and Year filters in Power view report
     it is showing total Year values for Year and Quarter values
    for Quarter etc..
    Like below i am getting 
    Last Yr Month Amt   Current Yr Month Amt   Last Yr Qtr Amt   Current Yr Qtr  Amt    Last Yr     Current Yr
     10000                     30000                              10000                30000
                        30000       30000
    but i need Blanks in report if i am not selecting any filters
    thanks,
    Sreeni

  • Page Number Disappesrs when click on Reset button in Dynamic Form

    Dear all,
    In dynamic forms I have taken Page n of m field outside the content area in master pages.I have added the reset button in body pages of the form.In the pdf When I click on Reset button the page nos are disappearing along with the other data.
    I want the page no should not disappear.How can I get rid of this problem. If any body can please help me.
    Thanks a bunch in advance
    Regards
    Rakesh

    Firefox checks on the server if the file has been modified if you use the back button.<br />
    If the page was requested by sending post data to the server then Firefox sends that post data and asks for confirmation.<br />
    You can try to use the tab history of the Back button skip sites that require sending post data.
    You can also try if it works if you set to never check the server by setting the browser.cache.check_doc_frequency pref to 2.
    *http://kb.mozillazine.org/browser.cache.check_doc_frequency

  • With a PDF Dynamic form using show/hide actions, how to ensure that when the completed form is saved, closed and re-opened, the form still show the fields as before it was closed?

    With a PDF Dynamic form using show/hide actions, how to ensure that when the completed form is saved, closed and re-opened, the form still show the fields as before it was closed?
    I have developed a form with fields hidden by default, that become visible based on box ticked or radio button selections.
    My problem is that, when I close the form and re-open it, it comes back to it's default presentation, regardless of the information already recorded in the form (including in the now hidden fields.
    How to correct that
    Thanks in advance for any hint you can provide.

    I've had the same problem. This solved it...
    Go to the "Form properties..." in the File-menu. Select "Run-time" to the left and in the box "Scripting" Preserve scripting changes to form when saved: choose Automatically (Script-based state changes are saved locally in an insecure fashion. This option cannot be used for certified forms).
    Hope it works for you to...

  • Saving dynamic forms in Acrobat Reader

    How do you create PDF dynamic forms and save them so that they can be completed and saved  in Acrobat Reader.

    Thank you very much for your help. As I said this was my first attempt with Livecyle. I had sold the concept of dynamic forms to a collegue and promised to do a dynamic form one for him before going on a winter holiday. Completed the form in a hurry only to find I could not enable users with Acrobat Reader. My worry was that I would not be able to save dynamic forms without additional software, but your helpful comments confirm its something I have done that is causing my issue.
    I think Livecycle is a great product, but fragmented information is available for individual users. Bought the Book PDF Forms Using LifeCycle Designer (Acrobat 9) and joined PDFscripting web service which are both good in there own way. I get confused with Adobe's help, not being IT techie and the difference of Enterprise Editions of LifeCycle on how to get the best out of LiveCycle.
    Many thanks George for you assistance, I will retry when I return from my winter break.

Maybe you are looking for

  • Created a material  and want to post  by  using tcode mb1c, not  allowing.?

    friends i  have a problem here, i created a material   for  my  sales  order. i wanted  to  post  like 100 of them in my storage location. so i used  tcode mb1c, entered  the  storage location , plant along with  the movment type 561 .  it  goes  in 

  • IPhone 6 Plus - screen swipe problem in photo apps

    I am having issues swiping at at the bottom of my screen, but strangely it only seems to be in photo editing based apps, which suggests it is is some kind of software issue. My wife also has the same issue with her iPhone 6 Plus so I know it is not j

  • Restructure Purchase Order Form?

    Hi all I am in learning phase of SAP BYD. I have task to restructure the Purchase order Form. Contact should be Purchase request and orders (WC) > Purchase order / Général tab Buyer responsible field Below Contact I want to put new label Service Serv

  • Whole po value

    i want to know where will be whole po value will be updated. prasad.

  • "KGCore plug-in" error message & crash with voiceover

    Hi. I'm working on a small video (less than 2 min.) with an audio file already attached -- a short tune composed in GarageBand converted to .aif. I'm trying to add a small voiceover as well, but when the recording gets to the end of the sequence, it