【发布时间】:2014-02-03 17:58:22
【问题描述】:
我希望根据查询字符串中的参数预先填充 jsf 表单。我该怎么办?
【问题讨论】:
-
他们是GET请求参数吗?
-
作为查询字符串 - 是的。
标签: jsf-2 managed-bean
我希望根据查询字符串中的参数预先填充 jsf 表单。我该怎么办?
【问题讨论】:
标签: jsf-2 managed-bean
编写一个bean函数并调用该jsf页面的ActionListener
Bean功能代码-
public void viewProperty(ActionEvent actionEvent) {
FacesContext context = FacesContext.getCurrentInstance();
BindingContext bindingContext = BindingContext.getCurrent();
DCDataControl dc = bindingContext.findDataControl("AppModuleDataControl"); // Name of application module in datacontrolBinding.cpx
AppModuleImpl appM = (AppModuleImpl)dc.getDataProvider();
ViewObject vo = appM.findViewObject("propertyInformationNew1"); //Name of ViewObject
String brokerUsername = MyADFUtil.getFromSessionScope("brokerUsername").toString();
vo.setNamedWhereClauseParam("pBrokerProp", brokerUsername); //first value is parameter name and second one is value of that parameter
vo.executeQuery();
}
【讨论】:
使用f:viewParam 实用程序。有这个网址:
/myForm.xhtml?nameField=Anthony
您可以在表单本身被呈现之前设置视图参数。在表单视图中使用此代码:
<f:metadata>
<f:viewParam name="nameField"
value="#{formBean.name}" />
</f:metadata>
<h:form>
<h:inputText value="#{formBean.name}" />
<h:commandButton value="Send name" action="#{formBean.sendName}" />
</h:form>
您指定的值将被设置为输入的默认值。
另请参阅:
【讨论】:
f:viewAction。