【问题标题】:Value not set correctly with JavaScript and Primefaces使用 JavaScript 和 Primefaces 未正确设置值
【发布时间】:2016-10-18 15:22:36
【问题描述】:

我将带有 JS 的变量发送到输入文本。然后当值被设置时,我点击一个 p:commandButton 来调用一个使用该值的方法,但传递的值是空白的......虽然 js 将值发送到输入并且我看到它......它需要它作为空白。如果我自己输入值,它会在方法中读取它......否则它不会......任何想法? 这是我尽可能多地恢复的代码(有点长):

XHTML:

<!-- Modal -->
            <div class="modal fade" id="myModalId" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
              <div class="modal-dialog">
                <div class="modal-content">
                  <div class="modal-header bg-warning">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="myModalLabel"><b>#{msg.html32}</b></h4>
                  </div>
                  <div class="modal-body">
                   <center style="font-size: 14px">#{msg.html31}</center>
                  </div>
                  <div class="modal-footer">
                    <p:commandLink  action="#{bd.setId(dotcalpro.id)}"  styleClass="btn btn-md btn-info" value="#{msg.htmlborrar}" immediate="true" update="tbResult, growl" accesskey="r" onclick="modalIdhide()"/>
                    <p:spacer height="5"/>
                    <p:commandLink  styleClass="btn btn-md btn-info" value="#{msg.html48}" immediate="true" update="tbResult, growl" onclick="modalIdhide()"/>
                   </div>
                </div>
              </div>
            </div>  

        <p:column width="60">  
        <f:facet name="header">#{msg.dotcalprotbver}</f:facet> 
        <center>
        <button type="button" class="btn btn-warning btn-xs"
        onclick="detalle('#{tb.zid}'); modalIdshow();" >
        <i class="fa fa-search fa-2x"></i>
        </button>
        </center>
        </p:column>  

JS:

function detalle(vT0){
    document.getElementById("formdotcalpro:id").value= rTrim(vT0);
    updateInput('formdotcalpro:id', '#F2F2F2')
    //alert(document.getElementById("formdotcalpro:id").value);
    var x = document.getElementById("formdotcalpro:id").value;
    alert("valor: " + x)
}

//Modal id show
function modalIdshow(){
    $("#myModalId").modal();
}


//Modal id hide
function modalIdhide(){
    $("#myModalId").modal('hide');
}

豆子:

/**
 * Setea tipo de valor de la meta para busqueda
 * @param next
 */
public void setId(String id){
    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("id", id);
    System.out.println("valor : " + id);
}

我再说一遍,以防我尽可能多地恢复代码。

【问题讨论】:

    标签: javascript html jsf primefaces


    【解决方案1】:

    好吧,我用我的会话变量找到了某种解决方案......它工作但不太确定它是否是正确的方法。

    刚刚在我的 Bean 类中添加了这个:

    /**
     * Setea tipo de valor de la meta para busqueda
     * @param next
     */
    public void setId(String id){
        HttpServletRequest rq = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        String idval = rq.getParameter("formdotcalpro:id");
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("id", idval);
        //System.out.println("valor : " + idval);
    }
    

    如果你有时间,我仍然欢迎对这个问题提出另一种观点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 2015-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-15
      • 2021-06-07
      相关资源
      最近更新 更多