jsf - Conditionally render components with ajax conditionally only if validation passes -


i using jsf 2.2 , wondering if there way render components ajax conditionally if validation passes. using render attribute of ajax components rendered regardless of validation passing or not. i'm after like:

<f:ajax ... render="#{validationhaspassed ? 'foo' : ''}" /> ... <h:panelgroup id="foo">           <!-- other components here -->   </h:panelgroup> 

is possible conditionally render component in similar way this? in case don't want have rendered attribute in fragment , set true or false, makes fragment not exist @ in dom if validation fails. might have specific css styling example in components inside panelgroup has been acquired through jquery after interaction page , don't want render section if validation fails, can remain in current visual state.

you can make use of facescontext#isvalidationfailed(). return true if validation has failed in current jsf lifecycle. current instance of facescontext available in el #{facescontext}.

just check in rendered attribute , update parent placeholder component. note can't conditionally render component has rendered attribute set javascript otherwise not able find , update it. theoretical <f:ajax> attempt have failed same way.

e.g.

<f:ajax ... render="foo-holder" /> ... <h:panelgroup id="foo-holder">     <h:panelgroup id="foo" rendered="#{not facescontext.validationfailed}">         validation has not failed.     </h:panelgroup> </h:panelgroup> 

add if necessary layout="block" make them <div> components instead of <span> ones, depending on final markup.

see also:


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -