render items with p:ajax

UI Components for JSF
Post Reply
Vikky
Posts: 7
Joined: 11 Jan 2011, 14:07

11 Jan 2011, 14:17

Hello,
I would like to have a question. I`m trying to render two input fields depending on a value chosen in select list, but they won`t render. Any help would be really appreciated.

Here is what I`m trying in view:

Code: Select all

    
        <h:selectOneMenu id="role"  value="#{maxUserMBean.vybranaRole}" 
                                     converter="maxRoleConverter" >
                        <f:selectItems value="#{maxRoleController.itemsAvailableSelectOne}" />
                        <p:ajax update="test2,test"
                                listener="#{maxUserMBean.onRoleChanged}"/>
                    </h:selectOneMenu>
        <h:inputText id="test" value="#{maxUserMBean.administratorChosen}" title="#{bundle.CreateMaxUserEntityTitle_username}"
                                 />
       <h:inputText id="test2" value="#{maxUserMBean.administratorChosen}" title="#{bundle.CreateMaxUserEntityTitle_username}"
                               rendered="#{maxUserMBean.administratorChosen}" />
Here`s the important part from Backing Bean

Code: Select all

   public void onRoleChanged() {
              administratorChosen = !administratorChosen;
    }
Even though the value in test is change as it should, the field test2 doesn`t get rendered. :cry:

dmantil
Posts: 93
Joined: 14 Jul 2010, 22:30

12 Jan 2011, 03:41

try this,

Code: Select all

<h:selectOneMenu id="role"  value="#{maxUserMBean.vybranaRole}"
                                     converter="maxRoleConverter" >
            <f:selectItems value="#{maxRoleController.itemsAvailableSelectOne}" />
            <p:ajax update="testpanel" listener="#{maxUserMBean.onRoleChanged}"/>
        </h:selectOneMenu>
        
        <p:outputPanel id="testpanel">
        <h:inputText id="test" value="#{maxUserMBean.administratorChosen}" 
                     title="#{bundle.CreateMaxUserEntityTitle_username}"/>
       <h:inputText id="test2" value="#{maxUserMBean.administratorChosen}" 
                    title="#{bundle.CreateMaxUserEntityTitle_username}"
                               rendered="#{maxUserMBean.administratorChosen}" />
        </p:outputPanel>
if the component it's not rendered it's never updated, but if you upadte an always rendered component it works.

I hope this helps.

Vikky
Posts: 7
Joined: 11 Jan 2011, 14:07

13 Jan 2011, 16:40

Sincerest thanks dmantil,

It works your way. However I would still like to know, why it works like this - now the original tag is inside output panel, but still depends on rendered atribut. What is the deal with outputPanel?

dmantil
Posts: 93
Joined: 14 Jul 2010, 22:30

13 Jan 2011, 21:35

The deal isnt' with output panel, it could be another component like a panel, or a htmlpanelgrid... (or whatever can contain the components to update)

The deal is with ajax update property value (id of component to update) and if that component isn't already rendered.
In your example, ajax behavior try to update a component which is not rendered so the update is ignored because that id
doesn't exists in page.

On the other hand when you use an output panel (or another parent component) which is always rendered, the ajax find correctly the id
and update it, and so the contained not rendered components appears!!!

The real deal with output panel is it's really usefull for doing this because it's invisible for users

I hope you understand me, my english is not as good as i can do a better explaination.

Vikky
Posts: 7
Joined: 11 Jan 2011, 14:07

14 Jan 2011, 14:39

I think you explanation was perfect. You cannot update component which is not there. However if you wrap it with parent component, which is on the view, all the items inside that component get updated too.

Once again thank you very much! :)

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 34 guests