Exclude field from a form in JSF

匿名 (未验证) 提交于 2019-12-03 01:00:01

问题:

I have the following question: Let's assume the code below:

...      <h:form id="..">         <table>          <table border="1">          <tr>          <td><h:outputText value="#{msg.prompt1}"/></td>          <td><h:inputText value="#{personBean.personData1}" />                    <!-- This field must not participate in the form. There would be                         other JSF form and tags here -->               <h:commandButton action="other_action_with_ajax"/>          </td>           </tr>          <tr>          <td><h:outputText value="#{msg.promp2}"/></td>          <td><h:inputText value="#{personBean.personData2}" /></td>          </tr>          <tr>          <td><h:outputText value="#{msg.msg}"/></td>          <td><h:commandButton action="greeting" value="#{msg.button_text}" /></td>          </tr>         </table>      </h:form> ... 

I need to exclude one field from a form which is in a table (currently plane html) as this field is readonly and handled and treated differently from the others. It will be part of other form which does not the wrapping form of this table. But this field must be placed in this table to be formated correctly. And I cant put form in a form. What is the best way to put two forms in one table without splitting it into two tables wrapped in forms?

回答1:

Just make use of the input component's readonly or disabled attribute.

E.g.

<h:inputText value="#{bean.value}" disabled="#{!bean.editable}" /> 

Setting readonly="true" will make it uneditable, but submittable. Setting disabled="true" will make it uneditable and unsubmittable (i.e. value isn't submitted to server).



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!