如何使用文本区域、文本框和文件上传字段创建 h:selectOneRadio 选项?

发布于 2024-12-19 15:39:10 字数 1872 浏览 1 评论 0 原文

我正在尝试在 JSF 2.0 中制作以下表单,但遇到一些麻烦:

screenshot

  1. 我怎样才能制作s 里面有文本框和文本区域?

  2. 未选择单选按钮时如何取消文本区域或文本框?


更新:事实上,我对那个表格还一无所知。我只有基本的数据表,我正在尝试:

<h:column>
  <h:selectOneRadio id="radio" layout="pageDirection" onclick="uncheckOthers(this)" > 
    <f:selectItem id="radio_1" itemLabel="Accesion Number: ">
      <h:inputTextarea id="radio" />
      <!-- Or another one objet distinct to <f:selectItem> -->
    </f:selectItem>
  </h:selectOneRadio>
</h:column>   

我在这个网络中找到了 uncheckOthers() 函数以及我认为它具有相同功能的另一个函数:

function seleccionarSequencesType(x){
    document.getElementById("gi").disabled=true;
    for (var i = 0; i < document.solicitud.sequencesType.length; i++) {
        if (document.solicitud.sequencesType[i].checked) {
            inhabilitar(document.getElementById(document.solicitud.sequencesType[i].value), false);
            //document.getElementById(x.value).disabled=false;
        } else {
            inhabilitar(document.getElementById(document.solicitud.sequencesType[i].value), true);
            //document.getElementById(document.solicitud.sequencesType[i].value).disabled=true;
        }
    }
}

function uncheckOthers(radio) {
    var name = radio.name.substring(radio.name.lastIndexOf(':'));
    var elements = radio.form.elements;
    for (var i = 0; i < elements.length; i++) {
        if (elements[i].name.substring(elements[i].name.lastIndexOf(':')) == name) {
            elements[i].checked = false;
        }
    }
    radio.checked = true;
}        

我有一个带有 < code>String 属性来保存textareas的信息,但是还没有完全开发出来,因为一开始我想实现上面的需求。

I'm trying to make the following form in JSF 2.0 but a have some troubles:

screenshot

  1. How can I make <h:selectOneRadio>s with textboxes and textareas inside?

  2. How can I disbale the textareas or textboxes when the radio buton isn't selected?


Update: in fact, I have nothing yet about that form. I have only the basic datatable, I'm trying that:

<h:column>
  <h:selectOneRadio id="radio" layout="pageDirection" onclick="uncheckOthers(this)" > 
    <f:selectItem id="radio_1" itemLabel="Accesion Number: ">
      <h:inputTextarea id="radio" />
      <!-- Or another one objet distinct to <f:selectItem> -->
    </f:selectItem>
  </h:selectOneRadio>
</h:column>   

I found the uncheckOthers() function in this web and the another function of which I think it does the same:

function seleccionarSequencesType(x){
    document.getElementById("gi").disabled=true;
    for (var i = 0; i < document.solicitud.sequencesType.length; i++) {
        if (document.solicitud.sequencesType[i].checked) {
            inhabilitar(document.getElementById(document.solicitud.sequencesType[i].value), false);
            //document.getElementById(x.value).disabled=false;
        } else {
            inhabilitar(document.getElementById(document.solicitud.sequencesType[i].value), true);
            //document.getElementById(document.solicitud.sequencesType[i].value).disabled=true;
        }
    }
}

function uncheckOthers(radio) {
    var name = radio.name.substring(radio.name.lastIndexOf(':'));
    var elements = radio.form.elements;
    for (var i = 0; i < elements.length; i++) {
        if (elements[i].name.substring(elements[i].name.lastIndexOf(':')) == name) {
            elements[i].checked = false;
        }
    }
    radio.checked = true;
}        

I have a basic bean with String properties to save the information of the textareas, but it isn't fully developed yet, because at first I want to achieve the above requirement.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

献世佛 2024-12-26 15:39:11

标准 JSF < h:selectOneRadio> 组件不支持此功能。最好的选择是使用 Tomahawk layout 属性设置为 spread。这使您能够将各个单选按钮定位为 任何你想要的地方。

要根据单选按钮选项值禁用文本字段,只需在未选择所需的单选按钮选项值时让其 disabled 属性评估 true 即可。

这是一个基本的启动示例:

<style>li { list-style-type: none; }</style>
...
<h:form enctype="multipart/form-data">
    <t:selectOneRadio id="options" value="#{bean.option}" layout="spread">
        <f:selectItem itemValue="text" itemLabel="Text in FASTA format" />
        <f:selectItem itemValue="number" itemLabel="Asseccion number" />
        <f:selectItem itemValue="file" itemLabel="Upload files" />
        <f:ajax render="@form" />
    </t:selectOneRadio>
    <ul>
        <li>
            <t:panelGrid columns="2">
                <t:panelGroup colspan="2">
                    <t:radio for="options" index="0" />
                </t:panelGroup>
                <h:outputLabel for="text1" value="1st sequence" />                
                <h:inputTextarea id="text1" value="#{bean.text1}" disabled="#{bean.option != 'text'}" />
                <h:outputLabel for="text2" value="2nd sequence" />                
                <h:inputTextarea id="text2" value="#{bean.text2}" disabled="#{bean.option != 'text'}" />
            </t:panelGrid>
        </li>
        <li>
            <t:panelGrid columns="2">
                <t:panelGroup colspan="2">
                    <t:radio for="options" index="1" />
                </t:panelGroup>
                <h:outputLabel for="number1" value="1st id" />                
                <h:inputText id="number1" value="#{bean.number1}" disabled="#{bean.option != 'number'}" />
                <h:outputLabel for="number2" value="2nd id" />                
                <h:inputText id="number2" value="#{bean.number2}" disabled="#{bean.option != 'number'}" />
            </t:panelGrid>
        </li>
        <li>
            <t:panelGrid columns="2">
                <t:panelGroup colspan="2">
                    <t:radio for="options" index="2" />
                </t:panelGroup>
                <h:outputLabel for="file1" value="1st sequence" />                
                <t:inputFileUpload id="file1" value="#{bean.file1}" disabled="#{bean.option != 'file'}" />
                <h:outputLabel for="file2" value="2nd sequence" />                
                <t:inputFileUpload id="file2" value="#{bean.file2}" disabled="#{bean.option != 'file'}" />
            </t:panelGrid>
        </li>
    </ul>
    <h:commandButton value="Submit" action="#{bean.submit}" />
</h:form>

请注意,Tomahawk 还提供了 在标准 colspan 支持href="http://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/h/panelGroup.html" rel="nofollow noreferrer">< /code> 以及 浏览并选择文件。后者要求将表单的编码类型设置为multipart/form-data。这反过来又需要在 web.xml 中注册 ExtensionsFilter,如本迷你教程所示:JSF 2.0 文件上传

The standard JSF <h:selectOneRadio> component doesn't support this. Your best bet using Tomahawk's <t:selectOneRadio> with the layout attribute set to spread. This enables you to position the individual radio buttons as <t:radio> everywhere you want.

To disable the text fields depending on the radio button option value, just let its disabled attribute evaluate true when the desired radio button option value is not selected.

Here's a basic kickoff example:

<style>li { list-style-type: none; }</style>
...
<h:form enctype="multipart/form-data">
    <t:selectOneRadio id="options" value="#{bean.option}" layout="spread">
        <f:selectItem itemValue="text" itemLabel="Text in FASTA format" />
        <f:selectItem itemValue="number" itemLabel="Asseccion number" />
        <f:selectItem itemValue="file" itemLabel="Upload files" />
        <f:ajax render="@form" />
    </t:selectOneRadio>
    <ul>
        <li>
            <t:panelGrid columns="2">
                <t:panelGroup colspan="2">
                    <t:radio for="options" index="0" />
                </t:panelGroup>
                <h:outputLabel for="text1" value="1st sequence" />                
                <h:inputTextarea id="text1" value="#{bean.text1}" disabled="#{bean.option != 'text'}" />
                <h:outputLabel for="text2" value="2nd sequence" />                
                <h:inputTextarea id="text2" value="#{bean.text2}" disabled="#{bean.option != 'text'}" />
            </t:panelGrid>
        </li>
        <li>
            <t:panelGrid columns="2">
                <t:panelGroup colspan="2">
                    <t:radio for="options" index="1" />
                </t:panelGroup>
                <h:outputLabel for="number1" value="1st id" />                
                <h:inputText id="number1" value="#{bean.number1}" disabled="#{bean.option != 'number'}" />
                <h:outputLabel for="number2" value="2nd id" />                
                <h:inputText id="number2" value="#{bean.number2}" disabled="#{bean.option != 'number'}" />
            </t:panelGrid>
        </li>
        <li>
            <t:panelGrid columns="2">
                <t:panelGroup colspan="2">
                    <t:radio for="options" index="2" />
                </t:panelGroup>
                <h:outputLabel for="file1" value="1st sequence" />                
                <t:inputFileUpload id="file1" value="#{bean.file1}" disabled="#{bean.option != 'file'}" />
                <h:outputLabel for="file2" value="2nd sequence" />                
                <t:inputFileUpload id="file2" value="#{bean.file2}" disabled="#{bean.option != 'file'}" />
            </t:panelGrid>
        </li>
    </ul>
    <h:commandButton value="Submit" action="#{bean.submit}" />
</h:form>

Please note that Tomahawk also offers a <t:panelGroup> which adds the colspan support on top of the standard <h:panelGroup> and also a <t:inputFileUpload> to browse and select files. The latter requires the form's encoding type to be set to multipart/form-data. This in turn requires the ExtensionsFilter to be registered in web.xml as shown in this mini-tutorial: JSF 2.0 File upload.

北恋 2024-12-26 15:39:11
  1. 单选按钮就是单选按钮,句号。文本框应该是单独的元素(最好的解决方案是创建包含单选按钮和文本框/文件上传字段的自定义组件)

  2. 使用 javascript。与 JSF 结合起来会变得很难看,但如果将其保存在外部文件中,应该没问题。

  1. A radio button is a radio button, period. The textboxes should be separate elements (the nicest solution is to create custom components that include the radio button and the textboxes/file upload fields)

  2. Use javascript. It gets ugly combined with JSF, but if you keep it in external files you should be fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文