将查询字符串参数插入到托管bean的属性中

时间:2014-01-15 10:09:25

标签: jsf-2 managed-bean

我希望根据查询字符串中的参数预先填充jsf表单。我该怎么做?

2 个答案:

答案 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();

}