在JSF中支持bean String []访问 [英] Backing bean String[] access in JSF

查看:106
本文介绍了在JSF中支持bean String []访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,很抱歉,如果您参与了我最近的问题.由于这不是讨论论坛,而且意见有限,所以我最后的希望是用实际代码提出一个具体问题,以期能以某种方式达到问题的深处.

First, apologies if you've been involved with my recent questions. As this isn't a discussion forum, and comments are limited, my last hope is to ask a specific question with actual code in the hope that somehow I can reach the bottom of my problem.

好.我有一个名为PrismBacking的后备豆,它具有以下相关代码:

OK. I've a backing bean called PrismBacking with this pertinent code:

     public class PrismBacking {
 private ArrayList dataList;

    public ArrayList<String> getFeedDataList() {
  XMLHandler xmlh = new XMLHandler();
  dataList = new ArrayList();
  Document doc = xmlh.getDoc(map); // catches removed

  // get all the feedNames from the doc, and the feedIds
  String[] FeedIds = xmlh.getXMLList("//feed/feed_id/text()");

  for (String feedId : FeedIds) {
   TaskListData tld = new TaskListData();
   tld.setFeedId(feedId);

   String feedName = xmlh.getValue("//feed[feed_id='" + feedId +"']" +"/feedname/text()");
   tld.setFeedName(feedName);

   String[] FTQs = xmlh.getList("//feed[feed_id='" + feedId +"']" +"/ftq/ftq_id/text()");
   for (String ftqId : FTQs) {
    logger.info("FTQ: " + ftqId);
   }
   tld.setFTQs(FTQs);

   dataList.add(tld);
  }

  setFeedDataListSize(dataList.size());
  return dataList;
 }

在TaskListData类中,

In class TaskListData,

    public class TaskListData {
 private String feedId;
 private String feedName;
 private String[] FTQar;

 public String getFeedId() {  
  return feedId;  
 }  

 public void setFeedId(String f) {  
  feedId = f;  
 } 

 public String getFeedName() {  
  return feedName;  
 }  

 public void setFeedName(String fn) {  
  feedName = fn;  
 } 

 public String[] getFTQs() {  
  return FTQar;  
 }  

 public void setFTQs(String[] ftqs) {  
  FTQar = ftqs;
 }  
}

所以我已经完成了getters和setters的设置,并且XPath都很好.在我的index.jsp jsf文件中:

so I've got my getters and setters setup, and my XPath all good. In my index.jsp jsf file:

    <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <!-- RichFaces tag library declaration -->
    <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
    <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
    <!-- JSTL XML lib declaration -->
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <!-- error redirect -->

    <f:view>
     <rich:page pageTitle="mypage" markupType="xhtml">
      <h:dataTable id="dt1" value="#{PrismBacking.feedDataList}" var="item"
       border="10" cellpadding="5" cellspacing="3" first="0"
       rows="#{PrismBacking.feedDataListSize}" width="50%" dir="LTR"
       frame="hsides" rules="all"
       summary="This is a JSF code to create dataTable.">

   <f:facet name="header">
    <h:outputText value="This is 'dataTable' demo" />
   </f:facet>

   <h:column>
    <f:facet name="header">
     <h:outputText value="id" />
    </f:facet>
    <h:outputText value="|#{item.feedId}|"></h:outputText>
   </h:column>

   <h:column>
    <f:facet name="header">
     <h:outputText value="name" />
    </f:facet>
    <h:outputText value="|#{item.feedName}|"></h:outputText>
   </h:column>

   <h:column>
    <f:facet name="header">
     <h:outputText value="ftqs" />
    </f:facet>
    <c:forEach items="#{item.FTQs}" var="jef">
     <h:outputText value="|#{jef}|" />
     <br />
    </c:forEach>

   </h:column>

  </h:dataTable>
  <h:outputText value="" />
 </rich:page>
</f:view>

好的,这可以正常编译,并且可以正常运行而不会出现错误.我在PrismBacking的logger.info行中看到了

OK, this compiles fine, and runs ok without error. I see from the logger.info line in PrismBacking:

|STDOUT| 2010-01-28 00:02:48,960 | INFO  | [http-8989-1]: feedId: 1 | feedSwitch: on | feedName: FEED1
|STDOUT| 2010-01-28 00:02:48,991 | INFO  | [http-8989-1]: FTQ: 1
|STDOUT| 2010-01-28 00:02:48,991 | INFO  | [http-8989-1]: feedId: 2 | feedSwitch: on | feedName: FEED2
|STDOUT| 2010-01-28 00:02:48,991 | INFO  | [http-8989-1]: FTQ: 1
|STDOUT| 2010-01-28 00:02:48,991 | INFO  | [http-8989-1]: feedId: 3 | feedSwitch: on | feedName: FEED3
|STDOUT| 2010-01-28 00:02:48,991 | INFO  | [http-8989-1]: FTQ: 1
|STDOUT| 2010-01-28 00:02:49,007 | INFO  | [http-8989-1]: feedId: 4 | feedSwitch: on | feedName: FEED4
|STDOUT| 2010-01-28 00:02:49,007 | INFO  | [http-8989-1]: feedId: 5 | feedSwitch: off | feedName: FEED5
|STDOUT| 2010-01-28 00:02:49,023 | INFO  | [http-8989-1]: feedId: 6 | feedSwitch: on | feedName: FEED6
|STDOUT| 2010-01-28 00:02:49,038 | INFO  | [http-8989-1]: feedId: 7 | feedSwitch: on | feedName: FEED7

所以我知道我的dataTable中有FEED 1-3,其FTQ编号应为1.在呈现页面时,我看到了

so I know I have FEEDs 1-3 which should have the FTQ number 1 in, in my dataTable. On rendering the page, I see this

This is 'dataTable' demo

id name ftqs
|1| |FEED1| ||
|2| |FEED2| ||
|3| |FEED3| ||
|4| |FEED4| ||
|5| |FEED5| ||
|6| |FEED6| ||
|7| |FEED7| || 

我不喜欢胡闹.我也不能发表冗长的文章,但是我在一个没人知道这些技术的环境中工作,而堆栈溢出是我发现提出这些问题的唯一也是最好的地方.由于机智,我希望您不要介意多余的帖子.

I don't like grovelling. I can't bear long posts either, but I'm working in an environment where I've nobody who knows about these technologies and stack overflow is the only and best place I've found to ask these questions. As I'm at my wits end, I hope you don't mind the extra post length.

那么我的问题是,上述代码需要更改什么才能使TaskListData String []成员FTQar可以访问?在此阶段,我会坦白地说,我希望有人可以发布我的代码的修改后的片段,向我显示我出了问题的地方.如果由我决定,那么正确的答案会给您比平常多的分数.

My question then is what from the above code needs to change to get the TaskListData String[] member FTQar accessible? At this stage, I'll be honest and say I'm hoping someone could post a modified snippet of my code showing me where I've gone wrong. If it were up to me, you'd get extra points than normal for the right answer.

的确非常感谢 标记

推荐答案

首先,JSTL和JSF不能像您期望的编码顺序那样无缝地同步同步工作.更重要的是,JSTL首先在 之前运行.实际上,JSTL首先从上到下处理整个页面,然后将生成的输出(因此,没有传递给任何JSTL)标记,但其生成的输出)传递到JSF,JSF依次再次从上到下处理整个页面.

First of all, JSTL and JSF doesn't work seamlessly together in sync as you would expect from the order in the coding. It's more so that JSTL runs first before JSF kicks in. Virtually, JSTL processes the entire page from top to bottom first and then hands the generated output (thus, without any JSTL tags, but with its generated output) over to JSF which in turn processes the entire page from top to bottom again.

由于h:dataTable尚未生成任何行,因此JSTL运行时,您不会在h:column内部的c:forEach中看到任何内容.

As the h:dataTable hasn't generated any rows yet at the moment the JSTL runs, you aren't going to see anything from the c:forEach inside a h:column.

而是使用JSF提供的迭代组件,例如Tomahawk的t:dataTable或RichFaces的a4j:repeat或Facelets的ui:repeat,甚至是嵌套的h:dataTable.

Rather use the JSF-supplied iterating components, such as Tomahawk's t:dataTable, or RichFaces' a4j:repeat, or Facelets' ui:repeat, or maybe even a nested h:dataTable.

这篇关于在JSF中支持bean String []访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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