Hi Nick,
Thanks for your reply and kind support,
Please find the below code
page.xhtml (In this I have a datatable with list of project is displayed and Action column contains the <a4j:commandLink> "Tags" displyed in bold section in below code), after clicking on link the controller showAction() method is getting called and HtmlModalPanel is appear with the dynamically generated fields).
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jstl/core"
template="/WEB-INF/layout/default.xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j">
<ui:param name="focusedTab" value="project"/>
<ui:define name="title">
<h:outputText value="Project Listing"/>
</ui:define>
<ui:define name="head">
</ui:define>
<ui:define name="content">
<f:view>
<h:form id="projectListForm" prependId="false">
<rich:messages infoClass="global-info-message"
warnClass="global-warn-message"
errorClass="global-error-message"
style="float:right;margin-bottom:10px"/>
<rich:modalPanel id="tagPanel" binding="#{projectController.tagModalPanel}"/>
<rich:dataTable id="data_table"
width="100%"
border="0"
cellspacing="0"
cellpadding="0"
headerClass="headers"
rowClasses="alt1,alt2"
var="project"
value="#{projectController.accountFilteredProjects}"
binding="#{projectController.projectDataTable}"
rows="10">
<rich:column id="idColumn" sortBy="#{project.id}">
<f:facet name="header"><h:outputText value="ID"/></f:facet>
<h:outputText value="#{project.id}"/>
</rich:column>
<rich:column id="nameColumn" sortBy="#{project.name}" filterMethod="#{projectFilterBean.filterByName}" filterValue="#{projectFilterBean.nameFilterValue}">
<f:facet name="header"><h:outputText value="Name"/></f:facet>
<h:outputText value="#{project.name}"/>
</rich:column>
<rich:column id="actionColumn" width="160 px">
<f:facet name="header"><h:outputText value="Actions"/></f:facet>
<a4j:commandLink value="Tags"
action="#{projectController.showAction}"
oncomplete="Richfaces.showModalPanel('tagPanel');"
reRender="tagPanel"/>
</rich:column>
</rich:dataTable>
</h:form>
</f:view>
</ui:define>
</ui:composition>
ProjectController.java (calling the method for building the dynamic ModalPanel mention in bold section)
public class ProjectController
extends AbstractRESTfulController {
protected static String SUCEESS="success";
public String showAction() {
Project project = (Project) getProjectDataTable().getRowData();
String clickUrl = null;
ProjectHelper.buildTagModalPanel(getTagModalPanel(), project,clickUrl);
return SUCCESS;
} // end method showAction
public String generateTagJS() {
Map<String, String> requestParams = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
Long projectId = Long.parseLong(requestParams.get("projectId")); // values are getting from UIParameter request
Integer width = Integer.parseInt(requestParams.get("projectWidth"));
Integer height = Integer.parseInt(requestParams.get("projectHeight"));
Long accountId = Long.parseLong(requestParams.get("accountId"));
String accountSecurityKey = requestParams.get("accountSecurityKey");
System.out.println("submitted values==="+tagsBean.getTagsType()); // getting null after submiiting the ModalPanel Show button)
System.out.println("using request Parameter Object==="+requestParams.get("tagsType")); // getting null after submiiting the ModalPanel Show button)
return SUCCESS;
}
public HtmlDataTable getProjectDataTable() {
return projectDataTable;
} // end method getProjectDataTable
public void setProjectDataTable(HtmlDataTable projectDataTable) {
this.projectDataTable = projectDataTable;
} // end method setProjectDataTable
public HtmlModalPanel getTagModalPanel() {
return tagModalPanel;
}
public void setTagModalPanel(HtmlModalPanel tagModalPanel) {
this.tagModalPanel = tagModalPanel;
}
} //End of Class
ProjectHelper.java (Generating the HtmlModalPanel)
public abstract class ProjectHelper {
public static void buildTagModalPanel(HtmlModalPanel tagModalPanel, Project project, String clickUrl) {
tagModalPanel.getChildren().clear();
tagModalPanel.setMinWidth(300);
tagModalPanel.setAutosized(true);
FacesContext context = FacesContext.getCurrentInstance();
Application application = context.getApplication();
// BUILD THE HEADER
HtmlPanelGroup headerPanelGroup = new HtmlPanelGroup();
HtmlOutputText headerOutputText = new HtmlOutputText();
headerOutputText.setValue("Javascript tag");
headerPanelGroup.getChildren().add(headerOutputText);
// BUILD THE CONTROLS
HtmlPanelGroup controlsPanelGroup = new HtmlPanelGroup();
HtmlGraphicImage controlsCloseImage = new HtmlGraphicImage();
HtmlComponentControl controlsComponentControl = new HtmlComponentControl();
controlsCloseImage.setId("hideImage");
controlsCloseImage.setUrl("/images/icon_close.gif");
controlsCloseImage.setAlt("Close");
controlsCloseImage.setStyle("cursor: pointer;");
controlsComponentControl.setFor("tagPanel");
controlsComponentControl.setAttachTo("hideImage");
controlsComponentControl.setOperation("hide");
controlsComponentControl.setEvent("onclick");
List<UIComponent> controlsPanelGroupChildren = controlsPanelGroup.getChildren();
controlsPanelGroupChildren.add(controlsCloseImage);
controlsPanelGroupChildren.add(controlsComponentControl);
// SET HEADER AND CONTROLS IN THE FACET MAP
Map<String, UIComponent> modalPanelFacetMap = tagModalPanel.getFacets();
modalPanelFacetMap.put("header", headerPanelGroup);
modalPanelFacetMap.put("controls", controlsPanelGroup);
//Changes Added for Tags
HtmlForm form = new HtmlForm();
// For Tags Types
HtmlPanelGrid panelGrid = new HtmlPanelGrid();
HtmlOutputText lblTagType = new HtmlOutputText();
lblTagType.setValue("Type: ");
HtmlSelectOneMenu mnuTagType = new HtmlSelectOneMenu();
mnuTagType.setId("TagTypeId"+project.getId());
mnuTagType.setStyleClass("TagType");
mnuTagType.setValueExpression("value", application.getExpressionFactory().createValueExpression(context.getELContext(), "#{tagsBean.tagsType}", String.class));
mnuTagType.setImmediate(true); // Your suggesion
//For ValueChangeListener
Class[] params2 = new Class[]{ValueChangeEvent.class};
MethodExpression ef = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().
createMethodExpression(context.getELContext(),
"#{tagsBean.tagValueChanges}", null, params2);
MethodExpressionValueChangeListener vcl = new MethodExpressionValueChangeListener(ef);
mnuTagType.addValueChangeListener(vcl);
//Populating the list of items for Drop Down
UISelectItems items = new UISelectItems();
items.setId("TagChoices");
List<SelectItem> selectItemList = new ArrayList<SelectItem>();
selectItemList.add(new SelectItem("Standard"));
selectItemList.add(new SelectItem("Flyover"));
selectItemList.add(new SelectItem("Popup"));
items.setValue(selectItemList);
mnuTagType.getChildren().add(items);
panelGrid.getChildren().add(lblTagType);
panelGrid.getChildren().add(mnuTagType);
//For Indentifier
HtmlOutputText lblIndentifier = new HtmlOutputText();
lblIndentifier.setValue("Identifier: ");
HtmlInputText txtIdentifier = new HtmlInputText();
txtIdentifier.setId("IndentifierId"+project.getId());
panelGrid.getChildren().add(lblIndentifier);
panelGrid.getChildren().add(txtIdentifier);
// For ajax command Buttton
HtmlPanelGroup buttonPanelGroup = new HtmlPanelGroup();
HtmlAjaxCommandButton showCommandButton = new HtmlAjaxCommandButton();
showCommandButton.setId("ShowButtonId"+project.getId());
showCommandButton.setValue("Show");
String action = "#{projectController.generateTagJS}"; // calling the action after submitting
showCommandButton.setImmediate(true); // Your Suggestion
showCommandButton.setActionExpression(
createActionExpression(action, String.class));
showCommandButton.setOncomplete("javascript:Richfaces.hideModalPanel('tagPanel')");
UIParameter parameterProjectId = new UIParameter();
parameterProjectId.setName("projectId");
parameterProjectId.setValue(project.getId());
showCommandButton.getChildren().add(parameterProjectId);
UIParameter parameterWidth = new UIParameter();
parameterWidth.setName("projectWidth");
parameterWidth.setValue(project.getDimension().getWidth());
showCommandButton.getChildren().add(parameterWidth);
UIParameter parameterHeight = new UIParameter();
parameterHeight.setName("projectHeight");
parameterHeight.setValue(project.getDimension().getHeight());
showCommandButton.getChildren().add(parameterHeight);
UIParameter parameterAccountId = new UIParameter();
parameterAccountId.setName("accountId");
parameterAccountId.setValue(project.getAccount().getId());
showCommandButton.getChildren().add(parameterAccountId);
UIParameter parameterAccountSecurityKey = new UIParameter();
parameterAccountSecurityKey.setName("accountSecurityKey");
parameterAccountSecurityKey.setValue(project.getAccount().getSecurityKey());
showCommandButton.getChildren().add(parameterAccountSecurityKey);
UIParameter parameterTagsType = new UIParameter();
parameterTagsType.setName("tagsType");
parameterTagsType.setValue(mnuTagType.getSubmittedValue());
showCommandButton.getChildren().add(parameterTagsType);
HtmlAjaxCommandButton emailCommandButton = new HtmlAjaxCommandButton();
emailCommandButton.setId("EmailButtonId"+project.getId());
emailCommandButton.setValue("Email");
buttonPanelGroup.getChildren().add(showCommandButton);
buttonPanelGroup.getChildren().add(emailCommandButton);
panelGrid.getChildren().add(buttonPanelGroup);
tagModalPanel.getChildren().add(panelGrid);
//Ended for Tags
form.getChildren().add(tagModalPanel);
} // end method buildAccountUsersModalPanel
} // end class ProjectHelper