VMware Cloud Community
heikki_hyperic
Contributor
Contributor

HQU Plugin and Form Submit

I am trying to build an HQU plugin that has a form to ask some questions from the user, do some work when the user submits and display a response. There are two views and two methods in the controller. In pseudocode this is what I am trying to do:

controller:


class MyController extends BaseController

def index(params) {

render()

}


def result(params) {

// check form values, make remote call, display result page

render(locals:[ myResult: 'Success'])

}


index.gsp:


<form action="/hqu/myplugin/mycontroller/result.hqu" method="post">

// some fields

<input name="commit" type="submit" value="Submit">

</form>


result.gsp:

<p>${myResult}</p>

Plugin.groovy:


addView(description: 'My Plugin,

attachType: 'admin',

controller: MyController,

action: 'index',

category: 'tracker')


My plugin is listed on the Administrator page, and the index page gets rendered fine. But when I hit the submit button, I get a stack trace that has:

groovy.lang.MissingPropertyException: No such property: myResult for class: Script1 at

Q1: Why isn't myResult available in the gsp even though I pass it in the render() call (hmm, is the result method even called at all I wonder)?

Q2: If I make the result.gsp "<p>Hello<p>" I do get a page. However, it is a standalone page (not wrapped in Hyperic header and footer like the index.gsp page). Is there any way to get this result page also wrapped like the index page?

0 Kudos
5 Replies
heikki_hyperic
Contributor
Contributor

Q1 is actually different from what I originally thought. The issue is that the values I pass in locals to render() don't get updated like I expected. For example if I change myResult to "Failure", this does not get updated unless I restart Hyperic. Also if I add a new entry to locals, this does not get picked up unless I restart Hyperic. However, if I have an entry for locals that uses a variable, and I pick up the value for the variable from the submitted form values for example, then this value does end up in the result.gsp as I expected (without needing to restart).
0 Kudos
admin
Immortal
Immortal

Hello Heikki,

POSTS or any links which navigate to other HQU pages will not
necessarily be wrapped up in the HQ UI (Q2). I would suggest you
take a look at using AJAX style calls like what is done in the
gconsole code. Simply execute the AJAX method on the server, then
innerHtml the response that it gives you. This will keep things
wrapped up nicely and provide the illusion of page navigation.

-- Jon




On May 29, 2008, at 12:37 PM, Heikki Toivonen wrote:

>

I am trying to build an HQU plugin that has a form to ask some
> questions from the user, do some work when the user submits and
> display a response. There are two views and two methods in the
> controller. In pseudocode this is what I am trying to do:
>
>

controller:

>
> class MyController extends BaseController

> def index(params) {

> render()

> }

>
> def result(params) {

> // check form values, make remote call, display result page

> render(locals:[ myResult: 'Success'])

> }

>
>

index.gsp:

>
> <form action="/hqu/myplugin/mycontroller/result.hqu"
> method="post">

> // some fields

> <input name="commit" type="submit" value="Submit">

> </form>

>
>

result.gsp:
>
> <p>${myResult}</p>
>
>

Plugin.groovy:

>
> addView(description: 'My Plugin,

> attachType: 'admin',

> controller: MyController,

> action: 'index',

> category: 'tracker')

>
>

My plugin is listed on the Administrator page, and the index
> page gets rendered fine. But when I hit the submit button, I get a
> stack trace that has:
>
> groovy.lang.MissingPropertyException: No such property: myResult
> for class: Script1 at
>
>

Q1: Why isn't myResult available in the gsp even though I
> pass it in the render() call (hmm, is the result method even called
> at all I wonder)?
>
>

Q2: If I make the result.gsp "<p>Hello<p>" I do
> get a page. However, it is a standalone page (not wrapped in
> Hyperic header and footer like the index.gsp page). Is there any
> way to get this result page also wrapped like the index page?


0 Kudos
admin
Immortal
Immortal

You should never need to restart HQ when making changes to your
plugins. Have you checked out redeploying your plugin via ant hqu-
redeploy-plugin?

ant hqu-redeply-plugin -Dplugin=myplugin

-- Jon


On May 29, 2008, at 2:26 PM, Heikki Toivonen wrote:

> Q1 is actually different from what I originally thought. The issue
> is that the values I pass in locals to render() don't get updated
> like I expected. For example if I change myResult to "Failure",
> this does not get updated unless I restart Hyperic. Also if I add a
> new entry to locals, this does not get picked up unless I restart
> Hyperic. However, if I have an entry for locals that uses a
> variable, and I pick up the value for the variable from the
> submitted form values for example, then this value does end up in
> the result.gsp as I expected (without needing to restart).


0 Kudos
heikki_hyperic
Contributor
Contributor

Ok, I'll look into doing this with AJAX. Thanks for the clarifications.

The way I am currently developing is by having installed the production version of the latest stable Hyperic. I don't see how I could use ant to redeploy my plugin with that. I am developing the plugin in an svn tree, and have put a symlink in the Hyperic plugin deployment directory. The setup was fine for a little experimentation but now the need to restart Hyperic has become a real drag so I guess I'll need to look at other ways to do this.
0 Kudos
heikki_hyperic
Contributor
Contributor

Figured out how to redeploy the plugin without needing to restart Hyperic. rm plugindir, wait a couple of secs, recreate symlink.
0 Kudos