How to pass a row object to the backing bean using JSF 2 and RichFaces? -



How to pass a row object to the backing bean using JSF 2 and RichFaces? -

i using richfaces's ordering list display table custom command objects user. user uses form create new commands added list. here orderinglist implementation:

app.xhtml <rich:orderinglist id="olist" value="#{commandbean.newbatch}" var="com" listheight="300" listwidth="350" converter="commandconverter"> <f:facet name="header"> <h:outputtext value="new batch details" /> </f:facet> <rich:column width="180"> <f:facet name="header"> <h:outputtext value="command type" /> </f:facet> <h:outputtext value="#{com.commandtype}"></h:outputtext> </rich:column> <rich:column> <f:facet name="header"> <h:outputtext value="parameters" /> </f:facet> <h:outputtext value="#{com.parameters}"></h:outputtext> </rich:column> <rich:column> <h:commandbutton value="remove #{com.id} : #{com.seqno}" action="#{commandbean.remove(com.id,com.seqno)}" onclick="alert('id:#{com.id} seqno:#{com.seqno}');"/> </rich:column>

my troubles began when tried implement remove button send command's id , seqno backing bean (cb) removed list. here backing bean:

import javax.faces.bean.managedbean; import javax.faces.bean.sessionscoped; @managedbean @sessionscoped public class commandbean implements serializable{ private static final long serialversionuid = 1l; private commandtype type; private string parameters; private list<command> newbatch = new arraylist<command>(); private set<command> commandset = new hashset<command>(); private string msg = "not removed"; public commandtype[] getcommandtypes() { homecoming commandtype.values(); } public void addcommand(commandtype type, string parameters) { newbatch.add(new command(type, parameters)); } commandtype gettype() { homecoming type; } void settype(commandtype type) { this.type = type; } string getparameters() { homecoming parameters; } void setparameters(string parameters) { this.parameters = parameters; } public list<command> getnewbatch() { homecoming newbatch; } public void setnewbatch(list<command> newbatch) { this.newbatch = newbatch; } public set<command> getcommandset() { homecoming commandset; } public void setcommandset(set<command> commandset) { this.commandset = commandset; } string getmsg() { homecoming msg; } public void remove(integer id, integer seqno) { for(command c : newbatch) { if(c.getid() == id && c.getseqno() == seqno) { newbatch.remove(c); msg = "removed " + c; return; } } msg = string.format("%d : %d", id,seqno); } }

when command (com)'s id , seqno passed via #{cb.remove(com.id,com.seqno)} both 0. read somewhere null values transformed 0's, explain it. tried pass command object straight via #{cb.remove(com)} command null when bean tried process it.

i'm betting there off scoping, new jsf figure out...

update

i have eliminated conflicting @named tag , have updated html reflect new name of bean, namely commandbean. still having issues though.

you can pass 2 values request parameters:

<h:commandbutton ... > <f:param name="id" value="#{com.id}"/> <f:param name="seqno" value="#{com.seqno}"/> </h:commandbutton>

and retrieve them in managed bean this:

httpservletrequest request = ((httpservletrequest)facescontext.getcurrentinstance().getexternalcontext().getrequest()); system.out.println(request.getparameter("id")); system.out.println(request.getparameter("seqno"));

jsf richfaces cdi

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -