Hi Paul,

On Jun 26, 2007, at 3:46 PM, Paul Marvine wrote:

Hello,
This is a basic concept that I can't seem to get my brain to understand. I have an entity called "webView" with an attribute called "headline". When a user views a record and clicks a button (linked to an action "doUpdates") I want to change "headline" and other attributes and then save the record.
I've tried lines like...
webView.takeValueForKey("Hey, you clicked on the button", "headline");

That should work.


or
webViewDisplayGroup.selectedObject().takeValueForKey("Hey, you clicked on the button", "headline");

and always seem to get a "can't resolve symbol" error on build.

That will give a build error. First off, we have a rule: no posting about errors without including the exact text of the error and a stack trace if there is one. Otherwise we are reduced to playing guessing games and that gets tiring.

Second, read the error message. No, really, read the whole thing. :-) I will guess that it says that "can't resolve symbol takeValueForKey on Object". Which is, like, totally true. java.lang.object does not have any takeValueForKey method. WODisplayGroup.selectedObject() returns Object:

public Object selectedObject()
Provides the first object from selectedObjects.

You need to cast:

((WebView)webViewDisplayGroup.selectedObject()).takeValueForKey("Hey, you clicked on the button", "headline");


But, honestly, that is freaking ugly and hard to read.  Why not just
webView().setHeadline("Hey, you clicked on the button");

Or, if you want to take values that the user typed in:



(yes, that is right, no code.  No that is not a typo).


Chuck


What is the correct way to do this.

Below is a simplified version of the page. The page works fine except for the line in question.


//
// AdjustPagePreview.java: Class file for WO Component 'AdjustPagePreview'
// Project ContentDB
//
// Created by paul on 6/27/07
//

import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoaccess.*;

public class AdjustPagePreview extends WOComponent {
    public WebView webView;
    public WODisplayGroup webViewDisplayGroup;


    public DeletePagePreview(WOContext context) {
        super(context);
    }
        
    public WebView webView() {
        return webView;
   }

    public void setWebView(WebView newWebView){
        webView = newWebView;
    }
        

    public EditPage2 doUpdates()
    {
        EditPage2 nextPage = (EditPage2)pageWithName("EditPage2");

// webViewDisplayGroup.selectedObject() has an attribute of "headline"
        // I want to change this data to something different
        // something like the line below

webViewDisplayGroup.selectedObject().takeValueForKey("Hey, you clicked on the button", "headline"); // line in question

//this obviously doesn't work. What is the correct way to change some of the attributes
        // before it is saved?
                                
        this.session().defaultEditingContext().saveChanges();
        
nextPage.webViewDisplayGroup.setSelectedObject ( webViewDisplayGroup.selectedObject() );

        return nextPage;
    }

}

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/chill% 40global-village.net

This email sent to [EMAIL PROTECTED]


--

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/products/practical_webobjects





_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to