English 中文(简体)
facelets: passing bean name with ui:param to action attribute
原标题:

Due to some custom components which expect a bean name (NOT the bean instance) in their attributes I need to pass the actual bean name between pages. As the bean itself is also used by non-custom components, I would like to avoid using additional ui:param (like described here Passing action in <rich:modalPanel>) since it will essentially specify the same bean.

Is it possible to specify component s action using bean name provided with ui:param?

Basically I am trying to achieve the following:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/template.xhtml">

   <ui:param name="beanName" value="sessionBean"/>
   ...

</ui:composition>

and template.xhtml is

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
template="/someothertemplate.xhtml">

  </ui:define name="somename">
    <h:form>
        <a4j:commandButton value="test" action="#{beanName.delete}"/>
    </h:form>
  </ui:define>
</ui:composition>

Although delete method is properly defined (verified with action="#{sessionBean.delete}") the above code gives me

javax.faces.FacesException: #{beanName.delete}: javax.el.MethodNotFoundException: /template.xhtml @201,89 action="#{beanName.delete}": Method not found: sessionBean.delete()

最佳回答

You should be able to reference the bean via its scope:

 <a4j:commandButton value="test"
      action="#{sessionScope[beanName].delete}"/>
问题回答
<a4j:commandButton value="test" action="#{bean[action]}" />

The params to pass

<ui:param name="bean" value="#{sessionBean}" />
<ui:param name="action" value="delete" />

you can use #{bean[ delete ]} if your action name is fixed.





相关问题
JSF a4j:support with h:selectManyCheckbox

I m having trouble with a JSF selectManyCheckbox and A4J support. The purpose is to run some action when a checkbox is selected. This works perfectly in Firefox. Yet, when testing in any IE (ie6 / ie7 ...

Mojarra for JSF Encoding

Can anyone teach me how to use mojarra to encode my JSF files. I downloaded mojarra and expected some kind of jar but what i had downloaded was a folder of files i don t know what to do with

如何拦截要求终止?

在共同基金中,如果用户要求终止,就需要采取一些行动。 我需要某种拦截器,但我不知道如何这样做。 我需要帮助。 增 编

ICEFaces inputFile getting the file content without upload

Is there any way of just getting the content of the browsed file without any upload/file transfer operations? I currently use ICEFaces inputFile component but I do not need the default uploading ...

Weird behaviour of h:commandLink action (MethodExpression)

I have two JSPs where I am displaying some info from database in a h:dataTable. One of them is showing all the info, and one of them user specifically. I have showXML.jsp that shows the "XML" column ...

How to correctly use ResultSet with h:dataTable

The problem is, that after displaying the ResultSet with <h:dataTable>, the connection is left open. If I close it, it closes the ResultSet too. I m thinking about copying the ResultSet data ...

热门标签