Modal dialog : How to "toggle" manually

Hello,

I think my problem is pretty simple but could not find the solution so far. I miss the logic I think.

Here is the context :
I have a “Portlet application” composed of 3 portlets.

The purpose of those three portlet are :

  • search & show complaints instances
  • an attachment panel (for files)
  • submittion of new complaint via a form

In that last portlet I have :

  • several forms
  • one modal dialog

Problem description :
My concern is the following. When I submit the form to send a new complaint instance I do some checks before sending the complaint via WS (giving the opportunity for the user to modify some values if they are wrong).

If the complaint is sent correctly, I would like to show the modal dialog saying that the complaint was sent correctly with a link to the same portlet reseting the state (erase all data filled so far for a new instance of complaint).

If I set up the AsyncCommandButton which submit the form with my modal dialog in the “toggle” field, the modal dialog is showed in all cases (even if there is a problem).

My AsyncCommandButton execute a custom action. I tried to toggle the modal dialog manually in that action but could not find how.

I’m searching into two ways :

  • the first one is a specific return of the custom action that disabled the toggle function of the button automatically (tried to throw exception, return “OUTCOME_ERROR”…)
  • the second one is to find a way to toggle manually via java code the modal dialog (tried to find the toggle function of the asyncommandbutton, tried to add a toggle button non visible and call the toggle function, …)

No luck so far for both ways.
If someone could give me some ligths on this matter, I’d appreciate.

Regards,
Mathieu

Hi Mathieu,
i suppose that one option would be to check (in the “click” javascript event) what is the WSC result and toggle the dialog accordingly. For this you can add an “ActionCompleteListener” to the Async Command Button that makes this check. Have a look in [url]http://tech.forums.softwareag.com/viewtopic.php?t=15226&start=0&postdays=0&postorder=asc&highlight=&C=30[/url].
hope this helps,
Javier

p.s.: the updated link to the javascript docu is [url]http://techcommunity.softwareag.com/ecosystem/documentation/webmethods/wmsuite8_ga/My_webMethods_and_Task_Engine/8-0-SP1_CAF_JavaScript_Reference/index.html[/url]

Thx Javier,

I tried the javacript approach which I’m not good with :slight_smile:

It worked for making visible the modal dialog but at the same time the behaviour changed. I’m a bit lost.

Here is the javascript I put :


/* Java Script Block */
CAF.model('#{activePageBean.clientIds["buttonSubmitComp"]}').addActionCompleteListener(
function (commandID) { 
	if ( CAF.model('#{activePageBean.clientIds["checkSubmit_label"]}').getValue() == "1")  {
	 	CAF.model('#{activePageBean.clientIds["modalDialog"]}').toggle();
	}
}
); 

Not optimized but works.

The modal dialog is toggled only when the custom action set the value of the checkSubmit_label to “1”. That part is OK.

But now when I click on the “portlet simple link” of the modal dialog the state of the portlet isn’t reseted anymore and I don’t understand why. I can still access to the old value.
The properties “reset state” of the extended portlet url is set to “true” just like before.

Regards,
Mathieu

Hi,
I am not sure if the “Reset State” is meant to reset the content of your portlet (i have never used that attribute).
One way you may try is to assign the “Apply” button of your dialog button to an action in your view bean where you reset your managed beans. And a way of resetting them is to re-instantiate them (I don’t know if this is the best way, but it works). It could be something like:

public String resetComplaintBean() {
  // simple bean... no initialization done in faces-config.xml
  myComplaintBean = new Complaint();
  // input for a WSC
  getMyServiceWSC().getParameters().setMyInput(null);
}

One more thing, you can add the actionCompleteListener to a Script Block like:

// Add actionCompleteListener only once when page is loaded
Event.observe(window, 'load', function() {
	CAF.model('#{caf:cid('evaluate-input-acb')}').addActionCompleteListener(function(id) {
		var resultCodeInput = CAF.model('#{caf:cid('result-code-input')}').getValue();
		if (resultCodeInput == "OK") {
			CAF.model('#{caf:cid('modalDialog')}').show();
		}
	});
});

so that it is only added once to the button.

best regards,
Javier

Thank you for the useful tips !

I’ll try it on Wednesday (I can’t before) and let you know the outcome.

Regards,
Mathieu

Hello Javier,

Again, thank you for all the help up to this point.
At the moment it is not working properly (the reset part) but it should be a mistake in the implementation on my part. So I’ll work on it.

I just would like to make sure that I used the correct words before for describing my needs.
The submittion complaint portlet is composed of 3 differents forms (not sub form). Each form use one or more WSC but also has some fields / controls not linked to a WSC.

To put an image : the expected result would be the same as “redeploying my portlet and then refreshing my browser”. The portlet is ‘blank’ on the first access (fields, controls, WSC, panel focused …).

Before using javascript to toggle my modal dialog, the “portlet simple link” was fulfilling that behavior.
Does the hint you gave me could behave like this (without manually resetting all values) ?

Thx a lot,
Mathieu

Hi

I have a similar problem, but currently I’m not able to:

In the server side action I want that in error case to show a message in the dialog.
However, I can I set in the server side the control value so that I can fetch this value then in the actionCompleteListener ?

Thanks

Can you add a messages control to the modal dialog and then refresh that control after submitting?

That way you won’t have to do as much scripting.