You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by mi...@apache.org on 2005/06/21 08:52:52 UTC
cvs commit: jakarta-tapestry/framework/src/java/org/apache/tapestry Framework.library
mindbridge 2005/06/20 23:52:52
Modified: framework/src/java/org/apache/tapestry Framework.library
Added: framework/src/java/org/apache/tapestry/components Else.jwc
If.jwc ElseBean.java IfBean.java
Log:
Adding the If and Else components
Revision Changes Path
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/components/Else.jwc
Index: Else.jwc
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE component-specification
PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
<!-- generated by Spindle, http://spindle.sourceforge.net -->
<component-specification class="org.mb.tapestry.base.ElseBean" allow-body="yes" allow-informal-parameters="yes">
<description>
Conditionally emulates an element and its attributes and/or includes a block of content
if the condition of the previous If component evaluates to false.
</description>
<parameter name="element" type="java.lang.String" direction="in" default-value="templateTag">
<description>
The element to emulate.
</description>
</parameter>
<parameter name="templateTag" type="java.lang.String" direction="auto" default-value="null">
<description>
The tag with which the component was inserted in its parent template.
This parameter will be bound automatically by the framework.
</description>
</parameter>
</component-specification>
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/components/If.jwc
Index: If.jwc
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE component-specification PUBLIC
"-//Apache Software Foundation//Tapestry Specification 4.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
<component-specification class="org.apache.tapestry.components.IfBean" allow-body="yes" allow-informal-parameters="yes">
<description>
Conditionally emulates an element and its attributes and/or includes a block of content
if a condition is met.
</description>
<parameter name="condition" required="yes">
<description>
The condition to evaluate.
</description>
</parameter>
<parameter name="conditionValue">
<description>
The value of the condition. During render this is obtained from
the condition parameter. During rewind it is the submitted condition.
</description>
</parameter>
<parameter name="listener"/>
<parameter name="formless" default-value="false">
<description>
Determines whether to avoid creating hidden fields within a form.
</description>
</parameter>
<parameter name="element" default-value="templateTag">
<description>
The element to emulate.
</description>
</parameter>
<parameter name="templateTag" default-value="null">
<description>
The tag with which the component was inserted in its parent template
This parameter will be bound automatically by the framework.
</description>
</parameter>
<property name="name"/>
<property name="form"/>
<inject property="dataSqueezer" object="service:tapestry.data.DataSqueezer"/>
<inject property="listenerInvoker" object="infrastructure:listenerInvoker"/>
</component-specification>
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/components/ElseBean.java
Index: ElseBean.java
===================================================================
//Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.tapestry.components;
import org.apache.hivemind.HiveMind;
import org.apache.tapestry.AbstractComponent;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
/**
* @author mb
*/
public abstract class ElseBean extends AbstractComponent
{
public abstract String getElement();
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
{
Object conditionObject = cycle.getAttribute(IfBean.IF_VALUE_ATTRIBUTE);
if (conditionObject instanceof Boolean && !((Boolean) conditionObject).booleanValue())
{
String element = getElement();
boolean render = !cycle.isRewinding() && HiveMind.isNonBlank(element);
if (render)
{
writer.begin(element);
renderInformalParameters(writer, cycle);
}
renderBody(writer, cycle);
if (render)
writer.end(element);
}
}
}
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/components/IfBean.java
Index: IfBean.java
===================================================================
//Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.tapestry.components;
import java.io.IOException;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.HiveMind;
import org.apache.tapestry.IActionListener;
import org.apache.tapestry.IBinding;
import org.apache.tapestry.IForm;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.Tapestry;
import org.apache.tapestry.TapestryUtils;
import org.apache.tapestry.form.AbstractFormComponent;
import org.apache.tapestry.services.DataSqueezer;
/**
* @author mb
*/
public abstract class IfBean extends AbstractFormComponent
{
public final static String IF_VALUE_ATTRIBUTE = "org.mb.tapestry.base.IfValue";
public abstract IBinding getConditionValueBinding();
public abstract boolean getCondition();
public abstract boolean getFormless();
public abstract String getElement();
public abstract IActionListener getListener();
private boolean _rendering = false;
private boolean _conditionValue;
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
{
boolean cycleRewinding = cycle.isRewinding();
// form may be null if component is not located in a form
IForm form = (IForm) cycle.getAttribute(TapestryUtils.FORM_ATTRIBUTE);
// If the cycle is rewinding, but not this particular form,
// then do nothing (don't even render the body).
if (cycleRewinding && form != null && !cycleRewinding)
return;
// get the condition. work with a hidden field if necessary
_conditionValue = evaluateCondition(cycle, form, cycleRewinding);
_rendering = true;
try {
// call listener
IActionListener listener = getListener();
if (listener != null)
listener.actionTriggered(this, cycle);
// now render if condition is true
if (_conditionValue)
{
String element = getElement();
boolean render = !cycleRewinding && HiveMind.isNonBlank(element);
if (render)
{
writer.begin(element);
renderInformalParameters(writer, cycle);
}
renderBody(writer, cycle);
if (render)
writer.end(element);
}
}
finally {
_rendering = false;
}
cycle.setAttribute(IF_VALUE_ATTRIBUTE, new Boolean(_conditionValue));
}
protected boolean evaluateCondition(IRequestCycle cycle, IForm form, boolean cycleRewinding)
{
boolean condition;
if (form == null || getFormless()) {
condition = getCondition();
}
else {
// we are in a form and we care -- load/store the condition in a hidden field
String name = form.getElementId(this);
if (!cycleRewinding)
{
condition = getCondition();
writeValue(form, name, condition);
}
else
{
condition = readValue(cycle, name);
}
}
// write condition value if parameter is bound
IBinding conditionValueBinding = getConditionValueBinding();
if (conditionValueBinding != null)
conditionValueBinding.setObject(new Boolean(condition));
return condition;
}
private void writeValue(IForm form, String name, boolean value)
{
String externalValue;
Object booleanValue = new Boolean(value);
try
{
externalValue = getDataSqueezer().squeeze(booleanValue);
}
catch (IOException ex)
{
throw new ApplicationRuntimeException(
Tapestry.format("FormConditional.unable-to-convert-value", booleanValue),
this,
null,
ex);
}
form.addHiddenValue(name, externalValue);
}
private boolean readValue(IRequestCycle cycle, String name)
{
String submittedValue = cycle.getParameter(name);
try
{
Object valueObject = getDataSqueezer().unsqueeze(submittedValue);
if (!(valueObject instanceof Boolean))
throw new ApplicationRuntimeException(
Tapestry.format("If.invalid-condition-type", submittedValue));
return ((Boolean) valueObject).booleanValue();
}
catch (IOException ex)
{
throw new ApplicationRuntimeException(
Tapestry.format("If.unable-to-convert-string", submittedValue),
this,
null,
ex);
}
}
public abstract DataSqueezer getDataSqueezer();
public boolean isDisabled()
{
return false;
}
/**
* Returns the value of the condition
* @return the condition value
*/
public boolean getConditionValue()
{
if (!_rendering)
throw Tapestry.createRenderOnlyPropertyException(this, "conditionValue");
return _conditionValue;
}
}
1.6 +3 -1 jakarta-tapestry/framework/src/java/org/apache/tapestry/Framework.library
Index: Framework.library
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/Framework.library,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Framework.library 8 Mar 2005 22:36:40 -0000 1.5
+++ Framework.library 21 Jun 2005 06:52:52 -0000 1.6
@@ -45,10 +45,12 @@
<component-type type="FieldLabel" specification-path="valid/FieldLabel.jwc"/>
<component-type type="Foreach" specification-path="components/Foreach.jwc"/>
<component-type type="Frame" specification-path="html/Frame.jwc"/>
+ <component-type type="Else" specification-path="components/Else.jwc"/>
<component-type type="ExceptionDisplay" specification-path="html/ExceptionDisplay.jwc"/>
<component-type type="Form" specification-path="form/Form.jwc"/>
<component-type type="GenericLink" specification-path="link/GenericLink.jwc"/>
<component-type type="Hidden" specification-path="form/Hidden.jwc"/>
+ <component-type type="If" specification-path="components/If.jwc"/>
<component-type type="Image" specification-path="html/Image.jwc"/>
<component-type type="ImageSubmit" specification-path="form/ImageSubmit.jwc"/>
<component-type type="Insert" specification-path="components/Insert.jwc"/>
@@ -73,7 +75,7 @@
<component-type type="TextField" specification-path="form/TextField.jwc"/>
<component-type type="Upload" specification-path="form/Upload.jwc"/>
<component-type type="ValidField" specification-path="valid/ValidField.jwc"/>
-
+
<page name="StaleLink" specification-path="pages/StaleLink.page"/>
<page name="StaleSession" specification-path="pages/StaleSession.page"/>
<page name="Exception" specification-path="pages/Exception.page"/>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org