Register.java:
package com.packtpub.celebrity.collector.pages;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.SelectModel;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.util.EnumSelectModel;
import org.slf4j.Logger;

import com.packtpub.celebrity.collector.model.Country;
import com.packtpub.celebrity.collector.model.Gender;

public class Register {
    
    @Inject
    private Logger logger;
    
    @Persist
    private String userName;
    
    @Persist
    private String password;
    
    private String password2;
    
    @Persist
    private Gender gender;
    
    @Persist
    private boolean subscribe;
    
    private boolean unsubscribe;
    
    @Persist
    private String email;
    
    @Inject
    private Messages messages;
    
    @Persist
    
    private Country country;
        
    public SelectModel getCountries() {
        return new EnumSelectModel(Country.class, messages);
    }
    
    @OnEvent(component="submitButton", value=EventConstants.SELECTED)
    void onSubmitButton() { 
        logger.debug("Submit Button was Pressed!");
        if(unsubscribe) {
            subscribe = false;
        }
    }
    
    @OnEvent(component="resetButton", value=EventConstants.SELECTED)
    void onResetButton() {
        userName = null;
        password = null;
        password2 = null;
        email = null;
        gender = null;
        subscribe = false;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPassword2() {
        return password2;
    }

    public void setPassword2(String password2) {
        this.password2 = password2;
    }

    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }
    
    public Gender getMale() {
        return Gender.MALE;
    }
    
    public Gender getFemale() {
        return Gender.FEMALE;
    }
    
    public boolean isSubscribe() {
        return subscribe;
    }
    
    public void setSubscribe(boolean subscribe) {
        this.subscribe = subscribe;
    }

    public void setUnsubscribe(boolean unsubscribe) {
        this.unsubscribe = unsubscribe;
    }

    public boolean isUnsubscribe() {
        return unsubscribe;
    }
    
    public boolean isPasswordNotSubmitted() {
        return userName == null;
    }

    public void setCountry(Country country) {
        this.country = country;
    }

    public Country getCountry() {
        return country;
    }
}

Register.tml:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml";
      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
      xmlns:p="tapestry:parameter"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
     
xsi:schemaLocation="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd
http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
      t:type="layout" title="Registration">

    <p>Registration</p>
    <t:form t:id="registrationForm">
        <table>
            <tr>
                <td><label t:type="label" t:for="userName"></label>:</td>
                <td><input type="text" t:type="textfield" t:id="userName"
t:value="userName"/></td>
            </tr>
            <t:if t:test="passwordNotSubmitted">
                    <tr>
                        <td><label t:type="label" 
t:for="password"></label>:</td>
                        <td><input type="text" t:type="passwordfield"
t:id="password" t:value="password"/></td>
                    </tr>
                    <tr>
                        <td><label t:type="label" 
t:for="password2"></label>:</td>
                        <td><input type="text" t:type="passwordfield"
t:id="password2" t:value="password2"/></td>
                    </tr>
            </t:if>
            <tr>
                <td>Gender:</td>
                <td>
                    <t:radiogroup t:value="gender">
                        <input type="radio" t:type="radio" t:value="male"/>
Male
                        <input type="radio" t:type="radio"
t:value="female"/> Female
                    </t:radiogroup>
                </td>
            </tr>
            <tr>
                <t:if t:test="subscribe">
                    <td><label t:type="label" t:for="email"></label>:</td>
                    <td>
                        <input type="text" t:type="textfield" t:id="email"
t:value="email"/>
                        <input type="checkbox" t:type="checkbox"
t:value="unsubscribe" onclick="this.form.submit()"/>
                        I don't want to subscribe.
                    </td>
                    <t:parameter t:name="else">
                        <td colspan="2">
                            <input type="checkbox" t:type="checkbox"
t:value="subscribe" onclick="this.form.submit()"/>
                            Check the box to subscribe to our Newsletter.
                        </td>
                    </t:parameter>
                </t:if>
            </tr>
            <tr>
                <td>Country:</td>
                <td>
                    <select t:type="select" t:model="countries"
t:value="countries">
                        <option>Country 1</option>
                        <option>Country 2</option>
                    </select>
                </td>
            </tr>
        </table>
        <t:submit t:id="submitButton" value="Submit"/>
        <input type="submit" t:type="submit" t:id="resetButton"
value="Reset"/>
    </t:form>
    <br/>
     # Back to Index Page 

</html>

Layout.tml:
<!DOCTYPE html [
    <!ENTITY % HTMLlat1 PUBLIC "-//W3C//ENTITIES Latin 1 for XHTML//EN"
"http://www.w3.org/MarkUp/DTD/xhtml-lat1.ent";> %HTMLlat1;
    <!ENTITY % HTMLsymbol PUBLIC "-//W3C//ENTITIES Symbols for XHTML//EN"
"http://www.w3.org/MarkUp/DTD/xhtml-symbol.ent";> %HTMLsymbol;
    <!ENTITY % HTMLspecial PUBLIC "-//W3C//ENTITIES Special for XHTML//EN"
"http://www.w3.org/MarkUp/DTD/xhtml-special.ent";> %HTMLspecial;
]>
<html xmlns="http://www.w3.org/1999/xhtml";
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
        xmlns:p="tapestry:parameter"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        xsi:schemaLocation="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd
http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";>

        <head>
                <meta http-equiv="content-type" content="text/html; 
charset=utf-8" />
                <title>${title}</title>
        </head>
        <body>
                <!-- start header -->
                <div id="header">
                        <div id="logo">
                                <h1>
                                        <t:pagelink page="index">Celebrity 
Collector</t:pagelink>
                                </h1>
                        </div>
                        <div id="menu">
                                <ul>
                                        <li t:type="loop" source="pageNames" 
value="pageName"
                                                class="prop:classForPageName">
                                                <t:pagelink 
page="prop:pageName">${pageName}</t:pagelink>
                                        </li>
                                </ul>
                        </div>
                </div>
                <!-- end header -->
                <!-- start page -->
                <div id="page">
                        <!-- start content -->
                        <div class="title">
                                <h2>${title}</h2>
                        </div>
                        <div class="entry">
                                <t:body />
                        </div>
                        <!-- end content -->
                        <br style="clear: both;" />
                </div>
                <!-- end page -->
                <!-- start footer -->
                <div id="footer">
                        <p class="legal">
                                &copy;2009. All Rights Reserved.
                                &nbsp;&nbsp;&bull;&nbsp;&nbsp;
                                Design by
                                 http://www.freecsstemplates.org/ Free CSS 
Templates 
                                &nbsp;&nbsp;&bull;&nbsp;&nbsp;
                                Icons by
                                 http://famfamfam.com/ FAMFAMFAM 
                                .
                        </p>
                </div>
                <!-- end footer -->
        </body>
</html>

-- 
View this message in context: 
http://www.nabble.com/%40OnEvent-annotated-methods-not-firing-tp24903936p24977231.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to