HtmlModalPanel on rerendering hide the Modal Panel
kapil29 Aug 23, 2010 6:39 AMHi,
I have dynamically generated HtmlModalPanel when clicking on <a4j:commandButton /> component. The modal panel displays the several form elements on it (i.e. textarea for emails , textboxes and two buttons <show> and <email>.). Now the situation is I need to display the email button only when the contents in the textarea are not empty. Initially when Modal Panel appear I need to hide the email button.
I have implemented this by using HtmlAjaxSupport for hiding / showing button using backing bean boolean property, but when onchange event is occured on textarea and panel is rerendered, the Modal Panel is closed when action is finishes.
HtmlAjaxCommandButton emailCommandButton = new HtmlAjaxCommandButton();
HtmlOutputText lblEmail = new HtmlOutputText();
lblEmail.setValue("Email: ");
HtmlInputTextarea txtEmail = new HtmlInputTextarea();
txtEmail.setCols(20);
txtEmail.setRows(5);
txtEmail.setReadonly(false);
txtEmail.setValueExpression("value", application.getExpressionFactory().createValueExpression(context.getELContext(), "#{tagBean.emails}", String.class));
txtEmail.setImmediate(true);
Class[] EmailsClass = new Class[]{ValueChangeEvent.class};
MethodExpression emailsME = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().
createMethodExpression(context.getELContext(),
"#{tagBean.emailsValueChanges}", null, EmailsClass);
MethodExpressionValueChangeListener emailsVCL = new MethodExpressionValueChangeListener(emailsME);
txtEmail.addValueChangeListener(emailsVCL);
HtmlAjaxSupport ajaxSupport = new HtmlAjaxSupport();
ajaxSupport.setActionExpression(FacesContext.getCurrentInstance().getApplication().getExpressionFactory().
createMethodExpression(FacesContext.getCurrentInstance().getELContext(),
"#{projectController.getEmailButtonStatus}", String.class, new Class[] {}));
ajaxSupport.setEvent("onchange");
ajaxSupport.setReRender("tagPanel");
txtEmail.getFacets().put("a4jsupport",ajaxSupport);
panelGrid.getChildren().add(lblEmail);
panelGrid.getChildren().add(txtEmail);
emailCommandButton.setId("EmailButtonId"+project.getId());
emailCommandButton.setValue("Email");
emailCommandButton.setValueExpression("rendered",application.getExpressionFactory().createValueExpression(context.getELContext(), "#{tagBean.emailButtonStatus}", Boolean.class));
String emailAction = "#{projectController.emailTagAction}";
emailCommandButton.setImmediate(true);
emailCommandButton.setActionExpression(
createActionExpression(emailAction, String.class));
emailCommandButton.setOnclick("javascript:Richfaces.hideModalPanel('tagPanel')");
buttonPanelGroup.getChildren().add(emailCommandButton);
Can any one let me know what is the exact cause for this isseue and how to reslove it.