Skip to main content

[webtier] Setting initial inputarea contents from request parameters

2 replies [Last post]
Anonymous

Hello,

Is there a good way to set the initial content of an h:inputTextarea field
with values provided as request parameters?
The background of this question is that my h:inputTextarea should not be
empty the first time it is rendered, but should already contain an
initial content. This initial content is generated in the previous
request, a navigation rule with an external redirect displays the new
page with my inputTextarea. Can I somehow add (as a request parameter)
data to a request that will automatically be used to initially fill out
my h:inputTextarea?

Best regards Uwe

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jkva
Offline
Joined: 2005-04-06
Points: 0

Yes of course. If you use JSF 1.2, you can read the parameter from the request in a managed bean method annotated with @postconstruct and put it in a managed bean property. From there it is easy to show it on your page.

On a pre-1.2 deployment, you can just put the logic in your bean, like this:

class MyManagedBean {
private String someText;

String getSomeText() {
if (someText == null) {
someText = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("the_parameter_name");
}

return someText;
}

setSomeText(String s) {
this.someText = s;
}

}

In your page you can then use the expression #{myManagedBean.someText}.

You just have to watch out with special characters in your request parameters and encoding, but that isn't really related to JSF.

You can even fill your textarea from the JSP/Facelet, by using this expression #{param.the_parameter_name}, but with this option, you can't bind your textarea to a managed bean property.

Or do you mean something else???

Cheers,

Jan-Kees van Andel

Uwe Seimet

> Yes of course. If you use JSF 1.2, you can read the parameter from the request in a managed bean method annotated with @postconstruct and put it in a managed bean property. From there it is easy to show it on your page.

Yes, I use JSF 1.2, so this approach looks good to me. Thank you!

Cheers Uwe

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net