Hi,

You may also use #toLong(defaultValue) which does not throws exception and
return a default value in case of conversion error (or value not supplied).

Regards,
Sebastien.

On Thu, Sep 20, 2012 at 9:22 PM, Francois Meillet <
[email protected]> wrote:

> I don't see where you set the parameters...
> parameters.set("id", x);
>
> It has to be done somewhere.
> If parameters.get("id") return null, as null can't be converted to long,
> you get the exception.
>
> François
>
>
> Le 20 sept. 2012 à 21:16, Stephen Walsh <[email protected]> a
> écrit :
>
> > Thanks for responding.  That would make sense.  Is there any way to
> > identify when or when it couldn't be converted?
> >
> > Does the array that I provided cause this issue?  In my Post class I
> > followed the example code and have the class assigning ids as long.
> >
> > _______________________________________
> > Stephen Walsh | http://connectwithawalsh.com
> >
> >
> >
> > On Thu, Sep 20, 2012 at 12:55 PM, Francois Meillet <
> > [email protected]> wrote:
> >
> >> parameters.get("id").toLong() throws this exception when id can't be
> >> converted to long.
> >>
> >> François
> >>
> >>
> >> Le 20 sept. 2012 à 19:06, Stephen Walsh <[email protected]>
> a
> >> écrit :
> >>
> >>> I am new to Wicket and Java, so forgive any ignorance or lack of
> >> information.
> >>>
> >>> I am modeling a blog type application after the Wicket Examples Library
> >> application and have not had any luck passing the post id to the details
> >> page.  I'm not using the user portion at this point because I'll be
> doing a
> >> role based authorization later.
> >>>
> >>> The blog page populates the array that it is given and provides a link
> >> to the detail page, but this is when the exception is thrown.  Any
> thoughts?
> >>>
> >>> Thanks!
> >>>
> >>> public abstract class BasePage extends WebPage {
> >>>      /**
> >>>       *
> >>>       */
> >>>      private static final long serialVersionUID = 1L;
> >>>
> >>>
> >>>      private String pageTitle = "(no title)";
> >>>
> >>>      /**
> >>>       *
> >>>       * @return pageTitle
> >>>       */
> >>>      public final String getPageTitle() {
> >>>
> >>>              return pageTitle;
> >>>      }
> >>>
> >>>      /**
> >>>       *
> >>>       * @param title
> >>>       */
> >>>      public final void setPageTitle(String title) {
> >>>
> >>>              pageTitle = title;
> >>>      }
> >>>
> >>>      public BasePage() {
> >>>
> >>>              this(new PageParameters());
> >>>      }
> >>>
> >>>      /**
> >>>       *
> >>>       * @param parameters
> >>>       */
> >>>      public BasePage(final PageParameters parameters) {
> >>>
> >>>              super(parameters);
> >>>
> >>>              add(new Label("title", new PropertyModel<String>(this,
> >> "pageTitle")));
> >>>              add(new BookmarkablePageLink("logo", Index.class));
> >>>              add(new BookmarkablePageLink("home", Index.class));
> >>>              add(new BookmarkablePageLink("news", Blog.class));
> >>>              add(new BookmarkablePageLink("contact", ContactUs.class));
> >>>              add(new BookmarkablePageLink("about", About.class));
> >>>              add(new FooterPanel("social"));
> >>>      }
> >>>
> >>>      /**
> >>>       * Construct
> >>>       *
> >>>       * @param model
> >>>       */
> >>>      public BasePage(IModel<?> model) {
> >>>
> >>>              super(model);
> >>>      }
> >>>
> >>> public class Blog extends BasePage {
> >>>
> >>>      /**
> >>>       * Constructor
> >>>       *
> >>>       * @param params
> >>>       */
> >>>      public Blog(final PageParameters paramaters) {
> >>>
> >>>              setPageTitle("News");
> >>>
> >>>              //Add a list of blogPosts
> >>>              final PageableListView<Post> listView;
> >>>              add(listView = new PageableListView<Post>("blogPosts", new
> >> PropertyModel<List<Post>>(this, "blogPosts"), 5) {
> >>>
> >>>                      @Override
> >>>                      public void populateItem(final ListItem<Post>
> >> listItem) {
> >>>                              final Post blogPost =
> >> listItem.getModelObject();
> >>>                              listItem.add(BlogDetails.link("details",
> >> blogPost, getLocalizer().getString("noPostTitle", this)));
> >>>                              listItem.add(new Label("text", new
> >> Model<Post>(blogPost)));
> >>>                              listItem.add(new Label("tags", new
> >> Model<Post>(blogPost)));
> >>>                              listItem.add(removeLink("remove",
> >> listItem));
> >>>                              listItem.add(EditBlogPost.link("edit",
> >> blogPost.getId()));
> >>>                      }
> >>>              });
> >>>              add(new PagingNavigator("navigator", listView));
> >>>      }
> >>>
> >>>      public List<Post> getBlogPosts() {
> >>>              final List<Post> blogPosts = new ArrayList<Post>();
> >>>
> >>>              blogPosts.add(new Post("Post1", "text1", "tag1, tag2,
> >> tag3"));
> >>>              blogPosts.add(new Post("Post2", "text2", "tag1, tag2,
> >> tag3"));
> >>>              blogPosts.add(new Post("Post3", "text3", "tag1, tag2,
> >> tag3"));
> >>>              blogPosts.add(new Post("Post4", "text4", "tag1, tag2,
> >> tag3"));
> >>>              blogPosts.add(new Post("Post5", "text5", "tag1, tag2,
> >> tag3"));
> >>>              blogPosts.add(new Post("Post6", "text6", "tag1, tag2,
> >> tag3"));
> >>>              blogPosts.add(new Post("Post7", "text7", "tag1, tag2,
> >> tag3"));
> >>>              blogPosts.add(new Post("Post8", "text8", "tag1, tag2,
> >> tag3"));
> >>>              blogPosts.add(new Post("Post9", "text9", "tag1, tag2,
> >> tag3"));
> >>>              blogPosts.add(new Post("Post10", "text10", "tag1, tag2,
> >> tag3"));
> >>>
> >>>              return blogPosts;
> >>>
> >>>      }
> >>> }
> >>>
> >>> public class BlogDetails extends BasePage {
> >>>
> >>>      /**
> >>>       *
> >>>       * @param parameters
> >>>       *                      PageParameters
> >>>       * @throws StringValueConversionException
> >>>       */
> >>>      public BlogDetails(final PageParameters parameters) throws
> >> StringValueConversionException {
> >>>              this(Post.get(parameters.get("id").toLong()));
> >>>      }
> >>>
> >>>      public BlogDetails(final Post blogPost) {
> >>>              add(new Label("title", blogPost.getTitle()));
> >>>              add(new Label("text", blogPost.getText()));
> >>>              add(new Label("tags", blogPost.getTags()));
> >>>              add(EditBlogPost.link("edit", blogPost.getId()));
> >>>      }
> >>>
> >>>      /**
> >>>       * Creates an external page link
> >>>       *
> >>>       * @param name
> >>>       *            The name of the link component to create
> >>>       * @param post
> >>>       *            The post to link to
> >>>       * @param noPostTitle
> >>>       *            The title to show if post is null
> >>>       * @return The external page link
> >>>       */
> >>>      public static BookmarkablePageLink<Void> link(final String name,
> >> final Post blogPost, final String noPostTitle) {
> >>>
> >>>              final BookmarkablePageLink<Void> link = new
> >> BookmarkablePageLink<Void>(name, BlogDetails.class);
> >>>
> >>>              if (blogPost != null) {
> >>>
> >>>                      link.getPageParameters().add("id",
> >> blogPost.getId());
> >>>                      link.add(new Label("title", new
> >> Model<Post>(blogPost)));
> >>>              }
> >>>              else {
> >>>
> >>>                      link.add(new Label("title", noPostTitle));
> >>>                      link.setEnabled(false);
> >>>              }
> >>>
> >>>              return link;
> >>>      }
> >>> }
> >>>
> >>>
> >>> ____________________________________
> >>> Stephen Walsh | http://connectwithawalsh.com
> >>>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [email protected]
> >> For additional commands, e-mail: [email protected]
> >>
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to