dont use the evanJSON() function, its not needed anymore

with regards
Sven Homburg
Founder of the Chenille Kit Project
http://www.chenillekit.org





2009/7/23 Max Weißböck (info) <m...@weissboeck.info>:
> 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());
>    }
> }
>
>
>
>
>

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

Reply via email to