2

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?

  • I don't understand the question. Do you want to have an input field that is not processed upon submit? In that case, just use a normal html input field instead of a jsf one. It will be ignored in the process input phase. – Joeri Hendrickx Aug 18 '11 at 14:52

1 Answers1

4

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).

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • But let us assume another situation. Inside this form I have to put composition which has its own form in there.. What if I need to put it into the table with it's form. Is it a good Idea to make this comment a separate question? – Dmitry Alexandrov Aug 18 '11 at 15:56
  • You cannot nest forms in HTML, so also not in JSF. – BalusC Aug 18 '11 at 15:57
  • is there a possibility to have splitted forms in one table? – Dmitry Alexandrov Aug 18 '11 at 16:02
  • 1
    A `
    ` can only go within ``. By the way, if you're using JSF2 with ``, it's good to know that you can specify the execution contexts with `execute` attribute. So instead of `execute="@form"` you could use `execute="input1 input3"` and so on where you skip `input2`.
    – BalusC Aug 18 '11 at 16:09