ui:repeat中的Primefaces:radioButton [英] Primefaces :radioButton inside a ui:repeat

查看:96
本文介绍了ui:repeat中的Primefaces:radioButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的xhtml代码:

This is my xhtml code :

 <?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">

  <h:head>
    <title>Custom Radio Test</title>
  </h:head>

  <h:body>

    <h:form id="mF" >

      <p:selectOneRadio id="ITRadioGrp" value="#{testBean.radioSelectedValue}" layout="custom">
        <f:selectItems value="#{testBean.selectItems}" />
      </p:selectOneRadio>

      <h:panelGrid columns="1">

        <ui:repeat id="vBGOF" value="#{testBean.groupOfFlights}" var="aFlight" varStatus="gofIndex">
          <p:radioButton for="ITRadioGrp" itemIndex="#{gofIndex.index}"/> #{aFlight}
        </ui:repeat>

      </h:panelGrid>

    </h:form>

  </h:body>

</html>

这是托管bean:

    package com.modern;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.model.SelectItem;
import java.util.*;

@ManagedBean
@RequestScoped
public class TestBean {

  private String radioSelectedValue;
  private String[] groupOfFlights;
  private List selectItems;

  public TestBean() {
    groupOfFlights = new String[]{"FlightOne", "FlightTwo", "FlightThree"};
  }

  public String[] getGroupOfFlights() {
    return groupOfFlights;
  }

  public void setGroupOfFlights(String[] groupOfFlights) {
    this.groupOfFlights = groupOfFlights;
  }

  public String getRadioSelectedValue() {
    return radioSelectedValue;
  }

  public void setRadioSelectedValue(String radioSelectedValue) {
    this.radioSelectedValue = radioSelectedValue;
  }

  // modified
  public List getSelectItems() {
    try {
      if (selectItems == null || selectItems.isEmpty()) {
        selectItems = new ArrayList();
        for (int g = 0; g < 3; g++) {
          SelectItem option = new SelectItem(g, "flight" + (g + 1)); // value, label
          selectItems.add(option);
        }
      }
    } catch (Exception e) {
      System.out.println(this.getClass().getName() + "] EXCEPTION " + e.toString());
    }
    return selectItems;
  }

  public void setSelectItems(List selectItems) {
    this.selectItems = selectItems;
  }
}

我总是遇到相同的错误:

I always get the same error :

在视图中找不到组件'mF:ITRadioGrp'.

javax.faces.FacesException: Cannot find component 'mF:ITRadioGrp' in view.
    at org.primefaces.component.radiobutton.RadioButtonRenderer.findSelectOneRadio(RadioButtonRenderer.java:144)
    at org.primefaces.component.radiobutton.RadioButtonRenderer.encodeEnd(RadioButtonRenderer.java:35)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1763)
    at com.sun.faces.facelets.component.RepeatRenderer.encodeChildren(RepeatRenderer.java:104)
    at com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:513)
    at com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:974)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
    at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
    at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:401)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

我尝试更改

<p:radioButton for="mF:ITRadioGrp" itemIndex="#{gofIndex.index}"/> #{aFlight}

到(我检查了HTML源代码,删除了p:selectOneRadio中的layout = custom):

to (i checked the HTML source deleting the layout=custom" in p:selectOneRadio) :

  1. mF:ITRadioGrp
  2. ITRadioGrp
  3. mF:ITRadioGrp:0
  4. mF:ITRadioGrp:1 ...

但总是相同的错误! 我在哪里错了??? 谢谢!

but always same error!! where i'm wrong??? Thanks!

推荐答案

使用冒号作为前缀,以便从视图根开始寻址p:selectOneRadio:

Use a colon as prefix in order to address the p:selectOneRadio beginning from the view root:

<p:radioButton for=":mF:ITRadioGrp" itemIndex="#{gofIndex.index}"/>

如果这不起作用,请在浏览器中查看页面的html源,并找到p:selectOneRadio的正确客户端ID.在您的for属性中使用此ID.

If this does not work, look into the html source of your page in browser and find the correct client id for the p:selectOneRadio. Use this id in your for attribute.

这篇关于ui:repeat中的Primefaces:radioButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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