Skip to main content

[webtier] inputField content gets lost when immediate is set for submit button

3 replies [Last post]
Anonymous

Hello,

I have a problem when using a list data model with Mojarra 1.2_12 and
mapping the contents of h:inputText fields to a map in this model. My
stripped down JSP looks like this:

The row data:

public class RowData
{
private Map contentMap = new HashMap();

public Map getContentMap() {
return contentMap;
}

public void setContentMap(Map contentMap) {
this.contentMap = contentMap;
}
}

And the backing bean:

public class TestBean
{
private DataModel model;

public DataModel getModel() {
if (model == null) {
final List list = new ArrayList();
list.add(new RowData());

model = new ListDataModel(list);
}

return model;
}
}

When submitting a form with the immediate attribute of the command button
set to "false" everything works as expected: The response page is rendered
and the h:inputText field still contains the same text that was present
before submitting the form.
But when the immediate attribute is set to "true" for the command button
the content of h:inputText is lost when the response is displayed.

I do not understand why setting immediate to "true" results in the input data
getting lost. My understanding is that all input values should have been
preserved.

If h:inputText is not contained in a h:dataTable, the data in the input field
are still present when the response is rendered. This is just like I expect
it. The input only gets lost for any h:inputField in the data table. Why?

Thank you for your help.

Best regards Uwe

--
-----------------------------------------------------------------------
Dr. Uwe Seimet http://www.seimet.de/

---------------------------------------------------------------------
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.
feichtegger
Offline
Joined: 2009-06-25
Points: 0

Hi Everbody,

I've a similar problem as Uwe has/had.
I want to add rows to my h:dataTable using an to skip validation. The data outside the table will be restored, in contrast to the data inside.

So how can you solve that issue using jsf without updating the model manually and not storing unvalidated and uncoverted data to the model.

kind regards
Michael

arveds
Offline
Joined: 2008-12-31
Points: 0

Hi, Uwe

Consider the fact that "immediate" operates in the Apply Request Values phase...for the component in question, the value from the request parameters (typically) is converted and validated, and that value is stored in the component.

Furthermore, components that implement ActionSource (JSF 1.2) will queue an ActionEvent if their "immediate" is true, which event will then be delivered at the end of the Apply Request Values phase.

Note that you have not yet done the Update Model Values phase for anything, and at the time that the event fires for the activated component (in your case a command button), none of the other components have even done conversion/validation - they only contain submitted "local" values (i.e. the request parameters or cookies).

This hopefully will help you answer your own question. Essentially, where your "missing" values are is still in the request parameters.

Typically the "immediate" property is used on a button to implement Cancel (or something similar), or in conjunction with a submit() in Javascript to update the page in response to a change in some component (where you haven't really filled out the form yet). And you probably would also be using bindings to the component in question to access the value.

HTH, Arved

Uwe Seimet

Hi Arved,

Thank you for your explanations.

> Note that you have not yet done the Update Model Values phase for anything, and at the time that the event fires for the activated component (in your case a command button), none of the other components have even done conversion/validation - they only contain submitted "local" values (i.e. the request parameters or cookies).

I see, but why does the content of my inputField inside the dataTable get lost
during the Apply Request Values phase, whereas the content of an inputField
outside the dataTable is preserved? Where does this difference in behavior
come from? I would expect *all* entered values to be preserved in the
rendered response, not just the values for inputFields placed outside a
dataTable.

Please have a look at this JSP, which has an inputText A outside a dataTable
and another inputText B inside a dataTable:







After submitting the form the content of the inputText A is still present
unchanged in the rendered response, but the content of the inputText B is
lost. I do not find any explanation for what appears an inconsistency to me.

Best regards Uwe

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