2

我有一个网页,其中包含 jstl forEach 循环内的面板列表。所有面板在加载页面时都会折叠。在展开每个面板时,我将折叠状态保存到 bean 以便以后参考。我从 ap:commandLink 更新面板,但面板显示为基于先前的 index 展开,而不是 bean 值。我的要求是面板的折叠属性应该根据之前设置的 bean 值更新,目前面板正在根据之前扩展面板的索引进行扩展,而不是根据它的 bean 属性值。

只需看一下代码片段。

<h:form id="form">
        <c:forEach items="#{items}" var="name">
            <p:panel header="#{name}" toggleable="true"
                toggleTitle="#{bean.toggleStatus.get(name)}"
                collapsed="#{bean.toggleStatus.get(name)}" toggleSpeed="500"
                id="panel#{name}" widgetVar="panel#{name}">
                <h:outputText value="#{name}"/>
            </p:panel>
        </c:forEach>
        <p:commandLink id="Search" style="margin-left :5px;"
            action="#{bean.search}" update="form" ajax="true"/>
    </h:form>

当我单击我的 firstview 中的按钮时,我想通过 segue 将 json 数据直接传递给我的 secondview

我从 url 获取 json 数据:http ://api.kivaws.org/v1/loans/search.json?status=fundraising我在我的屏幕上得到它,但我必须将数据直接发送到我的secondviewcontrollerthroughsegue无需firstviewcontroller通过单击firstviewcontroller.

#import "ViewController.h"

#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) 
#define kLatestKivaLoansURL [NSURL URLWithString:@"http://api.kivaws.org/v1/loans/search.json?status=fundraising"] 

@implementation ViewController
@synthesize textinput;

- (IBAction)loadData {
        dispatch_async(kBgQueue, ^{
           NSData* data = [NSData dataWithContentsOfURL:
                                kLatestKivaLoansURL];
           [self performSelectorOnMainThread:@selector(fetchedData:)
                                       withObject:data waitUntilDone:YES];
        });
 }

- (void)fetchedData:(NSData *)responseData {

    NSError* error;
    NSDictionary* json = [NSJSONSerialization
                          JSONObjectWithData:responseData //1
                          options:kNilOptions
                          error:&error];

    NSArray* latestLoans = [json objectForKey:@"loans"]; //2

    NSLog(@"loans: %@", latestLoans); //3
    [textinput resignFirstResponder];

   if ([textinput.text isEqualToString:@""])
   {
         display.text = @"Enter The Value";

   }else{
        if ([textinput.text isEqualToString:@"loans"])
          {

             NSDictionary* loans = [latestLoans objectAtIndex:0];


             NSDictionary* info = [NSDictionary dictionaryWithObjectsAndKeys:
                 lblWHO.text = [loans objectForKey:@"name" ],
                 lblActivtiy.text =  [loans objectForKey:@"activity"],nil];
                  lblLoan.text = [(NSDictionary*)[loans objectForKey:@"location"]
                   objectForKey:@"country"], nil;


             NSData* jsonData = [NSJSONSerialization dataWithJSONObject:info
                                               options:NSJSONWritingPrettyPrinted error:&error];
          }   
      }
 }

我将绑定在 my 中的数据传递firstviewcontrollerseguesecondviewcontroller如下所示:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"ShowCustDetail"])
    {
          self.showact = Activity.text;
          self.showname = Name1.text;
          self.showcount = Country.text;

        CustViewController *cv = [segue destinationViewController];
     cv.showact = self.showact;
     cv.showname = self.showname;
     cv.showcount = self.showcount;
    }
}  

但是我必须将这些数据直接绑定到我的目标视图控制器中,而不是在我的第一个视图控制器中

  #import "CustViewController.h"

  @interface CustViewController ()
  @end

  @implementation CustViewController
  @synthesize Name1;
  @synthesize showname;
  @synthesize showact;
  @synthesize showcount;
  @synthesize Name2;
  @synthesize Name3;

  - (void)viewDidLoad
   {
     [super viewDidLoad];

      Name1.text = self.showact;
      Name2.text = self.showname;
      Name3.text = self.showcount;
      Name4.text = self.showstat;
      Name5.text = self.showsect;

   }



   @end

感谢您将我与你们联系起来。如果我得到解决方案很有用。

4

1 回答 1

0

from your code, it seems that #{bean.toggleStatus.get(name)} returns a String object.

The <p:panel collapsed=""> requires a boolean value.

You have to post your backing bean code, to see the return value of that method.

于 2012-12-10T14:43:46.257 回答