update attribute not working as expected while trying to render panels conditionally











up vote
0
down vote

favorite












I am trying to show/hide my panels based upon a boolean value present on the backing bean but it's not working as expected and there is no change on the UI.
This works fine for the first time (only one of the panels is shown) when the app loads but then after there is no update performed.



I know that for the update to be performed, the element should exist in the dom already so it doesn't update the panel which is not rendered by the server . But my query is why the other panel (shown when the app loads) doesn't get hidden when the boolean condition changes.



xhtml file





    <p:panel>
<h6 align="center" style="width: 14.7em; background-color: #ACBECE;">Case
Type</h6>
<!-- comment type -->
<p:selectOneListbox id="caseTypeId"
value="#{treeBean.caseTypeOption}">
<f:selectItems value="#{treeBean.caseType}" var="X"
itemLabel="#{X}" itemValue="#{X}" />
<p:ajax listener="#{treeBean.caseTypeList}" update=":#{p:component('panel2')} :#{p:component('panel3')}"/>
</p:selectOneListbox>
</p:panel>

<p:panel id="panel2" rendered="#{treeBean.editmode}">
<h6 align="center" style="width: 14.7em; background-color: #ACBECE;">Something
</h6>

<p:selectOneListbox id="somethingId"
value="#{treeBean.somethingOption}">
<f:selectItems value="#{treeBean.something}" var="X"
itemLabel="#{X}" itemValue="#{X}" />
</p:selectOneListbox>
</p:panel>

<p:panel id="panel3" rendered="#{!treeBean.editmode}">
<h6 align="center" style="width: 14.7em; background-color: #ACBECE;">Anything
</h6>

<p:selectOneListbox id="anythingId"
value="#{treeBean.anythingOption}">
<f:selectItems value="#{treeBean.anything}" var="X"
itemLabel="#{X}" itemValue="#{X}" />
</p:selectOneListbox>
</p:panel>

</h:panelGrid>


Backing bean (omitting details)



if (this.caseTypeOption.equalsIgnoreCase("XXX")) {
this.editmode = false;

} else {
this.editmode = true;
}


wher XXX is one of the options in caseTypeId select box.



How to make this work for both the panels ??










share|improve this question






















  • Possible duplicate of Ajax update/render does not work on a component which has rendered attribute
    – Kukeltje
    Nov 19 at 10:59















up vote
0
down vote

favorite












I am trying to show/hide my panels based upon a boolean value present on the backing bean but it's not working as expected and there is no change on the UI.
This works fine for the first time (only one of the panels is shown) when the app loads but then after there is no update performed.



I know that for the update to be performed, the element should exist in the dom already so it doesn't update the panel which is not rendered by the server . But my query is why the other panel (shown when the app loads) doesn't get hidden when the boolean condition changes.



xhtml file





    <p:panel>
<h6 align="center" style="width: 14.7em; background-color: #ACBECE;">Case
Type</h6>
<!-- comment type -->
<p:selectOneListbox id="caseTypeId"
value="#{treeBean.caseTypeOption}">
<f:selectItems value="#{treeBean.caseType}" var="X"
itemLabel="#{X}" itemValue="#{X}" />
<p:ajax listener="#{treeBean.caseTypeList}" update=":#{p:component('panel2')} :#{p:component('panel3')}"/>
</p:selectOneListbox>
</p:panel>

<p:panel id="panel2" rendered="#{treeBean.editmode}">
<h6 align="center" style="width: 14.7em; background-color: #ACBECE;">Something
</h6>

<p:selectOneListbox id="somethingId"
value="#{treeBean.somethingOption}">
<f:selectItems value="#{treeBean.something}" var="X"
itemLabel="#{X}" itemValue="#{X}" />
</p:selectOneListbox>
</p:panel>

<p:panel id="panel3" rendered="#{!treeBean.editmode}">
<h6 align="center" style="width: 14.7em; background-color: #ACBECE;">Anything
</h6>

<p:selectOneListbox id="anythingId"
value="#{treeBean.anythingOption}">
<f:selectItems value="#{treeBean.anything}" var="X"
itemLabel="#{X}" itemValue="#{X}" />
</p:selectOneListbox>
</p:panel>

</h:panelGrid>


Backing bean (omitting details)



if (this.caseTypeOption.equalsIgnoreCase("XXX")) {
this.editmode = false;

} else {
this.editmode = true;
}


wher XXX is one of the options in caseTypeId select box.



How to make this work for both the panels ??










share|improve this question






















  • Possible duplicate of Ajax update/render does not work on a component which has rendered attribute
    – Kukeltje
    Nov 19 at 10:59













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to show/hide my panels based upon a boolean value present on the backing bean but it's not working as expected and there is no change on the UI.
This works fine for the first time (only one of the panels is shown) when the app loads but then after there is no update performed.



I know that for the update to be performed, the element should exist in the dom already so it doesn't update the panel which is not rendered by the server . But my query is why the other panel (shown when the app loads) doesn't get hidden when the boolean condition changes.



xhtml file





    <p:panel>
<h6 align="center" style="width: 14.7em; background-color: #ACBECE;">Case
Type</h6>
<!-- comment type -->
<p:selectOneListbox id="caseTypeId"
value="#{treeBean.caseTypeOption}">
<f:selectItems value="#{treeBean.caseType}" var="X"
itemLabel="#{X}" itemValue="#{X}" />
<p:ajax listener="#{treeBean.caseTypeList}" update=":#{p:component('panel2')} :#{p:component('panel3')}"/>
</p:selectOneListbox>
</p:panel>

<p:panel id="panel2" rendered="#{treeBean.editmode}">
<h6 align="center" style="width: 14.7em; background-color: #ACBECE;">Something
</h6>

<p:selectOneListbox id="somethingId"
value="#{treeBean.somethingOption}">
<f:selectItems value="#{treeBean.something}" var="X"
itemLabel="#{X}" itemValue="#{X}" />
</p:selectOneListbox>
</p:panel>

<p:panel id="panel3" rendered="#{!treeBean.editmode}">
<h6 align="center" style="width: 14.7em; background-color: #ACBECE;">Anything
</h6>

<p:selectOneListbox id="anythingId"
value="#{treeBean.anythingOption}">
<f:selectItems value="#{treeBean.anything}" var="X"
itemLabel="#{X}" itemValue="#{X}" />
</p:selectOneListbox>
</p:panel>

</h:panelGrid>


Backing bean (omitting details)



if (this.caseTypeOption.equalsIgnoreCase("XXX")) {
this.editmode = false;

} else {
this.editmode = true;
}


wher XXX is one of the options in caseTypeId select box.



How to make this work for both the panels ??










share|improve this question













I am trying to show/hide my panels based upon a boolean value present on the backing bean but it's not working as expected and there is no change on the UI.
This works fine for the first time (only one of the panels is shown) when the app loads but then after there is no update performed.



I know that for the update to be performed, the element should exist in the dom already so it doesn't update the panel which is not rendered by the server . But my query is why the other panel (shown when the app loads) doesn't get hidden when the boolean condition changes.



xhtml file





    <p:panel>
<h6 align="center" style="width: 14.7em; background-color: #ACBECE;">Case
Type</h6>
<!-- comment type -->
<p:selectOneListbox id="caseTypeId"
value="#{treeBean.caseTypeOption}">
<f:selectItems value="#{treeBean.caseType}" var="X"
itemLabel="#{X}" itemValue="#{X}" />
<p:ajax listener="#{treeBean.caseTypeList}" update=":#{p:component('panel2')} :#{p:component('panel3')}"/>
</p:selectOneListbox>
</p:panel>

<p:panel id="panel2" rendered="#{treeBean.editmode}">
<h6 align="center" style="width: 14.7em; background-color: #ACBECE;">Something
</h6>

<p:selectOneListbox id="somethingId"
value="#{treeBean.somethingOption}">
<f:selectItems value="#{treeBean.something}" var="X"
itemLabel="#{X}" itemValue="#{X}" />
</p:selectOneListbox>
</p:panel>

<p:panel id="panel3" rendered="#{!treeBean.editmode}">
<h6 align="center" style="width: 14.7em; background-color: #ACBECE;">Anything
</h6>

<p:selectOneListbox id="anythingId"
value="#{treeBean.anythingOption}">
<f:selectItems value="#{treeBean.anything}" var="X"
itemLabel="#{X}" itemValue="#{X}" />
</p:selectOneListbox>
</p:panel>

</h:panelGrid>


Backing bean (omitting details)



if (this.caseTypeOption.equalsIgnoreCase("XXX")) {
this.editmode = false;

} else {
this.editmode = true;
}


wher XXX is one of the options in caseTypeId select box.



How to make this work for both the panels ??







jsf primefaces






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 9:04









Neeraj Chand

1228




1228












  • Possible duplicate of Ajax update/render does not work on a component which has rendered attribute
    – Kukeltje
    Nov 19 at 10:59


















  • Possible duplicate of Ajax update/render does not work on a component which has rendered attribute
    – Kukeltje
    Nov 19 at 10:59
















Possible duplicate of Ajax update/render does not work on a component which has rendered attribute
– Kukeltje
Nov 19 at 10:59




Possible duplicate of Ajax update/render does not work on a component which has rendered attribute
– Kukeltje
Nov 19 at 10:59












2 Answers
2






active

oldest

votes

















up vote
0
down vote













In the update action you should use only the name of the components that you want to update. In your case you should use update=":form:panel2, :form:panel3".
If this panels is in form you should use the form element before the name of the component, otherwise just the name of the component will make the trick.






share|improve this answer





















  • that is what I have in my update attribute. update=":panel2, :panel3" and update=":#{p:component('panel2')} :#{p:component('panel3')}" are the same ryt ?
    – Neeraj Chand
    Nov 19 at 9:46




















up vote
0
down vote













Instead of rendered attribute , using visible attribute helped me to achieve what I wanted.



So instead of <p:panel id="panel2" rendered="#{treeBean.editmode}">



I used : <p:panel id="panel2" visible="#{treeBean.editmode}">






share|improve this answer





















  • This is expected yes - you can't update a component, which was never rendered. Your case will also work, when you update the parent component instead the children, which was not rendered yet.
    – tandraschko
    Nov 19 at 10:28










  • @tandraschko: as mentioned in the 'duplicate'
    – Kukeltje
    Nov 20 at 9:54











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371294%2fupdate-attribute-not-working-as-expected-while-trying-to-render-panels-condition%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













In the update action you should use only the name of the components that you want to update. In your case you should use update=":form:panel2, :form:panel3".
If this panels is in form you should use the form element before the name of the component, otherwise just the name of the component will make the trick.






share|improve this answer





















  • that is what I have in my update attribute. update=":panel2, :panel3" and update=":#{p:component('panel2')} :#{p:component('panel3')}" are the same ryt ?
    – Neeraj Chand
    Nov 19 at 9:46

















up vote
0
down vote













In the update action you should use only the name of the components that you want to update. In your case you should use update=":form:panel2, :form:panel3".
If this panels is in form you should use the form element before the name of the component, otherwise just the name of the component will make the trick.






share|improve this answer





















  • that is what I have in my update attribute. update=":panel2, :panel3" and update=":#{p:component('panel2')} :#{p:component('panel3')}" are the same ryt ?
    – Neeraj Chand
    Nov 19 at 9:46















up vote
0
down vote










up vote
0
down vote









In the update action you should use only the name of the components that you want to update. In your case you should use update=":form:panel2, :form:panel3".
If this panels is in form you should use the form element before the name of the component, otherwise just the name of the component will make the trick.






share|improve this answer












In the update action you should use only the name of the components that you want to update. In your case you should use update=":form:panel2, :form:panel3".
If this panels is in form you should use the form element before the name of the component, otherwise just the name of the component will make the trick.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 9:16









Jimmo

62




62












  • that is what I have in my update attribute. update=":panel2, :panel3" and update=":#{p:component('panel2')} :#{p:component('panel3')}" are the same ryt ?
    – Neeraj Chand
    Nov 19 at 9:46




















  • that is what I have in my update attribute. update=":panel2, :panel3" and update=":#{p:component('panel2')} :#{p:component('panel3')}" are the same ryt ?
    – Neeraj Chand
    Nov 19 at 9:46


















that is what I have in my update attribute. update=":panel2, :panel3" and update=":#{p:component('panel2')} :#{p:component('panel3')}" are the same ryt ?
– Neeraj Chand
Nov 19 at 9:46






that is what I have in my update attribute. update=":panel2, :panel3" and update=":#{p:component('panel2')} :#{p:component('panel3')}" are the same ryt ?
– Neeraj Chand
Nov 19 at 9:46














up vote
0
down vote













Instead of rendered attribute , using visible attribute helped me to achieve what I wanted.



So instead of <p:panel id="panel2" rendered="#{treeBean.editmode}">



I used : <p:panel id="panel2" visible="#{treeBean.editmode}">






share|improve this answer





















  • This is expected yes - you can't update a component, which was never rendered. Your case will also work, when you update the parent component instead the children, which was not rendered yet.
    – tandraschko
    Nov 19 at 10:28










  • @tandraschko: as mentioned in the 'duplicate'
    – Kukeltje
    Nov 20 at 9:54















up vote
0
down vote













Instead of rendered attribute , using visible attribute helped me to achieve what I wanted.



So instead of <p:panel id="panel2" rendered="#{treeBean.editmode}">



I used : <p:panel id="panel2" visible="#{treeBean.editmode}">






share|improve this answer





















  • This is expected yes - you can't update a component, which was never rendered. Your case will also work, when you update the parent component instead the children, which was not rendered yet.
    – tandraschko
    Nov 19 at 10:28










  • @tandraschko: as mentioned in the 'duplicate'
    – Kukeltje
    Nov 20 at 9:54













up vote
0
down vote










up vote
0
down vote









Instead of rendered attribute , using visible attribute helped me to achieve what I wanted.



So instead of <p:panel id="panel2" rendered="#{treeBean.editmode}">



I used : <p:panel id="panel2" visible="#{treeBean.editmode}">






share|improve this answer












Instead of rendered attribute , using visible attribute helped me to achieve what I wanted.



So instead of <p:panel id="panel2" rendered="#{treeBean.editmode}">



I used : <p:panel id="panel2" visible="#{treeBean.editmode}">







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 10:02









Neeraj Chand

1228




1228












  • This is expected yes - you can't update a component, which was never rendered. Your case will also work, when you update the parent component instead the children, which was not rendered yet.
    – tandraschko
    Nov 19 at 10:28










  • @tandraschko: as mentioned in the 'duplicate'
    – Kukeltje
    Nov 20 at 9:54


















  • This is expected yes - you can't update a component, which was never rendered. Your case will also work, when you update the parent component instead the children, which was not rendered yet.
    – tandraschko
    Nov 19 at 10:28










  • @tandraschko: as mentioned in the 'duplicate'
    – Kukeltje
    Nov 20 at 9:54
















This is expected yes - you can't update a component, which was never rendered. Your case will also work, when you update the parent component instead the children, which was not rendered yet.
– tandraschko
Nov 19 at 10:28




This is expected yes - you can't update a component, which was never rendered. Your case will also work, when you update the parent component instead the children, which was not rendered yet.
– tandraschko
Nov 19 at 10:28












@tandraschko: as mentioned in the 'duplicate'
– Kukeltje
Nov 20 at 9:54




@tandraschko: as mentioned in the 'duplicate'
– Kukeltje
Nov 20 at 9:54


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371294%2fupdate-attribute-not-working-as-expected-while-trying-to-render-panels-condition%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Ottavio Pratesi

Tricia Helfer

15 giugno