You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Maximilian Weißböck <m....@inode.at> on 2009/07/23 13:05:01 UTC

having big trouble with evalJSON() - am I really at war with it?

Based on the example from Hugo Palma (see http://markmail.org/message/4bdwo2yrx6tavdgh)
I implemented a dependend checkbox.

Event handling is fine, but I lost hours finding out while  
response.evalJSON() fails and I still have no clue...

Im always getting this erreor;
Error communication with the server: Result of expression  
'response.evalJSON' [undefined] is not a function.

Looks like evalJSON ist not defined (I'm not a JavaScript guy at  
all....)

How do I import the js library that includes the evalJSON function? I  
tried everithing I can think of and this is my
current js import

@IncludeJavaScriptLibrary( { "context:js/Chenillekit.js", "context:js/ 
RESelection.js", "${tapestry.scriptaculous}/prototype.js" })
public class RealEstateCreate {

Any help is VERY welcome, as I'm at a dead end now....


Thanks, Max


This are the js, tml and class files

---------- RESelection.js ---------

function onCompleteChangeReSubType(response) {
     selectElement = $('resubtype');
     Tapestry.debug(response);
     Tapestry.debug("1");
     responseJSON = response.evalJSON();
     Tapestry.debug("2");

     while (selectElement.options.length > 0) {
         selectElement.options[0] = null;
     }

     for (index = 0; index < responseJSON.length; index++) {
         selectElement.options[index] = new Option(responseJSON
         		[index].label, responseJSON [index].value);
     }

     Tapestry.ElementEffect.highlight($("resubtype"));
}


----class---





----- tml RealEstateCreate.tml ----

<html t:type="layout" title="message:pagename" sidebarTitle="message:sidebarTitle 
"
       xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
       xmlns:p="tapestry:parameter">

	<t:form t:id="form" class="yform">

	    <t:errors/>

		<div class="type-text">
	  		<t:label for="title"/>
	        <t:textfield t:id="title"  value="realestate.title"  
validate="required"/>
         </div>

         <t:label for="retype"/>
		<select t:type="select" t:id="retype" value="realestate.retype"
				model="reTypesSelectionModel" encoder="reTypesValueEncoder"  
validate="required"/>

		<t:label for="resubtype"/>
		<select t:type="select" t:id="resubtype" value="realestate.resubtype"
				model="reSubTypesSelectionModel" encoder="reSubTypesValueEncoder"  
validate="required"/>

     	<t:ybeaneditor t:id="realestate" exclude="title">
     		<p:description>
                 <t:label for="description"/>
                 <t:textarea t:id="description"  
value="realestate.description"/>
             </p:description>
     	</t:ybeaneditor>
     	
     	<div class="type-button">
             <input type="submit" value="Anlegen"/>
         </div>
     	
	</t:form>
	
	<t:if test="message">
		<div class="info">
			${message}
		</div>
	</t:if>
	
	<p:sidebar>
		<div class="menue-box">
			<t:agentmenu/>
		</div>
	</p:sidebar>

</html>


-------- class  RealEstateCreate.java ----------


package net.weissboeck.gimmo.pages.realestate;

import java.util.List;

import net.weissboeck.gimmo.annotations.InjectSelectionModel;
import net.weissboeck.gimmo.beans.WebUser;
import net.weissboeck.gimmo.entities.Agent;
import net.weissboeck.gimmo.entities.RESubType;
import net.weissboeck.gimmo.entities.REType;
import net.weissboeck.gimmo.entities.RealEstate;
import net.weissboeck.gimmo.services.DataService;
import net.weissboeck.gimmo.services.RealEstateService;
import net.weissboeck.gimmo.services.UserService;
import net.weissboeck.gimmo.util.ExceptionParser;

import org.apache.tapestry5.PersistenceConstants;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Log;
import org.apache.tapestry5.annotations.Mixins;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.corelib.components.Select;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.json.JSONArray;
import org.apache.tapestry5.json.JSONObject;
import org.chenillekit.access.annotations.Restricted;
import org.slf4j.Logger;


@Restricted(groups = { "AGENT" })
@IncludeJavaScriptLibrary( { "context:js/Chenillekit.js", "context:js/ 
RESelection.js", "${tapestry.scriptaculous}/prototype.js" })
public class RealEstateCreate {

     @Inject
     private Logger logger;

     @SessionState
     private WebUser webUser;

     @Component
     private Form form;

     @Persist
     @Property
     private RealEstate realEstate;

     @SuppressWarnings("unused")
	@Property
     @Persist(PersistenceConstants.FLASH)
     private String message;

     @InjectPage
     private RealEstateEdit editPage;

     @Inject
     private RealEstateService realEstateService;

     @Inject
     private DataService dataService;

     @Inject
     private UserService userService;

     @InjectSelectionModel(labelField = "name", idField = "oid")
     private List<REType> reTypes;

     @InjectSelectionModel(labelField = "name", idField = "oid")
     private List<RESubType> reSubTypes;

     @Component(parameters = {"event=change",  
"onCompleteCallback=literal:onCompleteChangeReSubType"})
     @Mixins({"ck/OnEvent"})
     private Select reType;



     @Log
     @OnEvent(component="reType", value="change")
     public JSONArray onChangeRETypeEvent(String value) {
         JSONArray jsonArray = new JSONArray();

         List<RESubType> subTypes =  
dataService 
.getRESubTypes(dataService.loadREType(Long.parseLong(value)));

         for (RESubType subType : subTypes) {
             JSONObject jo = new JSONObject();
             jo.put("value", subType.getOid());
             jo.put("label", subType.getName());
             jsonArray.put(jo);
         }

         return jsonArray;
     }

     @Log
     void onPrepare() {
     	reTypes = dataService.getRETypes();
     	reSubTypes = dataService.getRESubTypes(reTypes.get(0));
     }


     @Log
     Object onSuccess() {
     	realEstate.setIsActive(true);
         realEstate.setAgent(userService.loadAgent(webUser.getOid()));
         realEstateService.updateGeoData(realEstate);
         realEstateService.save(realEstate);
         editPage.onActivate(realEstate.getOid());
         return editPage;
     }

     @Log
     Object onException(Throwable cause) {
         form.recordError(ExceptionParser.extractMessage(cause));
         return this;
     }


     @Log
     void onActivate(Long pOid) {
     	Agent agent = userService.loadAgent(webUser.getOid());
     	if (pOid == null || pOid == 0) {
     		realEstate = new RealEstate();
     	}
     	realEstate.setContactEmail(agent.getContactEmail());
     	realEstate.setContactName(agent.getFirstname() + " " +  
agent.getLastname());
     	realEstate.setContactPhone(agent.getPhone());
     	realEstate.setContactSalutation(agent.getSalutation());
     }
}