验证JSF h:datatable中的选定行

时间:2021-12-22 06:50:09

I am having a tough time trying to find a solution to the following design related to h:dataTable.

我正在努力寻找与h:dataTable相关的以下设计的解决方案。

I have certain number of rows predisplayed. The first column is only checkboxes. The rest of the columns are disabled by default. On selecting a checkbox the elements in the corresponding rows get enabled. On submit of the for the values in the enabled row have to be validated on the server side. I am able to validate for invalid inputs but am not finding a method to use required="true" conditionally. Or any other method. Could anyone please help me on this.

我预先显示了一定数量的行。第一列只是复选框。默认情况下禁用其余列。选中复选框后,相应行中的元素将启用。必须在服务器端验证启用行中的值的提交。我能够验证无效输入但是没有找到有条件地使用required =“true”的方法。或任何其他方法。有谁可以帮我这个。

Thanks Barun

2 个解决方案

#1


I'm guessing you have a bean that looks something like this...

我猜你有一个看起来像这样的豆子......

public class SomeBean {
   boolean selected = false;
   String someProperty;

   ...
}

If you have a controller for those beans your markup would look something like this...

如果你有这些bean的控制器你的标记看起来像这样......

<h:dataTable value="#{SomeController.someBeans}" var="someBean">
   <h:column> 
      <f:facet name="header">Select</f:facet>
      <h:selectBooleanCheckbox value="#{someBean.selected}"/>
   </h:column>
   <h:column> 
      <f:facet name="header">Input</f:facet>
      <h:inputText value="#{someBean.someproperty}" required="#{someBean.selected}"/>
   </h:column>
</h:dataTable>

#2


You should have a method like:

你应该有一个像这样的方法:

public boolean isSelected(){

  return selected;
}

#1


I'm guessing you have a bean that looks something like this...

我猜你有一个看起来像这样的豆子......

public class SomeBean {
   boolean selected = false;
   String someProperty;

   ...
}

If you have a controller for those beans your markup would look something like this...

如果你有这些bean的控制器你的标记看起来像这样......

<h:dataTable value="#{SomeController.someBeans}" var="someBean">
   <h:column> 
      <f:facet name="header">Select</f:facet>
      <h:selectBooleanCheckbox value="#{someBean.selected}"/>
   </h:column>
   <h:column> 
      <f:facet name="header">Input</f:facet>
      <h:inputText value="#{someBean.someproperty}" required="#{someBean.selected}"/>
   </h:column>
</h:dataTable>

#2


You should have a method like:

你应该有一个像这样的方法:

public boolean isSelected(){

  return selected;
}