我是目的是要在页面通过<h:commandButton >把一个值0传到我的类里面。
页面中设置:
<h:form>
<h:inputHidden value="0" binding="#{paginationBean.startIndex}" >
<h:commandButton action="#{userBean.query}" type="submit" value="查询">
</h:form>UserBean.java中:
FacesContext context = FacesContext.getCurrentInstance(); 
PaginationBean bean =(PaginationBean)context.getApplication().getELResolver().getValue(context.getELContext(), null, "paginationBean");  
bean.getStartIndex();System.out.println("1111111111111111113" + bean.getStartIndex());PaginationBean.java中
@Name("paginationBean")
@Scope(ScopeType.PAGE)
public class PaginationBean<T extends PagedListBean> {
protected int startIndex = 0; }
结果是接受不到,xhtml中<h:inputHidden value="0" binding="#{paginationBean.startIndex}" >不知道对不对,报页面错误
<h:inputHidden value="#{paginationBean.startIndex}" >这样就没有页面错误了,但是没办法接受我的0这个值。
我觉得<h:inputHidden >和<h:inputText>应该差不多。<h:inputText>可以通过手动输入,可是<h:inputHidden >该把这个值放在哪呢?

解决方案 »

  1.   

    要传值你可以这样
    这是前台页面
    <h:form> 
    <h:inputHidden value="0" binding="#{userBean.ben1}"/ > 
    <h:commandButton actionListenner="#{userBean.query}" type="submit" value="查询"> 
    </h:form> 
    后台代码
    public class userBean{
      HtmlInputHidden ben1=new HtmlInputHidden();
      //你自己生成get和set方法
      public void query(ActionEvent event){
        String values=(String)ben1.getValue();
        System.out.println("您传过来的值为:"+values);
        //输出结果为0
      }
    }