Previous | Next
WireHose Developers Guide

Writing the code

Next, you'll add the code that makes the signup page work.

  1. First, add this code to so the signup page knows which tag was selected in the tag driller page:
    private WHTag _tag;
    public void setTag(WHTag value) {
        _tag = value;
    public WHTag tag() {
        return _tag;
  2. SignupPage will need to sanity check user input. The createAccount method will use an errorMsg method to return error messages to the user:
    public WOActionResults errorMsg(String msg) {
        message = helper().stringInComponent(this, msg);
        password = "";
        passwordAgain = "";
        return context().page();
  3. Add these lines to SignupPage.strings:
    missingField = "Please enter all fields";
    passwordMismatch = "Your password did not match";
    reservedID = "Sorry, that login is reserved";
  4. Part of the sanity checking is to verify that the user hasn't entered a login that was already used in the database. Add this method to
    private NSArray fetchMatchingUsers() {
        EOQualifier q = new EOKeyValueQualifier(
          "login", EOQualifier.QualifierOperatorEqual, login);
        EOFetchSpecification fs = 
          new EOFetchSpecification(WHApplicationHelper.userEntityName(), q, null, true, true, null);
        return session().defaultEditingContext().objectsWithFetchSpecification(fs);
  5. And finally, the createAccount method itself:
    public WOActionResults createAccount() {
        // sanity check user input
        if (login == null || password == null || passwordAgain == null || 
             "".equals(login) || "".equals(password) || "".equals(passwordAgain)) {
            return errorMsg("missingField");
        // make sure passwords match
        if (!password.equals(passwordAgain)) {
            return errorMsg("passwordMismatch");
        // make sure login wasn't already used
        NSArray users = fetchMatchingUsers();
        if (users.count() != 0) {
            return errorMsg("reservedID");
        } else {
            // never know what the current user entity might be
            WHUser user = (WHUser)WHEnterpriseObject.createAndInsertInstance(
            user.setDateLastLogin(new NSTimestamp());
            // replace the guest user for this session
            WHTagDrillerPage nextPage = 
            WOActionResults response = nextPage.addTag();
            // set a login cookie if the user asked for it
            if (shouldSaveCookie) {
                return helper().addLoginCookieToResponse(response.generateResponse());
            } else {
                return response;
  6. Build the application, launch it, and open this URL in your browser:
  7. Browse through the content, and when you get to an interesting category, click the "Add this to my page" button and create a new account.

  8. After creating your account, you'll be returned to the WHEditObjectPage, where you can adjust settings on the newly-created channel.

    Note: Several WireHose components, including the WHEditFetcher shown here, have a binding called hideDetails. If this binding resolves to true, then WHEditFetcher will show an abbreviated version of itself. See the NewsDemo sample application for an example which allows the user to control this with a pair of hide details/show details controls.

Previous | Next