フォームに動的入力フィールドを追加できます。
<h:form>
<h:dataTable id="tblFields" value="#{templateOptionBean.fields}"
var="field">
<h:column>
<h:inputText value="#{field.value}" />
</h:column>
<h:column>
<h:commandButton value="Remove">
<f:ajax
listener="#{templateOptionBean.onButtonRemoveFieldClick(field)}"
immediate="true" render="@form" />
</h:commandButton>
</h:column>
</h:dataTable>
<h:commandButton value="Add">
<f:ajax listener="#{templateOptionBean.onButtonAddFieldClick}"
execute="@form" render="tblFields" />
</h:commandButton>
</h:form>
私のバックエンドは次のようになります:
@ManagedBean
@ViewScoped
public class TemplateOptions implements Serializable
{
private List<Field> m_lFields;
public TemplateOptions()
{
m_lFields = new ArrayList();
m_lFields.add(new Field());
}
public void setFields(List<Field> p_lFields)
{
m_lFields = p_lFields;
}
public List<Field> getFields()
{
return m_lFields;
}
public void onButtonRemoveFieldClick(final Field p_oField)
{
m_lFields.remove(p_oField);
}
public void onButtonAddFieldClick(AjaxBehaviorEvent p_oEvent)
{
m_lFields.add(new Field());
}
}
ただし、フォームのボタンを変更するとp:commandButton
、ロジックが機能しなくなります。
ただし、これらのタイプのボタンを使用したいです。したがって、このタイプのボタンをどのように使用できますか?
あなたの答えに本当に感謝します!!!