1

I am using one h:selectbooleancheckbox in each row to make 2 columns editable.

Have a look at my JSF page

<h:dataTable id="editTable" styleClass = "listtable" value="#{bean.GroupList}"  var="group" border="1" first="0" rows="8" width="75%" frame="hsides" rules="all" cellpadding="5" headerClass="tableheading" rowClasses="firstrow, secondrow">

    <f:facet name="header">
    <h:outputText value="Groups"></h:outputText>
    </f:facet>

    <h:column>
        <f:facet name="header">
        <h:outputText value="GroupId"></h:outputText>
        </f:facet>
        <h:outputText value="#{group.Id}" rendered="#{not bean.checked[group.Id]}"></h:outputText>
        <h:inputText value="#{group.Id}" rendered="#{bean.checked[group.Id]}" required="true"/>
    </h:column>

    <h:column>
        <f:facet name="header">
        <h:outputText value="GroupName"></h:outputText>
        </f:facet>
        <h:outputText value="#{group.Name}" rendered="#{not bean.checked[group.Id]}"></h:outputText>
        <h:inputText value="#{group.Name}" rendered="#{bean.checked[group.Id]}" required="true"/>
    </h:column>


    <h:column>
        <f:facet name="header">
        <h:outputText value="Check to Enable/Disable"></h:outputText>
        </f:facet>
        <h:selectBooleanCheckbox value="#{bean.checked[group.Id]}" />
    </h:column>

    </h:dataTable>

I have required="true" for GroupId and GroupName columns.

I am not getting where to keep h:messages for each column to display requiredmessage

Please help.

Sreeram
  • 3,160
  • 6
  • 33
  • 44

1 Answers1

2

You need to use <h:message> instead to display errors specific to an input element. The <h:messages> will display all messages which are not covered by any <h:message>.

<h:column>
    <f:facet name="header">
    <h:outputText value="GroupId"></h:outputText>
    </f:facet>
    <h:outputText value="#{group.Id}" rendered="#{not bean.checked[group.Id]}"></h:outputText>
    <h:inputText id="groupId" value="#{group.Id}" rendered="#{bean.checked[group.Id]}" required="true"/>
    <h:message for="groupId" />
</h:column>

<h:column>
    <f:facet name="header">
    <h:outputText value="GroupName"></h:outputText>
    </f:facet>
    <h:outputText value="#{group.Name}" rendered="#{not bean.checked[group.Id]}"></h:outputText>
    <h:inputText id="groupName" value="#{group.Name}" rendered="#{bean.checked[group.Id]}" required="true"/>
    <h:message for="groupName" />
</h:column>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks for the response BalusC.I actually meant to ask about where to place h:message only.Is there any way to present the h:message in separate column so that the datatable cell is not cluttered? – Sreeram Sep 27 '11 at 12:45
  • Truly, just put it in another ``. This column will only be *always* rendered. Whether that's an issue or not depends on the layout/style. – BalusC Sep 27 '11 at 12:57
  • Ok.Column being always rendered is not an good option for me.Instead it would be better to use h:messages on the top of h:datatable to show all errormessages.What do you say? – Sreeram Sep 27 '11 at 13:03
  • 1
    Your site. Your requirements. Your choice :) Both are fine. – BalusC Sep 27 '11 at 13:04
  • Thank you.I will try both and see which fits better for my layout. – Sreeram Sep 27 '11 at 13:14
  • @Sreeram: If you omit the column header for your message column and have no background color or cell borders, the empty message column shouldn't bother too much. – Matt Handy Sep 27 '11 at 13:46