You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by trsvax <tr...@gmail.com> on 2012/09/03 17:12:19 UTC

Can't change BeanEditForm submitLabel with a mixin?

I'm trying to change the BeanEditForms submitLabel with a mixin like this

@BindParameter
private String submitLabel;

void setupRender() {
     submitLabel = "New";
}

but that results in this

Render queue error in SetupRender[user/New:user]: Failure writing parameter
'submitLabel' of component user/New:user: Binding LiteralBinding[default
submitLabel: Create/Update] is read-only.

I'm guessing that's because the parameter is declared like this

@Parameter(value = "message:submit-label", defaultPrefix =
BindingConstants.LITERAL)
@Property
 private String submitLabel;

which means the value is connected to a message by default and messages are
read only.

Is there a workaround for this or is it just impossible to override
Parameters declared this way?

Thanks,
Barry




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-t-change-BeanEditForm-submitLabel-with-a-mixin-tp5716012.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can't change BeanEditForm submitLabel with a mixin?

Posted by Lance Java <la...@googlemail.com>.
I'm starting to agree with your original suspicions that it's something to do
with the "message:" binding. Under the hood, MessageBindingFactory creates a
LiteralBinding which can be seen in the error message. I'm guessing you are
in some byte code state where tapestry can read from the binding but can't
write the property to a ThreadLocal as happens with normal properties.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-t-change-BeanEditForm-submitLabel-with-a-mixin-tp5716012p5716039.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can't change BeanEditForm submitLabel with a mixin?

Posted by trsvax <tr...@gmail.com>.
here is the current working mixin. It uses markup writer to set the button
value because 

submitLabel = defaultLabel; will result in the error

public class BeanEditDefaults {

	@BindParameter
	private String reorder;

	@BindParameter
	private String submitLabel;

	@Inject
	private Environment environment;

	@Inject
	private ComponentResources resources;

	@Inject
	private Logger logger;

	private Element form;

	private String newLabel;

	@SetupRender
	@SuppressWarnings("unchecked")
	void setupRender(MarkupWriter writer) {
		String defaultLabel =
resources.getContainerResources().getMessages().get("submit-label");
		logger.info("default {}", defaultLabel);

		if (submitLabel != null && submitLabel.equals(defaultLabel)) {
			form = writer.element("mixin", "name", this.getClass().getName());
			String type =
resources.getContainerResources().getBoundType("object").getSimpleName();
			newLabel =
resources.getPage().getComponentResources().getMessages().format("submit-label",
type);
			environment.peek(LayoutEnvironment.class).setTitle(newLabel);
		}

		Class beantype = resources.getContainerResources().getBoundType("object");
		BeanEditEnviromentInterface enviromentType = (BeanEditEnviromentInterface)
beantype.getAnnotation(BeanEditEnviromentInterface.class);
		if (enviromentType != null) {
			BeanEditEnvironment defaults = environment.peek(enviromentType.value());
			if (defaults != null) {
				if (reorder == null) {
					reorder = defaults.getOrder();
				}
			}
		}

	}

	@AfterRender
	void afterRender(MarkupWriter writer) {
		if (form != null) {
			writer.end();
			form.visit(new Visitor() {

				public void visit(Element element) {
					if (element.getName().equals("input")) {
						String value = element.getAttribute("value");
						String type = element.getAttribute("type");
						if (type != null && type.equals("submit")
								&& value != null && value.equals(submitLabel)) {
							element.forceAttributes("value", newLabel);
						}
					}

				}
			});
		}
	}

	@CleanupRender
	void cleanupRender() {
		if (form != null) {
			form.pop();
		}
	}

}

It's attached with a worker


public class AddMixinWorker implements ComponentClassTransformWorker2 {

	public void transform(PlasticClass plasticClass, TransformationSupport
support, MutableComponentModel model) {
		if ( match(BeanEditForm.class, plasticClass) ) {
			model.addMixinClassName(BeanEditDefaults.class.getName());
		}
		
	}
	
	boolean match( Class clazz, PlasticClass plasticClass) {
		return clazz.getName().equals(plasticClass.getClassName());
	}

}




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-t-change-BeanEditForm-submitLabel-with-a-mixin-tp5716012p5716038.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can't change BeanEditForm submitLabel with a mixin?

Posted by Lance Java <la...@googlemail.com>.
Can you post the code that attaches the mixin to the beaneditform (either TML
or Java)



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-t-change-BeanEditForm-submitLabel-with-a-mixin-tp5716012p5716037.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can't change BeanEditForm submitLabel with a mixin?

Posted by trsvax <tr...@gmail.com>.
 I still get the same error

Render queue error in SetupRender[address/New:address]: Failure writing
parameter 'submitLabel' of component address/New:address: Binding
LiteralBinding[default submitLabel: Create/Update] is read-only.

I also tried 

@Parameter
private String submitLabel;
	
@BindParameter(value="submitLabel")
private String componentLabel;

but that does not work either. It seems no matter what the component's
submitLabel is bound to the message unless you supply a value;

I did work around the problem using the MarkupWriter in the AfterRender
method to find the submit button and update it's value. That works but it
would be nice to be able to override a default Parameter value with a mixin.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-t-change-BeanEditForm-submitLabel-with-a-mixin-tp5716012p5716020.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can't change BeanEditForm submitLabel with a mixin?

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Mon, 03 Sep 2012 12:12:19 -0300, trsvax <tr...@gmail.com> wrote:

> I'm trying to change the BeanEditForms submitLabel with a mixin like this
>
> @BindParameter
> private String submitLabel;
>
> void setupRender() {
>      submitLabel = "New";
> }
>
> but that results in this
>
> Render queue error in SetupRender[user/New:user]: Failure writing  
> parameter
> 'submitLabel' of component user/New:user: Binding LiteralBinding[default
> submitLabel: Create/Update] is read-only.

Try adding @Property to submitLabel.

-- 
Thiago H. de Paula Figueiredo

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