将参数传递给同一页面中的对话框 [英] Pass parameter to dialog in the same page
问题描述
我有一个页面包含一个表单和嵌套在对话框中的其他表单.单击主窗体中的按钮时,我需要将参数传递给对话框
<p:dataTable var="form" value="#{myBean.formList}"><p:commandButton id="selectProduct"update="selectProductForm" oncomplete="selectProductDlg.show()"图像="ui-icon-" ><f:param name="formId" value="#{form.id}"/></p:commandButton></p:dataTable></h:form><p:对话框>...<h:form><p:commandButton action="#{myBean.setSelected}"更新=main_form"oncomplete="if(#{myBean.errorText == 'SUCCESS'}){ selectProductDlg.hide();}"值=秒"></p:commandButton>
我在带有代码的 myBean 中看不到 formId:
if (form == null) {HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();if(req.getParameter("formId") != null) {formId = Long.valueOf(req.getParameter("formId"));}if (formId != null && !"".equals(formId)) {form = formService.findById(formId);}}
我错在哪里谢谢
假设bean在view作用域内,只需在datatable列的command按钮的action方法中将其设置为bean属性direclty即可.
>
<p:dataTable var="form" value="#{myBean.formList}"><p:列><p:commandButton id="selectProduct"action="#{myBean.setCurrentForm(form)}"update="selectProductForm" oncomplete="selectProductDlg.show()"图像="ui-icon-"></p:commandButton></p:列></p:dataTable></h:form><p:对话框><h:形式><p:commandButton action="#{myBean.setSelected}"更新=main_form"oncomplete="if(#{myBean.errorText == 'SUCCESS'}){ selectProductDlg.hide();}"值=秒"></p:commandButton></h:form></p:对话框>
如果对话框中有取消按钮,则需要让它的action方法将其设置为null
.
无需在 POST 请求中摆弄原始 HTTP 请求参数.
应该尽可能多地仅用于 GET 请求(例如
,
等).
I have a page contains a form and other form nested in a dialog. I need to pass parameter to dialog when button clicked in the main form
<h:form>
<p:dataTable var="form" value="#{myBean.formList}">
<p:commandButton id="selectProduct"
update="selectProductForm" oncomplete="selectProductDlg.show()"
image="ui-icon-" >
<f:param name="formId" value="#{form.id}" />
</p:commandButton>
</p:dataTable>
</h:form>
<p:dialog>
...<h:form>
<p:commandButton action="#{myBean.setSelected}"
update="main_form"
oncomplete="if(#{myBean.errorText == 'SUCCESS'}){ selectProductDlg.hide();}"
value="Sec">
</p:commandButton>
i can not see formId in myBean with code:
if (form == null) {
HttpServletRequest req = (HttpServletRequest) FacesContext
.getCurrentInstance().getExternalContext().getRequest();
if(req.getParameter("formId") != null) {
formId = Long.valueOf(req.getParameter("formId"));
}
if (formId != null && !"".equals(formId)) {
form = formService.findById(formId);
}
}
where am i wrong thanks
Assuming that the bean is in the view scope, just set it as a bean property direclty in the action method of the command button in the datatable column.
<h:form>
<p:dataTable var="form" value="#{myBean.formList}">
<p:column>
<p:commandButton id="selectProduct"
action="#{myBean.setCurrentForm(form)}"
update="selectProductForm" oncomplete="selectProductDlg.show()"
image="ui-icon-">
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
<p:dialog>
<h:form>
<p:commandButton action="#{myBean.setSelected}"
update="main_form"
oncomplete="if(#{myBean.errorText == 'SUCCESS'}){ selectProductDlg.hide();}"
value="Sec">
</p:commandButton>
</h:form>
</p:dialog>
If you have a cancel button in the dialog, you need to let its action method set it to null
.
There's no need to fiddle around with raw HTTP request parameters in POST requests. The <f:param>
should as much as possible be used in GET requests only (e.g. <h:link>
, <h:button>
, etc).
这篇关于将参数传递给同一页面中的对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!