Dynamic component addition in JSF

I have a loan application that I've done using JSF.
The form has, among other things, fields for previous addresses as well as previous employers. Initially I'm only including enough fields for the user to enter 2 address and 2 employers.
Since we're requiring that the user give us employers and addresses for the last 5 years this may not be enough.
So I'm looking for the best way to allow the user to add more employers and addresses dynamically;
An "add another address" link that when clicked returns a page with another address field, for example.
I have a controller bean in which I could create many (say 10) employee and address beans but that's wasteful. And I experimented with a vector of employers and addresses but couldn't figure out how to do it.
There must be a simple (JSF) way to do this.

How about using the value of rows attribute of
<h:dataTable dynamically by value binding or in a
event handler method you could do:
facesContext.getViewRoot().getChildren().add(component
Thank you, i'll give it a try.
I also found this thread to be helpful:
http://forums.java.sun.com/thread.jspa?threadID=555626&messageID=2816029

Similar Messages

  • Dynamic Form componants in my jsf page?

    how could i make dynamic form componant in my jsf page ,depend on user inputs or result from database or whatever , where i use sun studio creator ???

    you need to use the "rendered" attribute of the components...
    for example in your jsp put this...
    <h:outputText value="Hello" rendered="#{myBean.renderHello}"/>
    the render hello method looks like this in your backing bean "myBean"
    public boolean getRenderHello() {
    return true; // or false
    if getRenderHello() returns true, "Hello" will be displayed, if getRenderHello() returns false, it will not...
    you can also use expressions in the jsf... for example...
    <h:outputText value="Hello" rendered="#{myBean.someNumber == 5}"/>
    if the "getSomeNumber()" method in your backing bean returns 5 it will be true and "Hello" will show up... otherwise it won't... :)
    Hope this helps...
    -Garrett

  • Embedding a declarative component written in JSF 1.2 in a jsf page

    Hi ,
    I have a declarative component written in JSF 1.2 . I want to embed this declarative component in an ADF application which is using JSF 2.0.
    On creating a jspx page in JSF 2.0 & embedding decalrative component it just works fine but I have to embed it in a JSF page instead , which is not working.
    Any suggestions ?
    Thanks
    Vinit

    Hi,
    for JDeveloper 11g R2 you will need to know before whether the application you build uses JSPX page documents or Facelets. The technologies are different (introduced with JSF 2) and declarative components thus need to be build for the document type used by teh application
    Frank

  • Dynamic component in WHERE-condition for LOOP AT ?

    i want to make
    loop at itab where  (dynamic field) > 0
    how i can make it...
    Edited by: Thomas Zloch on Mar 2, 2010 2:47 PM

    I thought it's funny.
    And the problem can maybe be solved by using a completely dynamic where-condition, not just a dynamic component.
    http://help.sap.com/abapdocu_70/en/ABAPLOOP_AT_ITAB_COND.htm#!ABAP_ADDITION_4@4@
    Thomas
    P.S. meaningless subject enhanced, and please take the time to say hi and please when asking for help. Thanks.

  • Web Dynpro Abap - Dynamic Component Usage - parameters

    Hi,
    I have a this scenario:
    by a main WD component (COMP_MAIN) I have to call others WD components (COMP_1, COMP_2, COMP_3,...)
    I use Dynamic Component Usage
    l_view_controller_api->prepare_dynamic_navigation(
                        source_window_name          = 'W_SC'
                        source_vusage_name          = 'V_SC_USAGE_1'
                        source_plug_name            = 'TO_USAGE'
                        target_component_name       = l_wa_cmp_usages-used_component
                        target_component_usage      = l_wa_cmp_usages-component_usage_name
                        target_view_name            = ls_cmp_usage_group-interface_view
                        target_plug_name            = ls_cmp_usage_group-inbound_plug
                        target_embedding_position   = l_wa_cmp_usages-embedding_position ).
    l_wa_cmp_usages-component_usage->create_component( l_wa_cmp_usages-used_component ).
    I ask :
    is possible to write context nodes of COMP_MAIN into COMP_x?
    If yes, how can I do that?
    Thank you
    Al

    Hi,
    Please go through below pdf document which will help in understanding the componenet usage in webdynpro ABAP.
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/2e71ce83-0b01-0010-11a4-98c28a33195f
    Hope it will help you.
    Raghu

  • Chart component Library for JSF.

    HI,
    I've been testing the chart component library for JSF:
    http://jschart.sourceforge.net
    And it's very powerfull, but I think, is necessary more info about to develop appz with this.
    Anyone knows, a blog or a web that contains any example of the use?
    I've been working for days with the HOW TO in this web but it's very simply.
    Thx in advance!!!
    Regards.

    I have successfully used the jfreechart (cewolf) charting library with creator...its simple to use but also allows complex charts if you wish....
    http://cewolf.sourceforge.net/new/index.html

  • ADF JSF Shuttle Component - Additional input fields

    Hello,
    We're in the process of integrating the nice shuttle JSF component into our application. Our app though requires that before the assignment is done (by moving an item left ->right in the shuttle UI) a dialog window must be opened to allow the user to fill in additional input fields (i.e the targe N-M association table that is populated by the shuttle component, needs those additional fields filled for each new record).
    Is there a way to do that with the current shuttle component?
    Thanks in advance for any help.
    Jordi

    ckx,
    The components don't require a model reference (i.e. assocaition with a JavaBean). You can access all of the components on the posting page on the server, so you could definitely get all of the values that way. You can build up the tree dynamically as well.
    So the short answer is yes :-).
    <<KM>>

  • Problem creating dynamic component children with RestoreState of JSF 1.2

    Hello everybody,
    With JSF 1.1, it was possible to create children of a component dynamically in the constructor of a component.
    But now, with JSF 1.2, there is an issue with the RestoreState as a new instance of each component of the tree is created.
    Does someone has an idea on how to solve this issue?
    One possibility is to create the children not in the component, but in the renderer of the component.
    But I'm not really convinced of this solution...
    Thank you in advance.
    bgOnline

    You can create a new component dynamically in the method setParent() according to the following code snippet:
    public void setParent(UIComponent parent) {
    if (parent != null) {
    List<UIComponent> children = parent.getChildren();
    Application application = FacesContext.getCurrentInstance().getApplication();
         componentLabel = (HtmlOutputLabel) application
         .createComponent(HtmlOutputLabel.COMPONENT_TYPE);
         componentLabel.setTransient(true);
         children.add(componentLabel);
         } else if (parent == null) {
         if (componentLabel != null) {
         List<UIComponent> children = getParent().getChildren();
              children.remove(componentLabel);
              super.setParent(parent);
         }

  • How to get values from dynamic component?

    Hi:
    I am displaying dynamic components based on user selection, where InputText and OutputText display properly. But now i want to read that component value on
    button click. Can any body help me in that?
    Source code is as follow,
    text.xhtml
    *<code>*
    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
         xmlns:h="http://java.sun.com/jsf/html"
         xmlns:f="http://java.sun.com/jsf/core"
         xmlns:ui="http://java.sun.com/jsf/facelets"
         xmlns:p="http://primefaces.prime.com.tr/ui"
         xmlns:ice="http://www.icesoft.com/icefaces/component"
         template="/WEB-INF/includes/templates/page-template.xhtml">
         <ui:define name="page-content">
              <div class="exampleBox splashContainer"
                   style="background: url('./xmlhttp/css/rime/css-images/contentContainer_bg.gif') top repeat-x">
              <table>
                   <tr>
                        <td colspan="2">
                        <h2>Set Request Process Flow</h2>
                        </td>
                   </tr>
                   <tr>
                        <td colspan="2"><ice:messages style="color:red;" /></td>
                   </tr>
                   <tr>
                        <td><ice:outputText value="Request Type*"></ice:outputText></td>
                        <td><ice:selectOneMenu value="#{offlinereq.requestno}"
                             valueChangeListener="#{offlinereq.requestChange}"
                             partialSubmit="true">
                             <f:selectItem itemValue="" itemLabel="--Select--" />
                             <f:selectItems value="#{offlinereq.requests}" />
                        </ice:selectOneMenu></td>
                   </tr>
                   <tr>
                        <td>*<h:panelGroup binding="#{offlinereq.panelBind}">*
    *                    </h:panelGroup>*</td>
                   </tr>
                   <tr>
                        <td colspan="4"><ice:commandButton value="Add"
                             actionListener="#{offlinereq.add}" /> <ice:commandButton
                             value="Update" actionListener="#{offlinereq.update}" /> <ice:commandButton
                             value="Delete" actionListener="#{offlinereq.delete}" /> <ice:commandButton
                             value="Reset" actionListener="#{offlinereq.reset}" /></td>
                   </tr>
              </table>
              </div>
         </ui:define>
    </ui:composition>
    *</code>*
    bean.java
    *<code>*
    //ValuechangeListener
         public void requestChange(ValueChangeEvent e){
              System.out.println("Select Value is::"+e.getNewValue()+"::"+userid);
              Connection conn=null;
              try {
                        if(!panelBind.getChildren().isEmpty())
                             panelBind.getChildren().clear();
                   Class.forName ("oracle.jdbc.OracleDriver");
                   conn = JdbcUtil.getConnection();
                   Statement stmt = conn.createStatement();
                   String sql="select * from IB_CUSTOMER_REQUEST_PARAMETERS where IB_REQMAST_SRNO='"+e.getNewValue()+"'";
                   ResultSet rs = stmt.executeQuery(sql);     
                   String out="out";
                   int i=1;
                   String ii;
                   while(rs.next()) {          
                        FacesContext facesContext = FacesContext.getCurrentInstance();
              Application application = facesContext.getApplication();
              HtmlPanelGrid grid = (HtmlPanelGrid)application.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
                   grid.setColumns(2);
              HtmlOutputText output = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
                   output.setValue(rs.getString("IB_CUSTREQSTPARA_NAME"));
                   ii=Integer.toString(i);
                   output.setId("a"+ii.toString());
                   System.out.println("id"+ii);
                   HtmlInputText input = (HtmlInputText)application.createComponent(HtmlInputText.COMPONENT_TYPE);
                   //input.setValue(rs.getString(1));
                   grid.getChildren().add(output);
                   grid.getChildren().add(input);
                   panelBind.getChildren().add(grid);
                   i++;
              catch(Exception e1)
                   System.out.println(e1);
         //Action listeners
         public void add(ActionEvent e)
              System.out.println("ADD");
    *</code>*
    Thank You,
    Anup

    Where are you stuck? find the component (UIComponent.findComponent) in the JSF component tree by its ID and get the value from it. This article might help:
    http://illegalargumentexception.blogspot.com/2009/02/jsf-working-with-component-ids.html
    Note: the code tag is \                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • MyFaces'  JspTilesViewHandlerImpl   &   dynamic component rendering

    Hi,
    First -- if you're on the myfaces user list, this is a repeat post. Skip!
    Second, I don't mean to offend the RI dev guys with this myfaces post!
    Has anyone dynamically rendered JSF components while using myfaces� JspTilesViewHandlerImpl view handler?
    I have a WebGalileoFaces tabbed panel component. Its listener attaches sub-tabs to it dynamically. The rendering works without using the view handler above. Yet, when I use the myfaces handler, I get an NPE. My listener impl is below.
    The view handler appears to cut off access to the actual UIViewRoot so the form cannot be found. I�ve tried a couple calls directly to the handler using context.getApplication().getViewHandler() yet, none of the methods gave me access to it (well, that I could figure out).
    Ideas anyone?
    Thanks
    Lorinda
        public void processTabSelected(TabSelectedEvent event)
                throws AbortProcessingException {
            context = FacesContext.getCurrentInstance();
            // who sent the event?
            FacesTabbedPanel eventSource = (FacesTabbedPanel) event.getSource();
            UIComponent tabbedPanel = event.getComponent();
            String tabName = tabbedPanel.getId();
            String formId = tabbedPanel.getParent().getId();
            LOG.info("Tab selected:   " + tabName);
            LOG.info("Parent form:   " + formId);
         UIForm form = (UIForm) context.getViewRoot().findComponent(formId);             
    NPE HERE ----  UIPanel panel =  (UIPanel) form.findComponent("childTabsGrid");
    // NOTE:  the childTabsGrid must be used to attach children.
            if (panel == null) {
                LOG.error("PanelGrid   'childTabsGrid'   could not be found.  ");
            } else {
    //  ATTACH SUB TABS
                // clear the childTabsGrid to prevent stacking child tabs      
                panel.getChildren().clear();
              ListSelectionModel selectionModel = eventSource.getListSelectionModel();
               UIComponent newTabbedPanel = createSubTabbedPanel(selectionModel);
               panel.getChildren().add(newTabbedPanel);
            }

    Yes, i have created a complete portal page using a custom portal tab and JspTilesViewHandlerImpl with all components dynamically rendered and inserted by tiles: dynamic partal tabs, i18n implementation for mesages and SelectItems, dynamically change company layout with its own look-and-feel if a requested information belongs to a company (division, department, branch office, etc). There is some abnormality and how i go around to get the solution up and running. I will post the details in myfaces dev list in the next couple days.
    In essence, the navigation page dispatched by JspTilesViewHandlerImpl works properly with all Jsf UI components. However, within this tile definition and its own layout, any fragment inserted by tiles such as portlets in the left/right columns and the display fragment does not have jsf <h:commandButton> and <h:commandLink> correctly picked up the action while <h:outputLink> properly linked to the intended page.
    I temporarily solve the issue to get the portal up and running. However, this is only a temporary solution since it will severly limit a complete integration of Jsf+Tiles. A complete solution needs to be addressed, which i thing myfaces developers can quickly patch it.
    BaTien
    DBGROUPS

  • Create dynamic code on a JSF with ADF Faces

    Hi,
    the next is just sample, nothing to production system, but if I can do the sample I can do something to production system.
    Fine.
    let's suppose that I want to create a html link
    in run-time over a JSF page with ADF Faces component.
    I can do that, I did using javascript and Custom tag,
    but the html link is placed out of the body of the page instead of put it over the place that I put it in development-time
    so, now my question is:
    how I can generate dynamic code using ADF FACES component commandButton or any others.
    any suggestion??
    P.D. if you need more info ask me.

    Hello Jeanne.
    You are right, I used <f:verbatim> element to wrap all my non-JSF elements and it work. :)
    so good so far.
    but, dynamic code mean generate code in this case HTML in run-time.
    That is to say: write code HTML just in time I invoke a page.
    That is posible through Custom Tags.
    You create a Custom Tags this tag generate HTML code after to process any Business Logic. then you put the tag in the page that you want to use it
    someting like this:
    <afh:rowLayout halign="center">
    <afh:cellFormat halign="center">
    <ESE-utilities:populateMenu/>
    </afh:cellFormat>
    </afh:rowLayout>
    the just above bold line is my Custom Tag that generate HTML code
    and not work.
    but, if I replace the tag directly using HTML code in the page, for example:
    <afh:rowLayout halign="center">
    <afh:cellFormat halign="center">
    <f:verbatim>
    prueba
    </f:verbatim>
    </afh:cellFormat>
    </afh:rowLayout>
    it work
    so, now my new question is:
    ¿How can I use a Custom Tagthat generate HTML code, and that code have been written inside of my body page?
    Thanks in advantage for your reply.
    Mauricio

  • How to create dynamic DataTable with dynamic header/column in JSF?

    Hello everyone,
    I am having problem of programmatically create multiple DataTables which have different number of column? In my JSF page, I should implement a navigation table and a data table. The navigation table displays the links of all tables in the database so that the data table will load the data when the user click any link in navigation table. I have gone through [BalusC's post|http://balusc.blogspot.com/2006/06/using-datatables.html#PopulateDynamicDatatable] and I found that the section "populate dynamic datatable" does show me some hints. In his code,
    // Iterate over columns.
            for (int i = 0; i < dynamicList.get(0).size(); i++) {
                // Create <h:column>.
                HtmlColumn column = new HtmlColumn();
                dynamicDataTable.getChildren().add(column);
                // Create <h:outputText value="dynamicHeaders"> for <f:facet name="header"> of column.
    HtmlOutputText header = new HtmlOutputText();
    header.setValue(dynamicHeaders[i]);
    column.setHeader(header);
    // Create <h:outputText value="#{dynamicItem[" + i + "]}"> for the body of column.
    HtmlOutputText output = new HtmlOutputText();
    output.setValueExpression("value",
    createValueExpression("#{dynamicItem[" + i + "]}", String.class));
    column.getChildren().add(output);
    public HtmlPanelGroup getDynamicDataTableGroup() {
    // This will be called once in the first RESTORE VIEW phase.
    if (dynamicDataTableGroup == null) {
    loadDynamicList(); // Preload dynamic list.
    populateDynamicDataTable(); // Populate editable datatable.
    return dynamicDataTableGroup;
    I suppose the Getter method is only called once when the JSF page is loaded for the first time. By calling this Getter, columns are dynamically added to the table. However in my particular case, the dynamic list is not known until the user choose to view a table. That means I can not call loadDynamicList() in the Getter method. Subsequently, I can not execute the for loop in method "populateDynamicDataTable()".
    So, how can I implement a real dynamic datatable with dynamic columns, or in other words, a dynamic table that can load data from different data tables (different number of columns) in the database at run-time?
    Many thanks for any help in advance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    flyeminent wrote:
    However in my particular case, the dynamic list is not known until the user choose to view a table. Then move the call from the getter to the bean's action method.

  • Dynamic User Authentication in JSF, ADF BC Application

    I have developed a JSF, ADF BC Application using JDeveloper 10.1.3.3. My application consists of jspx pages and I also have to integrate some existing oracle forms with it using OraFormsFaces library.
    I have successfully used custom DBProcLogin Module by Frank to authenticate the users with the help of a stored procedure and user credentials stored in database tables.
    During integrating Oracle Forms I realised that some of these oracle forms use get_application_property(username) to retreive connected user information. All of the users which are stored in database tables are also oracle users with the same credentials as stored in database tables. The existing oracle forms based application was connecting to Oracle every time with different provided user credentials each time and therefore returning correct (required) user name information.
    Now since I have used DBProcLogin Module in new ADF application, when I run it, user is successfully authenticated but get_application_property(username) in the existing oracle forms returns the user name that application module is using to connect with the database. To make it work correctly, I want my ADF application to connect to oracle database with different user each time.
    I have searched and seen topics such as, Dynamic JDBC Credentials, Database Proxy Users etc. But I am confused with the width and depth of this much information available. Therefore, I thought I may get some advice from the experts present in the forum that which of the techniques will go best with my application.
    Keeping in view the scenario that I have provided, can someone please guide me to the best suitable technique and the related information/documentation?
    Thanks in advance,
    Amir

    Hi,
    the whitepaper you reference is written by the expert on this subject. Samples are posted by the same author: http://radio.weblogs.com/0118231/stories/2004/09/23/notYetDocumentedAdfSampleApplications.html
    Note that what you try to do will create a dedicated connection for Forms and ADF, which means that 100 users will have 200 database connections open.
    Frank

  • Dynamically create selectManyCheckbox in jsf

    <address>Hai every one
    How can i dynamically create selectManyCheckbox using arrayList in jsf..
    How can i get the selected values and save to database... using jsf...
    Thank in advance..
    shashi
    </address>

    Write below code in backing bean
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import javax.faces.model.SelectItem;
    public class DynamicListBean {
         private ArrayList dynList = new ArrayList();
         private SelectItem[]items;
         private List dList = new ArrayList();
         private String selectedCategory;
         public DynamicListBean()
              items=populateSelectOneMenu();
         public SelectItem[] getItems() {
              return items;
         public void setItems(SelectItem[] items) {
              this.items = items;
         public String getSelectedCategory() {
              return selectedCategory;
         public void setSelectedCategory(String selectedCategory) {
              this.selectedCategory = selectedCategory;
         public List getDList() {
              return dList;
         public void setDList(List list) {
              dList = list;
         public ArrayList getDynList() {
              return dynList;
         public void setDynList(ArrayList dynList) {
              this.dynList = dynList;
         public SelectItem[] populateSelectOneMenu() {
              String a = "B";
              List selectItems = new ArrayList();
              for (int i = 1; i < 5; i++) {
                   dList.add(a + i);
              Iterator it = dList.listIterator();
              while (it.hasNext()) {
                   String label = (String) it.next();
                   selectItems.add(new SelectItem(label));
              return (SelectItem[]) selectItems.toArray(new SelectItem[0]);
    write below code in jsppage
    <%@ page language="java" pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
    <%String path = request.getContextPath();
                   String basePath = request.getScheme() + "://"
                             + request.getServerName() + ":" + request.getServerPort()
                             + path + "/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
         <head>
              <base href="<%=basePath%>">
              <title>
                   My JSF 'index.jsp' starting page
              </title>
              <meta http-equiv="pragma" content="no-cache">
              <meta http-equiv="cache-control" content="no-cache">
              <meta http-equiv="expires" content="0">
              <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
              <meta http-equiv="description" content="This is my page">
              <!--
         <link rel="stylesheet" type="text/css" href="styles.css">
         -->
         </head>
         <body>
              <f:view>
                   <h:panelGrid id="BatchesList" rendered="true">
                        <h:form>
                        <h:outputText value="Select Batch" />
                             <h:selectOneMenu value="#{dbl.selectedCategory}">
                                  <f:selectItems value="#{dbl.items}" />
                             </h:selectOneMenu>
                        </h:form>
                   </h:panelGrid>
              </f:view>
         </body>
    </html>

  • Dynamically displaying rows in jsf

    hi,
    I have arequirement in jsf like I have to display the rows dynamically when I click on Add New Product and also I have to display the products that are already added to the database. When I click on Add New I should be able to add the new product and after that i should be able to save the details to the database. Can I implement this using h:datatable tag?

    h:datatable is used to display an html table, but this is not enough to implement what you want.
    what do you need is a jsf tutorial to see how this framework (jsf) works.
    here http://www.coreservlets.com/JSF-Tutorial/ a very good tutorial.
    hope it helps

Maybe you are looking for