Hi Kiran,
Thank you for the reply. I managed to get the code through the site
dynamically adding components
But the problem is It shows error .
This is my
jsp code
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<f:view>
<h:form>
<h:selectOneRadio id="category"
value="#{binding.valueOfRadio}"
immediate="true"
onclick="submit()">
<f:selectItem id="article" itemLabel="Article" itemValue="article"/>
<f:selectItem id="subscriber" itemLabel="Subscriber" itemValue="subscriber"/>
<f:valueChangeListener type="#{binding.radioButton}" />
</h:selectOneRadio>
<h:outputText value="article" binding="#{binding.articleOutputText}"/>
<h:outputText value="subscriber" binding="#{binding.subscriberOutputText}"/>
</h:form>
</f:view>
</body>
</html>
This is my
java code
public class binding implements ValueChangeListener
{
private
String valueOfRadio;
private String valueOfInput;
UIComponent radioButton = new HtmlSelectOneRadio();
UIComponent articleOutputText = new HtmlOutputText();
UIComponent subscriberOutputText = new HtmlOutputText();
{
articleOutputText.setRendered(false);
subscriberOutputText.setRendered(false);
}
/** Creates a new instance of binding */
public binding()
{
}
public String getValueOfInput() {
return valueOfInput;
}
public void setValueOfInput(String valueOfInput) {
this.valueOfInput = valueOfInput;
}
public String getValueOfRadio()
{
return valueOfRadio;
}
public void setValueOfRadio(String valueOfRadio)
{
this.valueOfRadio = valueOfRadio;
}
public UIComponent getArticleOutputText()
{
return articleOutputText;
}
public void setArticleOutputText(UIComponent articleOutputText) {
this.articleOutputText = articleOutputText;
}
private void encodeInputText(FacesContext context)
{
HtmlInputText inputText = new HtmlInputText();
try
{
inputText.encodeBegin(context);
inputText.encodeEnd(context);
context.renderResponse();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public UIComponent getRadioButton()
{
FacesContext context = FacesContext.getCurrentInstance();
ValueChangeEvent event = new ValueChangeEvent(radioButton, this, this);
Object value = event.getNewValue();
System.out.println("Value "+event.getNewValue());
setValueOfRadio(event.getNewValue().toString());
if(value.equals("article"))
{
articleOutputText.setParent(radioButton);
articleOutputText.setRendered(true);
subscriberOutputText.setRendered(false);
}
else
{
encodeInputText(context);
articleOutputText.setRendered(false);
subscriberOutputText.setRendered(true);
subscriberOutputText.setParent(radioButton);
}
context.renderResponse();
return radioButton;
}
public void setRadioButton(UIComponent radioButton) {
this.radioButton = radioButton;
}
public UIComponent getSubscriberOutputText() {
return subscriberOutputText;
}
public void setSubscriberOutputText(UIComponent subscriberOutputText) {
this.subscriberOutputText = subscriberOutputText;
}
public void processValueChange(ValueChangeEvent event) throws AbortProcessingException {
throw new UnsupportedOperationException("Not supported yet.");
}
}
Can you figure it out why?