participate


JavaServer Faces - Bug of JSF spec?
This question is answered. Correct Answer available

<<   Back to Forum  |   Give us Feedback
This topic has 13 replies on 1 page.
nossie
Posts:7
Registered: 10/28/08
Bug of JSF spec?   
Oct 29, 2008 12:13 AM
 
 
I am not good at English. But but... please hear my JSF Problem.

<h:form>
    <h:inputText id="input1" required="#{true}"/>
    <h:message for="input1"/>
    <h:inputText id="input2" value="#{testBean.value}">
        <f:convertNumber integerOnly="true"/>
    </h:inputText>
    <h:message for="input2"/>
    <h:commandButton/>
</h:form>


From browser:
1.Input empty string at input1. (this cause validation error.)
2.Input empty string at input2. (convet to null.)
3.Click commandButton.

I hope:
Display value at input2 is empty string. (My input value is keeped.)

But result is:
Display value at input2 is "#{testBean.value}". (My input value is forgotten...)

In my research:
1.converter converts empty string to null.
2."local value" is set to null.
3.Go to Rnder Response Phase By Input1 validation error.
4.getValue ignore "local value" if it is null and see VE.

Uhh... Why getValue method doesn't see isLocalValueSet?
I can't understand... Please Help me...
 
zmarr
Posts:36
Registered: 8/21/08
Re: Bug of JSF spec?   
Oct 31, 2008 1:43 PM (reply 1 of 13)  (In reply to original post )
 
 
If there is a validation error, the JSF lifecycle will skip updating the model and go directly to the render response phase.

Therefore, no values will go into the model from the submitted form if a required field is empty.

This is the whole point of validation. Nothing should be updated in the model until all incoming data is successfully validated.
 
nossie
Posts:7
Registered: 10/28/08
Re: Bug of JSF spec?   
Nov 1, 2008 6:59 AM (reply 2 of 13)  (In reply to #1 )
 
 
Thank you for your reply!

This is the whole point of validation. Nothing should be updated in the model until all incoming data is successfully validated.

Model is updated if and only if validation success perfectly.
Yes It's important. I see.
And I think that there is similarly an important thing.

It is that:

if JSF failed at validation, user input values should be kept. if so user can re-create previous request immediately(with some fixes).

But a part of actual reponse is based on model values(unupdated)!!

This phenomenon occur at time when user input empty text. && Converter converts the empty text to null. && VE is set. (&& failed at validation). Result: values from VE is responsed. User input values(empty text) is disappeared...!!

How do you seem about this?

Sorry My poor poor English...
And Thank you*100 for reading!!
 
BalusC
Posts:29,957
Registered: 26/04/06
Re: Bug of JSF spec?   
Nov 1, 2008 11:02 AM (reply 3 of 13)  (In reply to original post )
 
 
I can't seem to reproduce your problem here with JSF 1.2_10 at Tomcat 6.0.18. I may not have understood your problem, or you're using a different JSF impl/version and/or appserver impl/version which may behave differently.

Here's the code I used to test it:

JSF
<h:form>
    <h:inputText id="input1" value="#{myBean.input1}" required="true" />
    <h:message for="input1" />
    <h:inputText id="input2" value="#{myBean.input2}">
        <f:convertNumber integerOnly="true" />
    </h:inputText>
    <h:message for="input2" />
    <h:commandButton value="submit" action="#{myBean.submit}" />
</h:form>

MyBean (request scoped)
private String input1; // +getter +setter
private Integer input2; // +getter +setter
 
public void submit() {
    System.out.println("submitted input1: " + input1);
    System.out.println("submitted input2: " + input2);
}

There are 6 different test cases possible:

1) Leave both fields empty and hit submit button.
A 'required' error for input1 is displayed. Both fields are still empty. Submit method is not invoked.

2) Enter input1 and leave input2 empty and hit button.
The submit method is invoked and prints entered value of input1 and null for input2. The input1 value is still displayed and input2 is still empty.

3) Leave input1 empty and enter input2 with valid number and hit button.
A 'required' error for input1 is displayed. The input1 value is still empty. The input2 value is still displayed. Submit method is not invoked.

4) Leave input1 empty and enter input2 with invalid number and hit button.
A 'required' error for input1 is displayed. A 'not a number' error for input2 is displayed. The input1 value is still empty. The input2 value is still displayed. Submit method is not invoked.

5) Enter input1 and enter input2 with valid number and hit button.
The submit method is invoked and prints entered value of both input1 and input2. The both field values are still displayed.

6) Enter input1 and enter input2 with invalid number and hit button.
A 'not a number' error for input2 is displayed. The input1 value is still displayed. The input2 value is still displayed. Submit method is not invoked.

Anything just went as expected.

By the way, the f:convertNumber is superfluous if the property is already a Number (e.g. Integer). Even after removing the f:convertNumber from input2, anything went exactly as described before.
 
nossie
Posts:7
Registered: 10/28/08
Re: Bug of JSF spec?   
Nov 1, 2008 1:59 PM (reply 4 of 13)  (In reply to #3 )
 
 
I try JSF1.2_10 Manually upgrading steps in Release Note to Sun App Server.

But same phenominon is occur.

Maybe my English is poor and short...
Thank you for the very kind 6 different test cases.
At 1) case, and Additionary MyBean's field input2 has non-null initial value!

So...
private Integer input2 = 1; // +getter +setter


In this case...
A 'required' error for input1 is displayed.
And input2 displays "1". (not empty text !)
Submit method is not invoked.

By the way, the f:convertNumber is superfluous if the property is already a Number (e.g. Integer). Even after removing the f:convertNumber from input2, anything went exactly as described before.

Wow!!!!! I don't know this chips!! JSF see Managed Bean's field type !??
And convert automatically !??? cool !!!
 
BalusC
Posts:29,957
Registered: 26/04/06
Re: Bug of JSF spec?   
Nov 1, 2008 6:36 PM (reply 5 of 13)  (In reply to #4 )
 
 
nossie wrote:
In this case...
A 'required' error for input1 is displayed.
And input2 displays "1". (not empty text !)
Submit method is not invoked.

This is just the expected behaviour.
What did you expect? That input2 disappears or so?

Wow!!!!! I don't know this chips!! JSF see Managed Bean's field type !??
And convert automatically !??? cool !!!

It's the application server's EL implementation which does that for you. EL recognizes at least String, Number and Boolean types. This 'phenomenon' is called EL type coercion.
 
nossie
Posts:7
Registered: 10/28/08
Re: Bug of JSF spec?   
Nov 2, 2008 9:38 AM (reply 6 of 13)  (In reply to #5 )
 
 
This is just the expected behaviour.
What did you expect? That input2 disappears or so?

Yes! Yes! I think input2 text shoud disappear !
If validation is failed, user input values should be re-rendered.
I beleave It is natural and user-friendly!!

But JSF spec is not so...

Uhh... there is deep reflection that I can't notice.....?
 
BalusC
Posts:29,957
Registered: 26/04/06
Re: Bug of JSF spec?   
Nov 2, 2008 3:10 PM (reply 7 of 13)  (In reply to #6 )
 
 
nossie wrote:
Yes! Yes! I think input2 text shoud disappear !
If validation is failed, user input values should be re-rendered.

That's contradictory what you say there.

You said that it should disappear. But you also said that it should be (re)rendered.

What do you expect?

I beleave It is natural and user-friendly!!

It's better for user experience if the input values doesn't disappear, so that the user can see what s/he has filled in.
 
nossie
Posts:7
Registered: 10/28/08
Re: Bug of JSF spec?   
Nov 3, 2008 5:01 AM (reply 8 of 13)  (In reply to #7 )
 
 
Sorry my poor poor english!!
I must go english schol... very expensive :'-(

I say "user input values should be (re)rendered" when I mean "if user input empty text, JSF also should render empty text (not managed bean value)".

In JSF if validation is failed:
User inputs empty text. -> render managed bean value.
User inputs other text. -> render input text.

Uhhn... there is no consistency...?

In my assumption if validation is failed:
User inputs empty text. -> render inputed text.(empty text)
User inputs other text. -> render inputed text.
 
BalusC
Posts:29,957
Registered: 26/04/06
Re: Bug of JSF spec?   
Nov 3, 2008 5:29 AM (reply 9 of 13)  (In reply to #8 )
Correct
 
Oh I now see what you mean.

You assign a default non-null value to input2. This value is displayed in the form. When user removes it and submits the form, then a 'required' error for input1 is displayed, but input2 redisplays the default value instead of submitted value.

Well, that's indeed undesirable behaviour. You may want to report an issue at http://javaserverfaces.dev.java.net.

A workaround for this problem may be the following in the constructor of the bean:

public MyBean() {
    if (!FacesUtil.isPostBack()) {
        this.input2 = 1;
    }
}
public static boolean isPostback() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    return facesContext.getRenderKit().getResponseStateManager().isPostback(facesContext);
}

The isPostback() returns true on form submit only.
 
nossie
Posts:7
Registered: 10/28/08
Re: Bug of JSF spec?   
Nov 3, 2008 12:08 PM (reply 10 of 13)  (In reply to #9 )
 
 
You assign a default non-null value to input2. This value is displayed in the form. When user removes it and submits the form, then a 'required' error for input1 is displayed, but input2 redisplays the default value instead of submitted value.

Yes! Yes! Thank you for reading!! and great third eye!! for my poor English!!

Well, that's indeed undesirable behaviour. You may want to report an issue at http://javaserverfaces.dev.java.net.

Oh!!! I can stop worrying.
I feared that there is deep reflection that I can't notice.

About Reporting an issue...?
I'm worried about my english skill.
I think it may need specially good words for issue searcher.

A workaround for this problem may be the following in the constructor of the bean:

Wow! smart and simple!
I often use isPostback. But No Idea it use in this case!!
Thank you * 1000!!!
 
RaymondDeCampo
Posts:2,616
Registered: 08/06/03
Re: Bug of JSF spec?   
Nov 3, 2008 12:10 PM (reply 11 of 13)  (In reply to #10 )
 
 
nossie wrote:
You assign a default non-null value to input2. This value is displayed in the form. When user removes it and submits the form, then a 'required' error for input1 is displayed, but input2 redisplays the default value instead of submitted value.

Yes! Yes! Thank you for reading!! and great third eye!! for my poor English!!

Well, that's indeed undesirable behaviour. You may want to report an issue at http://javaserverfaces.dev.java.net.

Oh!!! I can stop worrying.
I feared that there is deep reflection that I can't notice.

About Reporting an issue...?
I'm worried about my english skill.
I think it may need specially good words for issue searcher.

Don't worry about your English skills. Write it up as best you can and include a link to this thread. I think the problem is clear enough.


A workaround for this problem may be the following in the constructor of the bean:

Wow! smart and simple!
I often use isPostback. But No Idea it use in this case!!
Thank you * 1000!!!
 
nossie
Posts:7
Registered: 10/28/08
Re: Bug of JSF spec?   
Nov 3, 2008 2:47 PM (reply 12 of 13)  (In reply to #11 )
 
 
OK! I challenged!! Thank you for the encouragement!

This link is for issue.
https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=838
 
kwin10
Posts:1
Registered: 3/7/06
Re: Bug of JSF spec?   
Nov 19, 2008 12:37 PM (reply 13 of 13)  (In reply to #9 )
 
 
Unfortunately I've had no luck with this solution. In my case I am performing a search using a session scope bean. My results are listed in a dataTable and I have an actionListener on a request scoped bean. All of that works fine.

faces-config.xml
<managed-bean>
	<managed-bean-name>searchBean</managed-bean-name>
	<managed-bean-class>com.package.SearchBean</managed-bean-class>
	<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
	<managed-bean-name>detailBean</managed-bean-name>
	<managed-bean-class>com.package.DetailBean</managed-bean-class>
	<managed-bean-scope>request</managed-bean-scope>
</managed-bean>


public class DetailBean
{
	private String field1;
	private String field2;
	//Bind the dataTable component to the controller
	protected transient UIData dataTable;
	//The object used to populate the row in the table that was selected
	protected transient Object row;
 
	public DetailBean()
	{
		super();
		FacesContext facesContext = FacesContext.getCurrentInstance();
		Boolean isPostback = facesContext.getRenderKit().getResponseStateManager().isPostback(facesContext);
		if(!isPostback) //always seems to be true
		{
			if(dataTable != null)
			{
				row = dataTable.getRowData();
			}
		}
	}	
 
	public void detail(ActionEvent event)
	{
		row = dataTable.getRowData();
		if(row != null)
		{
			Map<String,String> record = (Map<String,String>)row;
			setField1(record.get("field1"));
			setField2(record.get("field2"));
		}
	}
 
	public String edit()
	{
		//do the edit
 
		return "success";
	}


<h:inputText id="field1" value="#{detailBean.field1}" required="true"/>
<h:inputText id="field2Input" value="#{detailBean.field2}"/>
<h:outputText id="field2Text" value="#{detailBean.field2}"/>
<h:inputText id="field2Hidden" value="#{detailBean.field2}"/>
<h:commandLink id="edit" action="#{detailBean.edit}" value="edit"/>
<h:messages errorStyle="color:red" showSummary="true"/>


The values from the table are successfully populated and the page is shown with the values:
field1=test1
field2Input=test2
field2Text=test2
field2Hidden=test2


when I clear field1 (required) and submit I have the following:

field1=
field2Input=test2
field2Text=
field2Hidden=test2
 
message about field1 being required


I would expect field2Text to still retain the value.

Furthermore if I set the field2Text to readonly="true", it, too, does not retain its value. However in both cases once the required field has a value and is submitted, all values show as expected.

My only workaround for this is to set my detailBean session scope, but that avoids the problem.
 
This topic has 13 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 28
  • Guests : 129

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums