簡體   English   中英

為什么這個參數在我的Bean中被發送為Null?

[英]Why this param is being sent as Null in my Bean?

我正在使用JSF 2和EJB 3.1來創建表單。

我正在使用頁面的這一部分來獲取一些數據,所以我可以使用下面的confirmDialog將它傳遞給我的bean

<p:column headerText="#{bundle.edit}" style="width:10px; overflow:visible;">  
    <p:rowEditor/>                            
</p:column>
<p:column headerText="#{bundle.delete}" style="width:10px; overflow:visible;">
    <p:commandButton update=":form" oncomplete="confirmation.show()" 
                     image="ui-icon ui-icon-close" title="Delete">  
        <f:param value="#{user}" name="userAction" />
    </p:commandButton>  
</p:column>
</p:dataTable>

<p:confirmDialog message="Are you sure? user:#{param['userAction']} " width="500"  
                    header="Confirm" severity="alert" widgetVar="confirmation">  
    <p:commandButton value="Yes sure" update=":form" 
              actionListener="#{userController.deleteAction(param['userAction'])}"
              oncomplete="confirmation.hide()" />  
    <p:commandButton value="Not yet" onclick="confirmation.hide()" type="button" />  

</p:confirmDialog>

</h:form>

而這就是應該得到它的Bean

@Named(value = "userController")
@Stateful
@RequestScoped
@TransactionManagement(TransactionManagementType.CONTAINER)
public class UserController implements Serializable {

    private User current;

    @Inject
    private br.com.cflex.itm.dataaccess.UserFacade userFacade;

    public UserController() {
    }

    public void deleteAction(User user) {
        userFacade.remove(user);
    }

但是我的bean只接收null作為User,並且在Dialog中我打印數據,所以我可以看到在那里選擇了一個User Object。

傳遞這樣的參數有什么不對?
為什么我的Bean中出現空值? 因為他們迷失在客戶端和服務器端之間的通信中......

<p:commandButton action="#{userController.deleteAction(param['userAction'])}" />

在提交表單時評估action EL(和actionListener ),而不是在顯示表單時評估。 請求參數是請求范圍的,並且在表單提交的后續請求中不存在。 你需要傳遞它:

<p:commandButton action="#{userController.deleteAction(param['userAction'])}">  
    <f:param name="userAction" value="#{param['userAction']}" />
</p:commandButton>

在顯示表單時評估<f:param>的EL。 因此它將在生成的HTML中存在並且JavaScript將注意它被傳遞。

請注意,請求參數是String類型。 期望他們成為User根本不會工作。 基本上,它包含User#toString()的值。 您需要將String作為操作參數並將其自己轉換為User 或者更好,使用<f:viewParam>其中您可以顯式指定轉換器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM