从JSF2 / Facelets的子视图内通过selectOneMenu用于更新文本组件 [英] Updating text component via selectOneMenu from inside a JSF2/Facelets subview

查看:108
本文介绍了从JSF2 / Facelets的子视图内通过selectOneMenu用于更新文本组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Facelets的子视图名为 basedata-cpanel.xhtml ,它获取它的参数通过&LT通过; UI :参数> S:

I have a Facelets subview called basedata-cpanel.xhtml, which gets its parameters passed via <ui:param>s:

<ui:define name="content-top">
  <h:form>
    <ui:include src="/subviews/basedata-cpanel.xhtml">
      <ui:param name="customerId"   value="#{pqHome.pq.customer.id}" />
      <ui:param name="customerName" value="#{pqHome.pq.customer.name}" />
      <ui:param name="customers"    value="#{organizationManager.allCustomers}" />        
    <ui:include />
  </h:form>
</ui:define>

在子视图中,我只是希望下面的小组,以显示当前选择的客户名称(该面板是新建和更新面板/页)。我需要一个AJAX请求这一点。

In the subview, I simply want a panel below to show the currently selected customer name (the panel is for NEW and UPDATE panels/pages). I need an AJAX request for this.

code /subviews/basedata-cpanel.xhtml

      <h:selectOneMenu value="#{customerId}" id="customer-select">
        <f:selectItems value="#{customers}"
                       var="customer"
                       itemValue="#{customer.id}"
                       itemLabel="#{customer.name}" />
        <f:ajax render="customer-name" />
      </h:selectOneMenu>
      <h:outputText value="#{customerName}" id="customer-name" />

我把&LT; F:AJAX渲染=用户名/&GT; 进入选择,但我们将outputText不更新。我真的不期望它,但...

I put the <f:ajax render="customer-name" /> into the select, but the outputText isn't updated. I didn't really expect it to, but...

什么我需要做的就是它的工作?

由于Facelets的子视图仍然有,因为他们通过相同的参数,我如何才能在新?什么是最好的做法呢?

As the Facelets subview still has the same parameters as they were passed, how do I get "new ones" in? What's the best practice for this?

PS:pqHome是 @ViewScoped

PS: pqHome is a @ViewScoped bean

推荐答案

您下拉只更改了客户,而不是客户名称的标识。更,它不会改变整个客户实体在所有。它只是改变了现有客户的ID。这是不好的。

Your dropdown only changes the ID of the customer, not the customer name. Even more, it does not change the whole customer entity at all. It only changes the ID of an existing customer. This is not good.

您需要更改code让它设置的只有它的ID在整个客户来代替。例如,

You need to change the code to let it set the whole customer instead of only its ID. E.g.

<ui:include src="/subviews/basedata-cpanel.xhtml">
    <ui:param name="customer" value="#{pqHome.pq.customer}" />
    <ui:param name="customers" value="#{organizationManager.allCustomers}" />        
</ui:include>

<h:selectOneMenu value="#{customer}" id="customer-select" converter="customerConverter">
    <f:selectItems value="#{customers}" var="c" itemValue="#{c}" itemLabel="#{c.name}" />
    <f:ajax render="customer-name" />
</h:selectOneMenu>
<h:outputText value="#{customer.name}" id="customer-name" />

不要忘记创建一个转换哪些客户ID和客户对象,并用它在两者之间转换在&LT; H:selectOneMenu用于&GT;

Don't forget to create a Converter which converts between customer ID and the Customer object and use it in the <h:selectOneMenu>.

这篇关于从JSF2 / Facelets的子视图内通过selectOneMenu用于更新文本组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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