How to PASS parameters in a CAF Form

Okay my example is pretty simple. I’m not trying to call a webservice (that you drop into a form), I have a FORM with two (2) Text Input controls.

I added a Button I labeled “Submit” and gave it a value of “Hello.view”. I want to send the the two (2) Text Input control DATA to another view.

What happens is that when I enter DATA into the Text Input controls, that data never gets sent over to my VIEW.

At first I thought it was because I did NOT bind a variable. So I added a “Managed Bean” and added to it TWO (2) properties (both Strings). Then I dragged the two properties into each Text Input control.

So now when I click on Text Input control #1, I see #{HomeView.HomeParams.param1} and Text Input control #2 (#{HomeView.HomeParams.param2}).

But what this does is only provide INITIAL values for the two controls. When I TYPE a NEW value, it never gets COPIED back to my properties.

In my 2nd view (“hello.view”) all I did was put two Text - Basic Text and bind them to #{HelloView.HomeParams.param1} and #{HelloView.HomeParams.param2}. And don’t worry the Managed Bean was set to SESSION, so my “Hello.view” sees the Managed Bean.

So somehow I need to know how the Text Input controls GET COPIED BACK into the Managed Bean Properties…

Can someone shed some light? I have been following the CAF Exercises - a colleague says that the answer is there, but he doesn’t know where…

IF I HARDCODE the values using either “Data Binding”, the hardcoded values appear correctly. OR if I HARDCODE via faces-config.xml (Managed Bean Tab), those values also appear.

BUT NEVER the values I INPUT into the control itself…

Many thanks,

Kris

Update: I have added a webservice call with two (2) parameters.

When I leave it AS IS, there is no default value and when you type something, when you click on the REFRESH button, the webservice is called and it works okay.

BUT if I substitute the param for my own Input Text control, the default value APPEARS, however when you click on REFRESH button, it’s as if the parameter was BLANK (when the webservice is called).

Very strange indeed.

Anyone care to give this a TRY??? 8)

Hi Kristopher:

Try this

Save the data in Session (1st portlet)


IContext context = ContextFactory.acquireContext(true);

String userID = "anyUserID";

context.setAttribute("userID", userID, IContext.SCOPE_SESSION);

Recover (2nd portlet)


IContext  context = ContextFactory.acquireContext(false);	
String userID = (String)context.getAttribute("userID", IContext.SCOPE_SESSION);

Hope this help

Regards.

Hi Norberto,

What methods do I need to add these snippets of code to???

I’m not working with Portlets - FYI. I am trying to create a simple form that can PASS two Parameters to another VIEW. Not rocket science… But everything seems to be difficult with CAF.

If you don’t generate & doctor, things do seem to work…

Also I wanted to emulate a synchronous web page call. So one form to get data, one page to process it.

I know this is not the way CAF was intended to work… Or so it seem! :frowning:

Hi Kris

How do you create these forms? Can you provide some screenshots or attach your project?

Regards.

Hi Norberto,

Import the ZIP MWS project. It’s called SampleWebApplication. Choose the home_backup.view.

That’s the one that is stripped-down to the basic form with 2 params. I want to pass them to hello.view.

Right now the default values are HARD-CODED. But if you input your own content in either text input, those values get ignored…
SampleWebApplication.zip (87.3 KB)

In general, sharing values between two pages could be done in many ways.

For a standalone webapp (not a portlet), the most straight forward ways could include:

  1. server-side sharing of the data. In this case you would have some session scoped managed bean that contains the fields you want to share. Both pages reference this same field from this shared managed bean instead of each page having their own copy.

  2. appending request parameters to the page you are redirecting to. For example, bind the action property of the command button to a method that does something like this:

	/**
	 * Action Event Handler for the control with id='htmlCommandButton'
	 */
	public String htmlCommandButton_action() {
		return String.format("/hello.view?faces-redirect=true&myparam1=%s", getLocalField1());
	}

Then when the second page renders, it can get the request parameters and copy the values into the local field you want them in for the second page. For example, something like this in the page bean of the second page:

	/* (non-Javadoc)
	 * @see com.webmethods.caf.faces.bean.BaseViewBean#afterRestoreView()
	 */
	@Override
	protected void afterRestoreView() {
		String value = (String)resolveExpression("#{param.myparam1}");
		if (value != null) {
			setLocalField2(value);
		}
		super.afterRestoreView();
	}

For your reference, I’ve attached the source code of a simple CAF web project that demonstrates both of these techniques.
passparams_test.zip (16.2 KB)

Hi Kris,

You may follow the guidelines posted by Eric.

Best regards.