示例#1
0
  @Override
  protected void onInitialize() {
    super.onInitialize();

    Game game = getModelObject();

    // Link
    final BookmarkablePageLink<CsldBasePage> gameLinkContent =
        new BookmarkablePageLink<CsldBasePage>(
            "gameLink", GameDetail.class, GameDetail.paramsForGame(game));
    add(gameLinkContent);

    // Rating
    gameLinkContent.add(new GameRatingBoxPanel("gameRating", getModel()));

    // Link && name
    final Label gameName = new Label("gameName", game.getName());
    gameLinkContent.add(gameName);

    // Number of players
    gameLinkContent.add(new Label("players", game.getPlayers()));

    // Comments
    gameLinkContent.add(new Label("comments", game.getAmountOfComments()));

    // Ratings
    gameLinkContent.add(new Label("ratings", game.getAmountOfRatings()));
  }
  @Override
  protected void onInitialize() {
    super.onInitialize();
    News pieceOfNews = getModelObject();
    if (pieceOfNews == null) {
      pieceOfNews = new News();
    }

    /* Add Form to add News */
    final ValidatableForm<News> createOrUpdateNews =
        new ValidatableForm<News>("addNews", new CompoundPropertyModel<News>(pieceOfNews));
    createOrUpdateNews.setOutputMarkupId(true);
    add(createOrUpdateNews);

    /* Add editor to decide text of the piece of News. */
    WebMarkupContainer descriptionWrapper = new WebMarkupContainer("newsWrapper");
    createOrUpdateNews.add(descriptionWrapper);
    TextArea description = (TextArea) new TextArea<String>("text").setRequired(true);
    description.add(new CSLDTinyMceBehavior());
    descriptionWrapper.add(description);
    descriptionWrapper.add(
        new CsldFeedbackMessageLabel(
            "newsFeedback", description, descriptionWrapper, "form.news.textHint"));

    List<String> availableLanguages = new ArrayList<String>(availableLocaleNames());
    final DropDownChoice<String> lang = new DropDownChoice<String>("lang", availableLanguages);
    createOrUpdateNews.add(lang);
    createOrUpdateNews.add(new CsldFeedbackMessageLabel("langFeedback", lang, null));

    /* Add button to create news piece. */
    createOrUpdateNews
        .add(
            new AjaxButton("submit") {
              @Override
              protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                super.onSubmit(target, form);

                if (createOrUpdateNews.isValid()) {
                  News pieceOfNews = createOrUpdateNews.getModelObject();
                  if (news.saveOrUpdate(pieceOfNews)) {
                    onCsldAction(target, form);
                  }
                }
              }

              @Override
              protected void onError(AjaxRequestTarget target, Form<?> form) {
                super.onError(target, form);

                target.add(form);
              }
            })
        .add(new TinyMceAjaxSubmitModifier());

    if (isSignedIn()) {
      add(new JSPingBehavior());
    }
  }