简体   繁体   English

如何从另一个复合组件更新复合组件表单?

[英]How to update a composite component form from another composite component?

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. 更清楚地说,我有一个主要形式,其中包含2个不同的复合组件,让我们调用include1和include2。 The page I want to update is the include2 being update after a search from a include1. 我要更新的页面是在从include1搜索之后正在更新的include2。

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>

Now, in include1 I have a button that tries to update the form inside include2 现在,在include1中,我有一个按钮试图更新include2内的表单

update="include2Form"

and in the include2 I have 在include2中,我有

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

When I try to load the page I always get an Error 500 saying that the "include2Form" has not been found! 当我尝试加载页面时,总是会收到错误500消息,提示未找到“ include2Form”!

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... 在来到这里之前,我尝试了一些研究,但没有任何帮助,我试图将表格更改为div,尝试通过参数,面板,带有prependId = false的表格传递ID ...

Using fireBug I found out that JSF or Primefaces is adding an random String to my form/components ID...as 使用fireBug,我发现JSF或Primefaces正在向我的表单/组件ID中添加一个随机String ... 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. 我认为这是我遇到问题的原因,并且我正在寻找解决方法。

Could anyone help me please??? 谁能帮我吗???

First of all, the additional string in your ID directly comes frome JSF, unrelated to PrimeFaces, because the Composite Component itself is a UINamingContainer . 首先,ID中的附加字符串直接来自JSF,与PrimeFaces无关,因为Composite Component本身是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. 这是预期的行为,甚至是必要的,因为当在同一视图中多次使用同一CC时,否则最终将导致重复的ID冲突。

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.. 为了提高可重用性,只需摆脱这种形式并使用processpartialSubmit ,也许使用f:subView等。

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. 组件外部可能是一个指标,表明复合组件不是满足您要求的完美方法。

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属性将要更新的内容的ID传递给CC,让CC不在乎要更新的内容和位置

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM