You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by dpmihai <dp...@yahoo.com> on 2013/03/14 12:48:10 UTC

Wicket 6: LinkResource with a dynamic resource

Hi.

I want to have a table with a Link PropertyColumn which contains a
LinkResource. When user clicks on the link I want to be able to pass the row
model to resource first and then have the resource loaded.

I created a ResourceLinkPropertyColumn class like:


public class ResourceLinkPropertyColumn<T> extends PropertyColumn<T, String>
{

    private IModel labelModel;
    private ByteArrayResource resource;

    public ResourceLinkPropertyColumn(IModel displayModel, IModel
labelModel, ByteArrayResource resource) {
		super(displayModel, null);
		this.labelModel = labelModel;
		this.resource = resource;
	}

     @Override
     public void populateItem(Item item, String componentId, IModel model) {
		item.add(new LinkPanel(item, componentId, model));
     }
	
     protected void onDone(IModel<T> rowModel) {		
     }
    
     public ByteArrayResource getResource() {
		return resource;
     }
	
     public class LinkPanel extends Panel {		

		public LinkPanel(final Item item, final String componentId, final IModel
model) {
			super(componentId);
			
			ResourceLink link = new ResourceLink("link", resource) {

				@Override
				public void onClick() {
					onDone(model);
					super.onClick();
				}
				
				protected void onComponentTag(ComponentTag componentTag) {
	                                 super.onComponentTag(componentTag);
	                                 componentTag.put("target", "_blank");
	                        }
												
			};
			add(link);

			IModel tmpLabelModel = labelModel;
			if (labelModel == null) {
				tmpLabelModel = getDataModel(model);
			}

			link.add(new Label("label", tmpLabelModel));
		}
	}
}

When I create my data table I add my column like:

columns.add(new ResourceLinkPropertyColumn<User>(new
Model<String>("Generate"), new Model<String>("Generate"),new
MyByteArrayResource()) {
        	protected void onDone(IModel<User> rowModel) {		
        		final MyObject object = rowModel.getObject();          	
        		((MyByteArrayResource)getResource()).setMyObject(object);
        	}
        });   

The problem is that when I click the link the resource is loaded first and
then my onDone method is called.
Is there any possibility to pass the model to the resource before it is
loaded?



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-6-LinkResource-with-a-dynamic-resource-tp4657238.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Wicket 6: LinkResource with a dynamic resource

Posted by dpmihai <dp...@yahoo.com>.
The only solution I have is to create my own class ResourceLink with a
method:

    public void beforeResourceRequested() {}  (here I will set rowModel to
my resource)


and use it inside onResourceRequested:

	/**
	 * @see org.apache.wicket.IResourceListener#onResourceRequested()
	 */
	@Override
	public final void onResourceRequested()
	{
		beforeResourceRequested();
		Attributes a = new Attributes(RequestCycle.get().getRequest(),
RequestCycle.get()
			.getResponse(), null);
		resource.respond(a);
		onLinkClicked();
	}



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-6-LinkResource-with-a-dynamic-resource-tp4657238p4657239.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org