jsf - Setting f:setPropertyActionListener value with a f:param value -


i'm trying use setpropertyactionlistener tag set value in backing bean. however, doesn't work expected.

context: userservice instance of backing bean, contains int member, reqid. this, in turn, key map of objects belong class called user. i'm trying create page list instances of user, , provide button visit separate view shows particular user's information. this, i'm attempting set userservice.reqid id of chosen user can generate reference user next view (which done in call userservice.touserinfo).

if use xhtml snippet below:

<ui:define name="content">         <h:form>             <h:panelgrid>                     <ui:repeat value="#{userservice.userlist.getuserlist()}" var="user">                         <li>                             <h:outputtext value="#{user.name}" />                             <h:commandbutton value="view details of #{user.name}" action="#{userservice.touserinfo}">                             <f:param name="id" value="#{user.id}" />                             <f:setpropertyactionlistener target="#{userservice.reqid}" value="#{id}"/>                             </h:commandbutton>                          </li>                     </ui:repeat>              </h:panelgrid>         </h:form>     </ui:define> 

the tag not appear evaluate id correctly , null pointer exception.

earlier, tried changing setpropertyactionlistenertag read out as:

<f:setpropertyactionlistener target="#{userservice.reqid}" value="id"/> 

which gave me error, because tag sending string "id" opposed int value of parameter.

is there way force f:setpropertyactionlistener evaluate expression under value? or there tag allow me this?

also, ui:param used appropriately here?

the <f:param> (and <ui:param>) doesn't work way. <f:param> intented add http request parameters outcome of <h:xxxlink> , <h:xxxbutton> components, , parameterize message format in <h:outputformat>. <ui:param> intented pass facelet context parameters <ui:include>, <ui:decorate> , <ui:define>. mojarra had bug behaves <c:set> without scope. not intented usage.

just use <c:set> without scope if it's absolutely necessary "alias" (long) el expression.

<c:set var="id" value="#{user.id}" /> 

put outside <h:commandlink> though. in construct, it's kind of weird. doesn't make code better. i'd leave out it.

<f:setpropertyactionlistener ... value="#{user.id}" /> 

see also:


unrelated concrete problem, if you're using el 2.2 (as you're using jsf 2.2, undoubtedly requires minimum of servlet 3.0, goes hand in hand el 2.2), pass bean action method argument without <f:setpropertyactionlistener> mess. see a.o. invoke direct methods or methods arguments / variables / parameters in el , how can pass selected row commandlink inside datatable?

<h:commandbutton ... action="#{userservice.touserinfo(user.id)}"> 

on again unrelated note, such "view user" or "edit user" request idempotent. you'd better use <h:link> (yes, <f:param>) this. see a.o. creating master-detail pages entities, how link them , bean scope choose , how navigate in jsf? how make url reflect current page (and not previous one).

oh, <h:panelgrid> around <ui:repeat><li> doesn't make sense in html perspective. rid of , use <ul> instead. see htmldog html beginner tutorial.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -