如何在jsf中将表单值转换为请求值?

时间:2014-01-02 06:12:14

标签: jsf

在xhtml中我应该输入值,当我提交时我需要将这些值直接输入具体方法而不使用bean类。从某种意义上说,可以将表单值转换为请求值,例如我们将<f:param>提供给<h:commandButton>,并且按钮值将变为request ..我们使用facescontext MAP<String,String>获取它>

face1.xhtml:

    <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core">
        <h:head>
            <title>p:faces -- Exercises</title>
        </h:head>
        <h:body>
        <h:form>
        username:<h:inputText name="username" value="praveen"/>
        <br/>
        password:<h:inputText name="password" value="anil"/>
        <br/>

        <h:commandButton action="#{sample1.editAction}">
        <f:param name="country" value="China" />

        </h:commandButton>
        </h:form>
        </h:body>
    </html>

这里需要从值获取,但是我的用户名,密码和我作为中国获得的国家是空的....就像明智的我需要得到用户名和密码...是否有任何获得那些价值通过MAP<String,String>

sample1.java

    import java.util.Map;

    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.SessionScoped;
    import javax.faces.context.FacesContext;

    @ManagedBean
    @SessionScoped
    public class sample1 {
        public String editAction()
        {
        //here I should get username,password as I enter in form

        Map<String, String> params = FacesContext.getCurrentInstance()
                .getExternalContext().getRequestParameterMap();
        String username=params.get("username");
        String pssword=params.get("password");
        String country=params.get("country");
        System.out.println(country);
         return "success";
    }
}

0 个答案:

没有答案