2015-08-15 60 views
1

我有這張3列的表。第三列是默認爲空的驗證消息。h:panelGrid中的列對齊

<h:form> 
    <h:panelGrid id="panel" styleClass="data_table_pricing" columns="3"> 

     <h:outputText value="Title"/> 

     <h:inputText id="title" value="#{pricingForm.title}" validatorMessage="Value is too big."> 
      <f:validateLength minimum="0" maximum="40" /> 
      <f:ajax event="change" render="@form"/> 
     </h:inputText> 

     <h:message id="title_message" for="title" style="color:red"/> 

     <!-- // --> 

     <h:outputText value="First name"/> 

     <h:inputText id="first_name" value="#{pricingForm.firstName}" validatorMessage="Value is too big."> 
      <f:validateLength minimum="0" maximum="40" /> 
      <f:ajax event="change" render="@form"/> 
     </h:inputText> 

     <h:message id="first_name_message" for="first_name" style="color:red"/> 

     <!-- // --> 

     <h:outputText value="Last name"/> 

     <h:inputText id="last_name" value="#{pricingForm.lastName}" validatorMessage="Value is too big."> 
      <f:validateLength minimum="0" maximum="40" /> 
      <f:ajax event="change" render="@form"/> 
     </h:inputText> 

     <h:message id="last_name_message" for="last_name" style="color:red"/> 

     <!-- // --> 

    </h:panelGrid> 

    <h:commandLink value="reset" class="link" type="reset" style="margin: 20px;"> 
     <f:ajax execute="@form" render="@form"/> 
    </h:commandLink> 
    <h:commandLink value="Next" class="link" style="margin: 20px;" actionListener="#{pricingForm.calculatorPage()}"> 
     <f:ajax execute="@form" render="@form"/> 
    </h:commandLink> 

</h:form> 

我用這個CSS代碼樣式表:

.data_table_pricing { 
    border-spacing: 12px; 
    border-collapse: separate; 
    width: 100%; 
} 

我需要找到一個方法來解決大小的列。當驗證消息出現時,第二列被推到左邊。

有什麼方法可以修復列的大小?

+0

你可以設置當前代碼的演示嗎? –

+0

當然:http://54.68.115.94:8080/Web_site/pricing_form.xhtml打開頁面並在任何輸入字段表格中插入超過40個字符,然後單擊「下一步」按鈕或從「開始」之外。你會看到結果。 –

回答

1

爲td元素設置固定寬度可防止列跳轉。

.data_table_pricing tbody tr td { 
    width: 33%; 
} 

編輯:

解表的列的數目可變的,並應上述方法中使用過。

table.data_table_pricing { 
    table-layout: fixed; 
} 
+0

那麼,我也試圖在一個4列的表中實現 - 它看起來非常縮小。還有其他解決方案嗎? –

+0

嗯。你能在這裏說出你的意思嗎?你想如何輸出? –

+0

我在這裏應用了您的代碼http://54.68.115.94:8080/Web_site/pricing_form.xhtml並在這裏http://54.68.115.94:8080/Web_site/pricing_calculator.xhtml在第二頁上插入了一些字符串值以查看驗證錯誤信息。 –