开发者

Editable Datatable using a Dialog in JSF 2.0

I am currently running my web application in JSF 2.0, It also is using Primefaces 2.2RC2.

I know that primefaces gives you the ability to have editable rows, but for my project I would prefer if a user clicks on a commandButton within the table that a dialog is displayed prepopulated with that particular rows values 开发者_如何转开发and the user can edit the row that way.

The only way I have gotten this to work is to in the column that contains the commandButton, pass that rows contents as params like the example below:

<p:dataTable var="car" value="#{myBean.cars}" id="carList">  
   <h:column>
         <h:inputText value="#{car.id}" style="width:100%"/> 
   </h:column>

   <h:column>
        <h:inputText value="#{car.name}" style="width:100%"/> 
   </h:column>
   <h:column>
        <h:commandButton actionListener=#{myBean.updateRow} onsuccess="editCardDialog.show()" >
           <f:param name="carId" value=#{car.id} />
           <f:param name="carName" value=#{car.name} />
        </h:commandButton>
    </h:column>

    ...
</p:dataTable>

So my Question is this, currently the only way I have gotten this to work is to in my backing bean create dummy temp global variables to set the params to so when my dialog opens it can reference the values like this

     //myBean.java
     private String tempCarId;
     private String tempCarName;

     public void setTempCarId(String tempCarId) {
          this.tempCarId = carId;
     }

     public String getTempCarId() {
          return tempCarId;
     }

     public void setTempCarName(String tempCarName) {
          this.tempCarName = carName;
     }

     public String getTempCarName() {
          return tempCarName;
     }

     public void updateRow(ActionEvent event) {

            String carId = FaceContext...getParameterMap("carId");
            String carName = FacesContext...getParameterMap("carName");

            setTempCarId(carId);
            setTempCarName(carName);      
     }

Then in the dialog I will just reference those temp variables

    <p:dialog>
        <h:inputText value=#{myBean.tempCarId} />
        <h:inputText value=#{myBean.tempCarName} />
    </p:dialog>

I am not sure if this is the correct way of doing it. My gut is telling me its not because it seems extremely redundant to have to create temp variables in my Bean just so I can pass them to the dialog. Does anyone know of a better more concise way of doing this so I dont have to create a million temporary variables in my backing bean?


Just replace the outputTexts in dialog below with inputTexts;

http://www.primefaces.org/showcase/ui/datatableRowSelectionByColumn.jsf

or

http://www.primefaces.org/showcase/ui/datatableRowSelectionInstant.jsf

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜