Hi, 

I am trying to create an ajax enabled select control, much like chenilleKits
InPlaceCheckbox...so i copied the .js and .java files and tried to customize
it for a select control.

I ran into problems passing the 'model' parameter.   instead of taking the
model parameter to use it to generate the options, the rendered page lands
up having the address of the model instance  passed...resulting in no select
box being created.

Also, I am not sure how the 'value' parameter should be passed...as a PROP
or a LITERAL.

The rendered page is:
<form>
<t:select t:id="inPlaceSelect"
model="com.adsafe.fcc.webapp.components.CodeSelectModel@cc99e73"
value="selectedStatus"></t:select>
</form>

Here is the code:

component code:

@SupportsInformalParameters
@IncludeJavaScriptLibrary(value = {"Chenillekit.js", "InPlaceSelect.js"})
public class InPlaceSelect implements ClientElement {

        public static final String EVENT_NAME = "change";

    @Parameter(value = "prop:componentResources.id", defaultPrefix =
BindingConstants.LITERAL)
    private String clientId;
    
    @Inject
    private RenderSupport renderSupport;

    @Parameter(required = false, defaultPrefix = BindingConstants.LITERAL)
    private String onCompleteCallback;
    
    @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
    private String value;
    
    @Parameter(required = true, defaultPrefix = BindingConstants.PROP)
    private SelectModel model;
    
    @Parameter(required = false, defaultPrefix = BindingConstants.PROP)
    private List<?> context;
    
    @Inject
    private ComponentResources resources;

    private Object[] contextArray;
    
    @Property
    private String assignedClientId;
    
    void setupRender() {
        assignedClientId = renderSupport.allocateClientId(clientId);
        contextArray = context == null ? new Object[0] : context.toArray();
    }
    
    void beginRender(MarkupWriter writer) {
                writer.element("t:select",
                                "t:id", getClientId(),
                                "model", model,
                                "value", value);
                                
        resources.renderInformalParameters(writer);
    }

    void afterRender(MarkupWriter writer)
    {
        writer.end(); // input

        Link link = resources.createEventLink(EventConstants.ACTION,
contextArray);
        String ajaxString = "new Ck.InPlaceSelect('%s', '%s'";

        if (onCompleteCallback != null)
            ajaxString += ",'" + onCompleteCallback + "'";

        ajaxString += ");";

        renderSupport.addScript(ajaxString, getClientId(),
link.toAbsoluteURI());
    }

    public String getClientId()  {
        return assignedClientId;
    }
        
    // other stuff, onEvent etc
}


how i use it in my tml:

<form>
   <div t:id="inPlaceSelect"/>
</form>


The corresponding java class:

@Property 
private String selectedStatus; 
    
@Component(parameters = {"value=selectedStatus",
"model=programStatusModel"})
private InPlaceSelect inPlaceSelect;

public SelectModel getProgramStatusModel() { 
                
       Map<String, String> options = new HashMap<String, String>();
                
        for(ProgramStatus status : ProgramStatus.getValues()) {
                options.put(status.getLabel(), status.getLabel());
        }
        
                return new CodeSelectModel(options, false);
                
}


-- 
View this message in context: 
http://tapestry.1045711.n5.nabble.com/creating-an-InPlaceSelect-control-tp3358181p3358181.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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

Reply via email to