में grails g.link का उपयोग नहीं कर सकता है मेरे पास एक डोमेन क्लास में स्थैतिक विधि है जो एक यूआरएल देता है। मुझे उस यूआरएल को गतिशील रूप से बनाने की जरूरत है, लेकिन g.link काम नहीं कर रहा है।डोमेन क्लास
static Map options() {
// ...
def url = g.link(controller: "Foo", action: "bar")
// ...
}
मैं निम्नलिखित त्रुटियाँ मिलती है:
Apparent variable 'g' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
You attempted to reference a variable in the binding or an instance variable from a static context.
You misspelled a classname or statically imported field. Please check the spelling.
You attempted to use a method 'g' but left out brackets in a place not allowed by the grammar.
@ line 17, column 19.
def url = g.link(controller: "Foo", action: "bar")
^
1 error
जाहिर है मेरी समस्या यह है कि मैं स्थिर संदर्भ से g
का उपयोग करने की कोशिश कर रहा हूँ, इसलिए मैं इस के आसपास कैसे मिलता है है?
एक स्थिर दायरे में ऐसा मत करो: सबसे अच्छा तरीका है शायद वह आपके डोमेन वर्ग के
domainClass
संपत्ति बंद हड़पने के लिए है। एक उदाहरण विधि का प्रयोग करें, या इससे भी बेहतर, इस कोड को एक सेवा में रखें ताकि इसे इंजेक्शन दिया जा सके। – OverZealousमेरे पास ऐसा कोई उदाहरण नहीं है जब मैं यह कर रहा हूं। – ubiquibacon
हाँ, मैं अति उत्साही से सहमत हूं। इस तरह से ऐसा करने के लिए वास्तव में बुरा विचार है। – Gregg