Friday, January 21, 2005

Tapestry persistence test code

--Begin snippet for Tester.java--


/*
* Created on Jan 21, 2005 by BCS and RCR
*
*/


import org.apache.tapestry.html.BasePage;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.form.IPropertySelectionModel;
import org.apache.tapestry.form.StringPropertySelectionModel;

public abstract class Tester extends BasePage {

private IPropertySelectionModel DROP_DOWN2_MODEL =
new StringPropertySelectionModel(new String[] { "1","2" });

public abstract void setHiddenBoolean(Boolean newVal);
public abstract void setCounter(Integer newVal);
public abstract Integer getCounter();


public void doSubmit(IRequestCycle cycle){
Integer temp = getCounter();
int newInt =0;
if(temp!=null){
newInt = temp.intValue()+1;
}
setCounter(new Integer(newInt));
if (getCounter().intValue()==5){
setHiddenBoolean(Boolean.valueOf("true"));
}
}

public void doCancel(IRequestCycle cycle){
cycle.discardPage(getPage().getPageName());
cycle.activate("Home");
}

public void detach(){
super.detach();
}

/**
* @return Returns the DROP_DOWN2_MODEL.
*/
public IPropertySelectionModel getDROP_DOWN2_MODEL() {
return DROP_DOWN2_MODEL;
}
/**
* @param drop_down2_model The DROP_DOWN2_MODEL to set.
*/
public void setDROP_DOWN2_MODEL(IPropertySelectionModel drop_down2_model) {
DROP_DOWN2_MODEL = drop_down2_model;
}
}



--End Tester.java snippet--
--Begin Test.page snippet--



<!-- generated by Spindle, http://spindle.sourceforge.net -->

<page-specification class="Tester">

<description>add a description</description>
<property-specification name="dd1" type="java.lang.Integer" persistent="yes"></property-specification>
<property-specification name="dd2" type="java.lang.String" persistent="yes"></property-specification>
<property-specification name="dd3" type="java.lang.Character" persistent="yes"></property-specification>
<property-specification name="input1" type="java.lang.String" persistent="yes"></property-specification>
<property-specification name="hiddenBoolean" type="java.lang.Boolean" persistent="yes" value="false"></property-specification>
<property-specification name="counter" type="java.lang.Integer" persistent="yes"></property-specification>
</page-specification>

--End Test.page snippet--
--Begin Test.html snippet--

<span jwcid="@Shell" title="test this">
<span jwcid="@Body">
<span jwcid="@Form">
<span jwcid="@PropertySelection" model="ognl:DROP_DOWN2_MODEL" required="true" submitonchange="false" value="ognl:dd2"/>
<span jwcid="@Hidden" name="hiddenVal" value="ognl:hiddenBoolean"/>
<span jwcid="@TextField" name="inp" value="ognl:input1"/>
<span jwcid="@Insert" value="ognl:counter"/>
here is the hidden value: <span jwcid="@Insert" value="ognl:hiddenBoolean"/>
<span jwcid="@LinkSubmit" listener="ognl:listeners.doSubmit">submit</span>
<span jwcid="@LinkSubmit" listener="ognl:listeners.doCancel">cancel</span>
</span>
</span>
</span>

--End Test.html snippet--

No comments: