0

I have an inputText and a selectOneRadio component, when form load selectOneRadio should be hidden. When user select inputText, I want to show the selectOneRadio component. I have made the selectOneRadio hidden in @PostConstruct, which should be display on select inputText.

<h:panelGrid id="panelgrid">
    <p:panel id="panel" >
        <h:outputLabel value="Name: " for="name" />
        <p:inputText id="name" value="#{userBean.name}" immediate="true">
        <p:ajax event="onselect" update="city" listener="#{userBean.showName}" />
        </p:inputText>
        <p:selectOneRadio  id="city" value="#{userBean.city}" layout="grid" columns="3" rendered="#{userBean.displayName}" >
            <f:selectItems value="#{userBean.cities}" var="c" itemLabel="#{city}" itemValue="#{city}" />
        </p:selectOneRadio> 
    </p:panel>
</h:panelGrid>

The bean code is like:

@PostConstruct
public void init() {
    displayName = false;
}

public boolean isShowName() {
    return true;
}

...

But some how this is not working. I'm using JSF2.0 with primefaces 5.2.

Tiny
  • 27,221
  • 105
  • 339
  • 599
Sai prateek
  • 11,842
  • 9
  • 51
  • 66
  • 1
    Also look at http://jsf.zeef.com for other basic jsf related things and tutorials – Kukeltje Jun 23 '15 at 05:16
  • The question is bit different because this is showing event onselect not supported. – Sai prateek Jun 23 '15 at 05:32
  • Where does it show that? You nowhere mention that? Still yoy will face the other issue after that. And please use some showcases and documentation. The events are all in there – Kukeltje Jun 23 '15 at 05:34
  • Why exactly did you add `immediate="true"`? Where exactly did you "learn" about that? I'm seeing this increasingly on code snippets coming from starters. So there must be some source of misinformation which needs to be corrected. Or was you focusing on JSF 1.x resources instead of JSF 2.x resources for answers? – BalusC Jun 23 '15 at 06:54
  • Balus : is this link is sufficient? https://docs.oracle.com/cd/E19226-01/820-7627/bnari/ – Sai prateek Jun 23 '15 at 07:27

1 Answers1

0

I found the solution.

<h:form id="frm">
    <h:panelGrid id="panelgrid">
        <p:panel id="panel" >
        <h:outputLabel value="Name: " for="name" />
            <p:inputText id="name" value="#{userBean.name}" immediate="true" onkeypress="#{userBean.showName}">

                <p:ajax event="change" update="frm:panelgrid" listener="#{userBean.inputcangeeListener}" />
            </p:inputText>
        </p:panel>


            <p:panel id="p2" rendered="#{userBean.displayName}">
                <p:selectOneRadio id="city" value="#{userBean.city}" layout="grid" columns="3">
                    <f:selectItems value="#{userBean.cities}" var="c" itemLabel="#{city}" itemValue="#{city}" />
                </p:selectOneRadio>
            </p:panel>

        </h:panelGrid>
    </h:form>

And my managed bean looks like-

    @PostConstruct
    public void init() {
        displayName = false;
    }

    public boolean isShowName(){
        return displayName;
    }

    public void inputcangeeListener(javax.faces.event.AjaxBehaviorEvent changeEvent){
        setDisplayName(true);
        cities = new ArrayList<>();
        cities.add("pune");
        cities.add("KOL");

    }

Thanks for your response.

Sai prateek
  • 11,842
  • 9
  • 51
  • 66
  • Please mention in your answer WHAT and WHY this is a solution. What was wrong in your question... And remarkably, you fixed something that was in my duplicate link, but by updating the panelgrid, adding a panel p2 around the select was not needed. You can still change updating the panelgrid to updating p2 – Kukeltje Jun 23 '15 at 06:51