将参数传递给overlaypanel jsf2

时间:2014-08-01 16:04:49

标签: java jsf primefaces

我使用spring JSF-2 and primefaces

我在OneToManyFiliale之间有Commentaire的关系。 我需要添加Commentaire。 但我有问题通过id of Filiale

我有以下代码:

    

<f:param name="idFiliale" value="#{filialeBean.details.filiale}" ></f:param>
        <f:viewParam id ="id" name="idFiliale" ></f:viewParam>

                    </f:metadata>
</ui:define>

...

<p:commandButton id="commentBtn" value="Dynamic" type="button" >

<p:overlayPanel id="commentPanel" for="commentBtn" hideEffect="fade" dynamic="true" style="width:600px">

    <p:panel header="Nouveau Commentaire" style="width:450px;height:250px;border:none;font-size:small;padding:0px;" >

        <h:form>
             <p:panelGrid columns="2" cellpadding="2">
                <h:outputLabel for="date" value="Date:" />
    <p:calendar id="date" value="#{commentaireBean.comment_date}" pattern="dd-MM-yyyy" mask="true" />

                <h:outputText for="text" value="Commentaire:" />

    <h:inputTextarea value="#{commentaireBean.comment_text}"></h:inputTextarea>

                <h:commandButton type="submit" value="Ajouter Commentaire"
                    action="#{commentaireBean.addCommentaire(idFiliale)}" >
                    <f:param  name="idFiliale" value="#{idFiliale}"></f:param>
                    </h:commandButton>
            </p:panelGrid>
        </h:form>
    </p:panel>
</p:overlayPanel>
</h:form>



@Component("commentaireBean")
@Scope("session")
public class CommentaireBean {

    @Autowired
    private CommentaireService commentService;

    @Autowired
    FilialeService filialeService;

String idfiliale= (String)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("idFiliale" );

public void addCommentaire(Long filiale_id){
        commentaire = new Commentaire();
             commentaire.setComment_text( getComment_text() );

             Long id = Long.parseLong(idfiliale);
             System.out.println("id" + id);

             commentaire.setFiliale( filialeService.getFiliale(id ));
            commentaire.setComment_date( comment_date );
          System.out.println("avant d'ajourer");
             commentService.addCommentaire( commentaire );
             System.out.println("après d'ajourer");

             FacesMessage message = new FacesMessage( "Ajout de commentaire reussi!" );
             FacesContext.getCurrentInstance().addMessage( null, message );
              }
}

错误:

Caused by: java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:453)
at java.lang.Long.parseLong(Long.java:483)
at com.ant.pbacklog.managedbean.FilialeBean.getFiliale_id(FilialeBean.java:102)
at com.ant.pbacklog.managedbean.FilialeBean.getCommentaires(FilialeBean.java:227)

1 个答案:

答案 0 :(得分:0)

您的idFiliale对象必须有一个getter和setter。然后你可以这样做:

<h:commandButton type="submit" value="Ajouter Commentaire"
    action="#{commentaireBean.addCommentaire(idFiliale)}" >
  <f:setPropertyActionListener value="#{idFiliale}" target="#{filialeBean.idFiliale}"/>
</h:commandButton>