Re: Calling action passed via biding in subcomponent.
Re: Calling action passed via biding in subcomponent.
- Subject: Re: Calling action passed via biding in subcomponent.
- From: Chuck Hill <email@hidden>
- Date: Fri, 02 Nov 2012 16:41:53 -0700
On 2012-11-02, at 3:02 PM, Miguel Torres wrote:
> Hi List,
>
> I am creating a Component to use <button > HTML tag in my apps.
>
> I am implementing Bootstrap in my WO application and I want to create buttons with icons.
>
> I followed the example in the book Practical WebObjects, chapter 6 that creates a Hyperlink Component.
>
> This is my code based on the book's example:
>
> public class BootstrapSubmitButton extends ERXComponent {
> public BootstrapSubmitButton(WOContext context) {
> super(context);
> }
>
> @Override
> public void appendToResponse(WOResponse response, WOContext context) {
> String tabindex = stringValueForBinding("tabindex");
> String cssClass = "btn "+stringValueForBinding("class", "");
> String icon = stringValueForBinding("icon");
>
> response.appendContentString("<button name=\""+context.elementID()+"\"");
> if(tabindex != null){
> response.appendContentString("tabindex=\""+tabindex+"\" ");
> }
> response.appendContentString("class=\""+cssClass+"\" type=\"submit\">");
> if(icon != null){
> response.appendContentString("<i class=\""+stringValueForBinding("icon")+"\" > </i> ");
> }
> response.appendContentString(stringValueForBinding("value"));
> response.appendContentString("</button>");
> }
>
> @Override
> public boolean synchronizesVariablesWithBindings() {
> return false;
> }
>
> @Override
> public WOActionResults invokeAction(WORequest request, WOContext context) {
> if(context.elementID().startsWith(context.senderID())){
> return (WOActionResults)valueForBinding("action");
> }
> return null;
> }
> }
>
>
> I just changed a line:
>
>
> if(context.elementID().startsWith(context.senderID())){
>
>
>
> The example in the book is coded like this:
> if(context.elementID().equals(context.senderID())){
>
>
> I had to changed it because it was not working, debugging the code I found that the element's ID is never equals to the sender's ID. It sounds logic because they are two different objects.
Why are they different objects? Look at the page content, what matches the senderID()? Your code is saying "if the action is from me, or from any of my children". Is there something else embedded in your button?
> I think my change is correct.
>
> Am I right and that's an error in the book's example?
>
> Did I misunderstand the concepts in the book and I am doing something dangerous for my application?
I am pretty sure the book is correct, I don't understand why you are seeing the results that you are seeing.
Chuck
--
Chuck Hill Senior Consultant / VP Development
Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/gvc/practical_webobjects
Global Village Consulting ranks 13th in 2012 in BIV's Top 100 Fastest Growing Companies in B.C!
Global Village Consulting ranks 76th in 24th annual PROFIT 200 ranking of Canada’s Fastest-Growing Companies by PROFIT Magazine!
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden