Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with value of component initially rendered="false"

843844Aug 19 2010 — edited Aug 20 2010
I'm unable to make initially invisible input component set it's value to the bound bean's property after I make it visible by some ajax update.
If component initially was visible (rendered="true") everything is ok. But if it initially was rendered="false" and I make it visible by some ajax request jsf doesn't apply new value from this component on submit.

I noticed that request has appropriated parameter but it is ignored during update values phase.

I use Mojarra 2.0.2 with Jetty 6

Is it the JSF bug or I miss something?

Thank you in advance.

Below my simple test case:

My hiddentest.xhtml:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</h:head>

<h:body>
	<h:form prependId="false">
		<center>


	Screen Type 
          <h:selectOneMenu value="#{hiddenTestBean.screenType}" 
				id="screenType">
	 	<f:selectItem itemLabel="" itemValue="" />
		<f:selectItem itemLabel="First" itemValue="1" />
		<f:selectItem itemLabel="Second" itemValue="2" />
	
        	<f:ajax render="@all" />
	 </h:selectOneMenu>
	
         <br />
	<h:inputText id="first" 
                           value="#{hiddenTestBean.first}" 
                           rendered="#{hiddenTestBean.screenType == '1'}" 
                           style="background-color: yellow;"/>

	<h:inputText id="second" 
                           value="#{hiddenTestBean.second}" 
                           rendered="#{hiddenTestBean.screenType == '2'}" 
                           style="background-color: green;"/>
						
         <h:commandButton value="Submit">
			<f:ajax execute="@all" render="result" />
	</h:commandButton>
					
	<br />
						
	<h:outputText id="result" value="#{hiddenTestBean.info}"/>  
		
		</center>
	</h:form>
</h:body>
</html>
And HiddenTestBean.java
package test;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class HiddenTestBean {

	private String screenType;

	private String first;

	private String second;

	public String getScreenType() {
		return screenType;
	}

	public void setScreenType(String screenType) {
		this.screenType = screenType;
	}

	public String getFirst() {
		return first;
	}

	public void setFirst(String first) {
		this.first = first;
	}

	public String getSecond() {
		return second;
	}

	public void setSecond(String second) {
		this.second = second;
	}

	public String getInfo() {
		if ("1".equals(getScreenType())) {
			return "First is: " + getFirst();
		} else if ("2".equals(getScreenType())) {
			return "Second is: " + getSecond();
		} else {
			return "Unknow";
		}
	}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 17 2010
Added on Aug 19 2010
1 comment
66 views