简体   繁体   中英

JSF render component ajax radio button selection

This Question is a follow up to JSF Primefaces Radio Button show/hide/enable a textarea One of the two problems were solved from that Post by wrapping the inputTextArea in a panelGroup, however I still need to figure out how to not show the inputTextArea on form load when the status is a 2 (=No), but only show when the radio under column 2 is being toggled.


在此处输入图片说明

    <p:column ...>
        <p:selectOneRadio ...>
        ...
            <p:ajax update="reason" />
        </p:selectOneRadio>
    </p:column>
    <p:column headerText="Reason For Attribute Failure">
      <h:panelGroup id="reason">
        <h:inputTextarea value="#{qAndA.fail_reason}" rendered="#{qAndA.toggle_value == '2'}" />
      </h:panelGroup>

        <h:outputText value="" rendered="#{qAndA.toggle_value == '1' or qAndA.toggle_value == '3'}" />
     <h:outputText value="#{qAndA.fail_reason}" rendered="#{qAndA.toggle_value == '2' or qAndA.toggle_value == '4'}" />

    </p:column>

perhaps the status codes are flawed:

  • 0 = no input yet
  • 1 = yes
  • 2 = no, with a reason
  • 3 = Not Applicable
  • 4 = the No was eventually resolved

I'd rather not have to modify the status codes but adding another intermediate code, something like this would probably work:

  • 2 = show reason box
  • 2.5 means no with a reason

Any other options besides modifying status code?

Well the real answer is to not have the value at 2 when the bean is loaded if you want to not display it. But you already know that. What you are asking is subjective to you and how you wanna do things. You have no issue and this is more a design question. Having said that here is one:

Maybe you'd like to have 2 conditions :

<h:inputTextarea value="#{qAndA.fail_reason}" rendered="#{qAndA.toggle_value == '2' and bean.AnotherCondition}" />

If you wanna get fancy make a @ViewScoped bean that listen for the click you were talking about in your post ( not sure what the click does). Listen for the click and have a boolean property you can set to true once the click has been registered (maybe with an action listener). This way the textarea will only show when clicked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM