Folks, SUBJECT: T-4.1.3 - Refresh versus Form-Submit I have an instance where 
neither of the above actions (browser refresh button OR form submit) results in 
normal behavior. My REFRESH resets the form to everything initialized (cached 
parameters and page properties are all reset) but the page gets rendered and my 
render logic calculates. I am unable to use this kind of software. My Form 
Submit occurs and I get a break point in the listener as well as other onchange 
event listeners and I induce an explicit manual refresh using 
getResponseBuilder().updateComponent(...) within the form submit. But nothing 
gets rendered. It's like nothing works. Attached are the modules. Everything is 
coded properly. Now everytime I flame this release for a bug or something folks 
get offended. Everytime I say that parameters and properties are faulty and DO 
NOT WORK folks just ignore. So I challenge anybody. Can you fix this code? Whay 
is tapestry so darn hard to get to work? 20+ of user interface R&D and blue in 
the face. Look at the modules and see for yourself. It is coded right.Is it 
true that some of it works only some of the time? I want to use this stuff 
commercially. Any help is appreciated.Best regards Ken in nashua

Helping your favorite cause is as easy as instant messaging. You IM, we give. 
Learn more. 
_________________________________________________________________
Climb to the top of the charts! Play the word scramble challenge with star 
power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_jan
package org.trails.demo.components;

import java.util.Collection;

import javax.servlet.ServletContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry.IAsset;
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.IScript;
import org.apache.tapestry.annotations.ComponentClass;
import org.apache.tapestry.annotations.EventListener;
import org.apache.tapestry.annotations.InjectObject;
import org.apache.tapestry.annotations.InjectScript;
import org.apache.tapestry.annotations.Parameter;
import org.apache.tapestry.form.IPropertySelectionModel;
import org.apache.tapestry.web.WebRequest;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.dao.DataAccessException;
import org.trails.component.TrailsComponent;
import org.trails.component.blob.BlobDownloadService;
import org.trails.component.blob.TrailsBlobAsset;
import org.trails.demo.Listing;
import org.trails.descriptor.DescriptorService;
import org.trails.page.EditPage;
import org.trails.persistence.HibernatePersistenceService;
import org.trails.util.IntegerPropertySelectionModel;

/**
 * This guy (tapestry/dojo/json/script oriented widget) renders a gallery.
 *
 * Script is facilitated to operate/persist auto-paging.
 *
 * @author kenneth.colassi [EMAIL PROTECTED]
 *
 */
@ComponentClass(allowBody = true, allowInformalParameters = true)
public abstract class Gallery extends TrailsComponent
{
	private static final Log LOG = LogFactory.getLog(Gallery.class);

	private static final Integer[] tableSizeIntegerOptions = new Integer[]
	{ new Integer("1"), new Integer("2"), new Integer("3"), new Integer("4"), new Integer("5"), new Integer("10"),
	        new Integer("25"), new Integer("50"), new Integer("100"), new Integer("500"), new Integer("1000"),
	        new Integer("2500"), new Integer("5000"), new Integer("10000"), new Integer("25000"), new Integer("50000") };

	private static final String[] tableSizeStringOptions = new String[]
	{ new String("1"), new String("2"), new String("3"), new String("4"), new String("5"), new String("10"),
	        new String("25"), new String("50"), new String("100"), new String("500"), new String("1000"),
	        new String("2500"), new String("5000"), new String("10000"), new String("25000"), new String("50000") };

	private static final Integer[] pagingSpanIntegerOptions = new Integer[]
	{ new Integer("5"), new Integer("10"), new Integer("15"), new Integer("20"), new Integer("25") };

	private static final String[] pagingSpanStringOptions = new String[]
	{ new String("5"), new String("10"), new String("15"), new String("20"), new String("25") };

	private IPropertySelectionModel tableSizeModel = null;

	private IPropertySelectionModel pagingSpanModel = null;

	private Collection collection = null;

	/**
	 * E-Frastructure and Services
	 */
    @InjectObject("service:tapestry.globals.ServletContext")
    public abstract ServletContext getServletContext();
    
    @InjectObject("service:tapestry.globals.WebRequest")
    public abstract WebRequest getWebRequest();
    
	@InjectObject("spring:persistenceService")
	public abstract HibernatePersistenceService getHibernatePersistenceService();

	@InjectObject("spring:descriptorService")
	public abstract DescriptorService getDescriptorService();

	@InjectObject("service:trails.core.BlobService")
	public abstract BlobDownloadService getDownloadService();

	@Parameter(required = true)
	public abstract Class getCollectionType();
	public abstract void setCollectionType(Class collectionType);

	/**
	 * PropertySelection Support
	 */
	//@Persist
	@Parameter(required = false, cache = true, defaultValue="ognl:2")
	//@Parameter(required = true, cache = true)
	//@InitialValue("ognl:2")
	public abstract Integer getTableSize();
	public abstract void setTableSize(Integer tableSize);

	//@Persist
	@Parameter(required = false, cache = true, defaultValue="ognl:5")
	//@InitialValue("ognl:5")
	public abstract int getPagingSpan();
	public abstract void setPagingSpan(int pagingSpan);

	//@Parameter(required = true, cache = true)
	//@Persist
	//public abstract int getValue();
	//public abstract void setValue(int value);

	protected void finishLoad()
	{
		super.finishLoad();

		// parameter initialization, alternative to parameter annotation
		// defaultValue
		// setTableSize("2");
		// setPagingSpan("5");
	}

	/**
	 * FOR component Collection Iterator support
	 */
	@Parameter(required = false)
	public abstract int getStartRow();
	public abstract void setStartRow(int startRow);

	public abstract Object getCurrentObject();
	public abstract void setCurrentObject(Object CurrentObject);

	public abstract int getIndex();
	public abstract void setIndex(int index);

	/**
	 * Typically injected via jwc - readonly, yes that means no setter
	 */
	@InjectScript("Gallery.script")
	public abstract IScript getScript();

	public Collection getCollection()
	{
		return collection;
	}

	public void setCollection(Collection collection)
	{
		this.collection = collection;
	}

	public Collection loadCollection(Class collectionClass) throws DataAccessException
	{
		DetachedCriteria criteria = DetachedCriteria.forClass(collectionClass);
		// criteria.add(Restrictions.eq("id", 1));
		return getHibernatePersistenceService().getInstances(collectionClass, criteria);
	}

	public IPropertySelectionModel getTableSizeModel()
	{
		if (tableSizeModel == null)
		{
			tableSizeModel = new IntegerPropertySelectionModel(tableSizeIntegerOptions);
			//tableSizeModel = new StringPropertySelectionModel(tableSizeStringOptions);
		}

		return tableSizeModel;
	}

	public IPropertySelectionModel getPagingSpanModel()
	{
		if (pagingSpanModel == null)
		{
			pagingSpanModel = new IntegerPropertySelectionModel(pagingSpanIntegerOptions);
			//pagingSpanModel = new StringPropertySelectionModel(pagingSpanStringOptions);
		}

		return pagingSpanModel;
	}

	@Override
	protected void prepareForRender(IRequestCycle cycle)
	{
		super.prepareForRender(cycle);

		setCollection(loadCollection(getCollectionType()));

		/*
		 * if ( getTableSize() == null ) setTableSize (tableSizeOptions[0]); if (
		 * getPagingSpan() == null ) setPagingSpan (pagingSpanOptions[0]);
		 */
	}

	public IAsset getPhotoAsset()
	{
		Listing listing = (Listing) getCurrentObject();
		String contentType = listing.getPhoto().getContentType();
		String fileName = listing.getPhoto().getFileName();

		return new TrailsBlobAsset(getDownloadService(), getCollectionType().getName(), listing.getId().toString(),
		        "photo", contentType, fileName);
	}

	@EventListener(events = { "onchange" }, targets = { "tableSizeSelect" }, submitForm = "galleryForm", async = true)
	public void tableChangeListener(IRequestCycle cycle)
	{
		LOG.info("In tableChangeListener : ");
	}

	@EventListener(events = { "onchange" }, targets = { "pagingSpanSelect" }, submitForm = "galleryForm", async = true)
	public void pagingSpanListener(IRequestCycle cycle)
	{
		// (events="onchange") Just keep all of your event names in lowercase and you'll be ok.

		LOG.info("In pagingSpanListener : ");
	}

	public IPage galleryFormSubmit(IRequestCycle cycle)
	{
		IPage page = cycle.getPage();

		LOG.info("In galleryFormSubmit : ");

		return page;
	}

	public void onBeginPage(IRequestCycle cycle)
	{
		LOG.info("In onBeginPage : ");
	}

	public IPage onPrevPage(IRequestCycle cycle)
	{
		EditPage editPage = null;

		LOG.info("In onPrevPage : ");

		return editPage;
	}

	public IPage onPage(Integer number)
	{
		EditPage editPage = null;

		LOG.info("In onPage : ");

		return editPage;
	}

	public IPage onNextPage(IRequestCycle cycle)
	{
		EditPage editPage = null;

		LOG.info("In onNextPage : ");

		return editPage;
	}

	public IPage onEndPage(IRequestCycle cycle)
	{
		EditPage editPage = null;

		LOG.info("In onEndPage : ");

		return editPage;
	}
}
package org.trails.demo.page;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry.IAsset;
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.annotations.EventListener;
import org.apache.tapestry.annotations.InitialValue;
import org.apache.tapestry.annotations.InjectComponent;
import org.apache.tapestry.annotations.InjectObject;
import org.apache.tapestry.annotations.InjectState;
import org.apache.tapestry.annotations.Persist;
import org.apache.tapestry.event.PageBeginRenderListener;
import org.apache.tapestry.event.PageEvent;
import org.apache.tapestry.services.ResponseBuilder;
import org.trails.component.blob.BlobDownloadService;
import org.trails.component.blob.TrailsBlobAsset;
import org.trails.demo.AdminLayout;
import org.trails.demo.components.Gallery;

public abstract class Home extends org.trails.page.HomePage 
	implements PageBeginRenderListener
{
	private static final Log LOG = LogFactory.getLog(Home.class);

	@InjectState("adminLayout")
	public abstract AdminLayout getLayout();

	@InjectObject("service:trails.core.BlobService")
	public abstract BlobDownloadService getDownloadService();
	
    @InjectComponent("galleryWidget")
    public abstract Gallery getGallery();	

	public IAsset getSplash()
	{
		String contentType = getLayout().getSplash().getContentType();
		String fileName = getLayout().getSplash().getFileName();

		return new TrailsBlobAsset(getDownloadService(),
				AdminLayout.class.getName(),
				getLayout().getId().toString(),
				"splash", contentType,
				fileName);
	}

	public IAsset getHeader()
	{
		String contentType = getLayout().getHeader().getContentType();
		String fileName = getLayout().getHeader().getFileName();

		return new TrailsBlobAsset(getDownloadService(),
				AdminLayout.class.getName(),
				getLayout().getId().toString(),
				"header", contentType,
				fileName);
	}

	/**
	 * Pages take properties
	 * Components take parameters
	 *
	 * These two need to be rigged up in order to persist across request cycles
	 *
	 * Components are configured by binding their parameters.
	 * Binding of parameters may occur inside a page or component template, or
	 * a page or component specification.
	 *
	 * @return
	 */
	@Persist
	@InitialValue("ognl:2")
	public abstract Integer getTableSize();
	public abstract void setTableSize(Integer tableSize);

	@Persist
	@InitialValue("ognl:5")
	public abstract int getPagingSpan();
	public abstract void setPagingSpan(int pagingSpan);

	//@Persist
	//public abstract int getValue();
	//public abstract void setValue(int value);

	@EventListener(events = { "onchange" }, targets = { "tableSizeSelect" }, submitForm = "galleryForm", async = true)
	public void tableChangeListener(IRequestCycle cycle)
	{
		LOG.info("In tableChangeListener : ");
	}

	@EventListener(events = { "onchange" }, targets = { "pagingSpanSelect" }, submitForm = "galleryForm", async = true)
	public void pagingSpanListener(IRequestCycle cycle)
	{
		// (events="onchange") Just keep all of your event names in lowercase and you'll be ok.

		LOG.info("In pagingSpanListener : ");
	}
	public IPage galleryFormSubmit(IRequestCycle cycle)
	{
		IPage page = cycle.getPage();

		LOG.info("In galleryFormSubmit : ");
		
		refresh();

		return page;
	}
	
    @Override
    public void pageBeginRender(PageEvent event)
    {
        super.pageBeginRender(event);
    }
    
    abstract public ResponseBuilder getResponseBuilder();
    
    /**
     * Re-renders (via ajax) the Tapestry node containing the ui.
     */
    public void refresh()
    {
    	/*
        getResponseBuilder().updateComponent("headerSelect");        
        getResponseBuilder().updateComponent("footerSelect");        
        getResponseBuilder().updateComponent("tableSizeSelect");        
        getResponseBuilder().updateComponent("pagingSpanSelect");
        */  
        getResponseBuilder().updateComponent("galleryForm");  
        getResponseBuilder().updateComponent("galleryWidget");  
             
    }       
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script PUBLIC
	"-//Apache Software Foundation//Tapestry Script Specification 4.0//EN"
	"http://jakarta.apache.org/tapestry/dtd/Script_4_0.dtd";>

<script>
	<!-- Method Parameter Bindings -->
	<input-symbol key="component" class="org.trails.demo.components.Gallery" required="yes" />
	<input-symbol key="selected" required="no" />
	<input-symbol key="pagingSpan" required="no" />

	<!-- Instance Variables -->
	<let key="widget" unique="yes">${component.clientId}</let>
	<let key="galleryForm">document.forms[0]</let>
	<let key="numColumns" unique="yes">inlineNumColumns</let>

	<body>
		<unique>
			dojo.require("tapestry.widget.Widget");
			dojo.require("tapestry.form");
			dojo.require("dojo.io");
			dojo.require("dojo.dom");
			dojo.require("dojo.widget.*");
			dojo.require("dojo.html.*");
			dojo.require("dojo.event");
		</unique>

		function setSelected(theList, theValue) {
			for (var i = 0; i &lt; theList.length; i++) {
				if ( theList[i].text == theValue) {
				  theList[i].selected = true;
				  break;
				}
			}
		}

		function initGallery() {

			var imageWidth = 160;
			var contentBox = dojo.html.getContentBox(${galleryForm});
			${numColumns} = Math.floor(contentBox.width / imageWidth);

			var dojoWidget = dojo.widget.getWidgetById("${component.clientId}");

			var divBlock = document.createElement("div");
			divBlock.appendChild(document.createTextNode("Loading..."));
			var contentDom = document.forms[0].document.getElementById("galleryContent");
			contentDom.appendChild(divBlock);

		}
	</body>

	<initialization>
		initGallery();
	</initialization>
</script>
<!DOCTYPE component-specification PUBLIC "-//Apache Software 
Foundation//Tapestry Specification 4.1//EN" 
"http://jakarta.apache.org/tapestry/dtd/Tapestry_4_1.dtd";>
<component-specification class="org.trails.demo.components.Gallery"
                                                 allow-body="yes"
                                                 
allow-informal-parameters="yes">


</component-specification>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to