Search code examples
jsflabelpositioningtextfield

How to create JSF outputLabel next to inputText


I am creating a few outputLabels and corresponding inputText components, but the Label always appears above the textfield. I haven't found any attribute controlling this so far.

How do I get the label next to the input?


Solution

  • You can use PanelGrid, Which in turn generates TABLE tag in HTML.

    <h:panelGrid columns="2">
       <h:outputLabel>Name:</h:outputLabel>
       <h:inputText/>
    
       <h:outputLabel>Email:</h:outputLabel>
       <h:inputText/>
    
       <h:outputLabel>Passowrd:</h:outputLabel>
       <h:inputSecret/>
    </h:panelGrid>
    

    Once you define the columns=2 it inserts the components side by side in each cell respectively.
    There is also h:column which you can use.
    But you can not perform ROWSPAN and COLSPAN in JSF as in HTML, however if you still want ROWSPAN and COLSPAN you can go for 3rd party JSF component Libriries like Primefaces,Richfaces...