【问题标题】:Insert query string parameter into property of managed bean将查询字符串参数插入托管 bean 的属性中
【发布时间】:2014-02-03 17:58:22
【问题描述】:

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

【问题讨论】:

  • 他们是GET请求参数吗?
  • 作为查询字符串 - 是的。

标签: jsf-2 managed-bean


【解决方案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();

}

【讨论】:

    【解决方案2】:

    使用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>
    

    您指定的值将被设置为输入的默认值。

    另请参阅:

    【讨论】:

    • 非常感谢。但是现在我有一个问题是没有触发更新这些输入的 ajax :(
    • 我先解决自己的问题
    • 这就是要走的路。祝你好运!
    • 更新。我通过使用 primefaces 的 remoteCommand autorun="true" 调用页面加载操作解决了上述评论中提到的问题
    • 如果 JSF 2.2 可用,请根据您的情况考虑使用 f:viewAction
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-26
    • 2011-07-13
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多