我希望根据查询字符串中的参数预先填充jsf表单。我该怎么做?
答案 0 :(得分:2)
使用f:viewParam
实用程序。有这个网址:
/myForm.xhtml?nameField=Anthony
您可以在表单本身呈现之前设置view参数。在表单视图中使用此代码:
<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>
您指定的值将被设置为输入的默认值。
另见:
答案 1 :(得分:-1)
写一个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();
}