如何从另一个复合组件更新复合组件表单? [英] How to update a composite component form from another composite component?

查看:79
本文介绍了如何从另一个复合组件更新复合组件表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试更新外部表单时遇到问题.更清楚地说,我有一个主要的表单,其中包含2个不同的复合组件,让我们调用include1和include2.我要更新的页面是在从include1搜索之后正在更新的include2.

I'm having problem trying to update an external form. To be more clear, I have a primary form that includes 2 different composite components, lets call include1 and include2. The page I want to update is the include2 being update after a search from a include1.

这就是包含这两个页面的方式.

this is how the 2 pages are being included.

<ui:define name="include1">
    <ui:param name="mbean" value="#{currentBean}" />
    <libcomp:include1 />
</ui:define>

<ui:define  name="include2">
    <ui:param name="mbean" value="#{currentBean}" />
    <libcomp:include2>
</ui:define>

现在,在include1中,我有一个按钮试图更新include2内的表单

Now, in include1 I have a button that tries to update the form inside include2

update="include2Form"

在我的include2中有

and in the include2 I have

<cc:implementation>
    <h:form 
        id="include2Form">

当我尝试加载页面时,总是会收到错误500消息,提示未找到"include2Form"!

When I try to load the page I always get an Error 500 saying that the "include2Form" has not been found!

我来这里之前尝试了一些研究,但没有帮助我,我试图将表格更改为div,尝试通过参数,面板,带有prependId = false的表格等传递ID ...

I tried some research before coming here but none helped me, I tried to change the form to a div, tried to pass id by parameter, a panel, form with prependId=false etc...

使用fireBug,我发现JSF或Primefaces正在向我的表单/组件ID中添加一个随机字符串...为

Using fireBug I found out that JSF or Primefaces is adding an random String to my form/components ID...as

id ="j_idt99:include2Form:myTable"

id="j_idt99:include2Form:myTable"

我认为这是我遇到问题的原因,我正在努力寻找解决方法.

I think that is the reason of my problem and I'm trying to find a work around.

有人可以帮我吗?

推荐答案

首先,您ID中的其他字符串直接来自JSF,与PrimeFaces无关,因为Composite Component本身是

First of all, the additional string in your ID directly comes frome JSF, unrelated to PrimeFaces, because the Composite Component itself is a UINamingContainer. This is expected behavoir and even necessary, because otherwise you would end up in duplicate ID conflicts, when using the same CC multiple times in the same view.

我认为完全没有复合组件的形式在内部 是不好的设计.要提高可重用性,只需摆脱这种形式,并使用processpartialSubmit,也许是f:subView等.

In my opinion it is bad design to have a form inside a Composite Component at all. To improve reusability just get rid of that form and work with process, partialSubmit, maybe f:subView etc..

此外,您应该重新考虑您的设计.一个复合组件必须更新的点. 外部组件可能是一个指标,表明复合组件不是满足您需求的完美方法.

Beside that you should rethink your design. The point that one Composite Component has to update s.th. outside the component might be an indicator, that a Composite Component is not the perfect approach to cover your requirements.

但是,如果您确实要 更新视图的某些部分之外,只需通过Composite属性将要更新的内容的ID传递给CC并让CC不在乎更新内容和更新地点

However, if you really have to update some parts of your view outside the composite component, just pass the ID of what to update via a composite attribute to your CC and let the CC not care about what and where to update

<composite:interface>
    <composite:attribute name="update" required="true" />
</composite:interface>

这篇关于如何从另一个复合组件更新复合组件表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆