[Beginners Corner] - a4j help
by philbrowndotcom
I'm trying to create a jsf custom table component extending HtmlDataTable. I need to implement pagination so I want to incorporate command links for first, last, next, and prev. How do I get the commandLinks to fire the methods in the component to update its attributes and reRender the entire component. I was moving in the direction of using A4J, but could not get the reRendering to occur. Here is what I have so far.
|
| /*
| * Created on Jul 19, 2004
| *
| */
| package net.em.com.components;
|
| import java.util.ArrayList;
| import javax.el.ValueExpression;
| import javax.faces.context.FacesContext;
| import javax.faces.component.html.HtmlDataTable;
| import javax.faces.component.html.HtmlOutputText;
| import net.em.com.tags.table.ListAlgorithm;
| import org.ajax4jsf.ajax.html.HtmlAjaxCommandLink;
| import org.ajax4jsf.framework.ajax.AjaxEvent;
| import org.ajax4jsf.framework.ajax.AjaxListener;
| import org.apache.commons.logging.Log;
| import org.apache.commons.logging.LogFactory;
|
| public class UITable extends HtmlDataTable implements AjaxListener {
|
| private static final Log log = LogFactory.getLog(UITable.class);
|
| // To support commands on the data prior to sorting and pagination
| private Class algorithm = null;
| private String algorithmCriteria = "";
| private boolean algorithmApplied = false ;
|
| // To Support pagination
| private boolean paginate = false ;
| private int pageSize = 10 ;
| private int currentPage = 1 ;
| private String firstTxt = "First" ;
| private String lastTxt = "Last" ;
|
| //To Support AJAX
| private String reRender ;
| private String eventsQueue = "dummy" ;
| private int requestDelay = 10 ;
|
| public void processAjax(AjaxEvent event) {
| Object j = event ;
| }
|
| public Object saveState(FacesContext context) {
| return super.saveState(context);
| }
| public void restoreState(FacesContext context, Object state) {
| super.setRendered(true) ;
| this.currentPage = 3 ;
| super.restoreState(context, state);
|
| }
| public String getFamily(){
| return "em.EmTable";
| }
| public String getRendererType(){
| return "javax.faces.Table";
| }
|
| public String getAlgorithmCriteria() {
| return algorithmCriteria;
| }
|
| public void setAlgorithmCriteria(String algorithmCriteria) {
| this.algorithmCriteria = algorithmCriteria;
| }
|
| public String getAlgorithmClass() {
| return (this.algorithm != null) ? this.algorithm.toString() : "";
| }
|
| public void setAlgorithmClass(String val) {
| if(val.length() > 0) {
| try {
| this.algorithm = Class.forName(val);
| if(!IterableAlgorithm.class.isAssignableFrom(this.algorithm)) {
| this.algorithm = null;
| }
| } catch (Exception e) {
| this.algorithm = null;
| }
| } else {
| this.algorithm = null;
| }
| if(this.algorithm == null) {
| log.info(this.getClass().toString() + ":setAlgorithm(String className)");
| log.info(val + "not of type: " + ListAlgorithm.class.toString());
| } else {
| this.algorithmApplied = false ;
| }
| }
|
| public void setValue(Object value) {
| this.algorithmApplied = false ;
| if(!Iterable.class.isAssignableFrom(value.getClass())) {
| ArrayList list = new ArrayList() ;
| list.add(value) ;
| super.setValue(list) ;
| } else {
| super.setValue(value) ;
| }
| }
|
| public Object getValue() {
| if(this.algorithmApplied == false && this.algorithm != null) {
| this.algorithmApplied = true ;
| setValue(applyAlgorithm((Iterable)super.getValue())) ;
| }
| if(isPaginate()){
| setRows(this.getPageSize());
| }
| //return retVal ;
| return super.getValue();
| }
|
| public void next() {
| setFirst(getFirst() + getPageSize());
| setCurrentPage(getCurrentPage() + 1);
| //enable prev
| if((getFirst() + getPageSize()) >= getRows()){
| //no more rows to display, disable "next" button?
| }
| }
| public void prev() {
|
|
| if((getFirst() - getPageSize()) < 0){
| setFirst(0);
| setCurrentPage(1);
| //hit start of table, diable "prev" button?
| }else{
| setFirst(getFirst() - getPageSize());
| setCurrentPage(getCurrentPage() - 1);
| //enable next
| }
| }
| public void last() {
| this.setFirst((getRows()/getPageSize()) * getPageSize());
| this.setCurrentPage(getRows()/getPageSize());
| //disable next, enable prev
|
| }
| public void first() {
| setFirst(0);
| setCurrentPage(1);
|
| //disable prev, enable next
| }
| public int getCurrentPage() {
| return (Integer)getProperty("currentPage", this.currentPage) ;
| }
|
| public void setCurrentPage(int currentPage) {
| this.currentPage = currentPage;
| }
|
| private Iterable applyAlgorithm(Iterable original) {
| this.algorithmApplied = true;
| Iterable results;
| try {
| IterableAlgorithm a = (IterableAlgorithm)this.algorithm.newInstance();
| a.setCriteria(this.getAlgorithmCriteria());
| results = a.Manipulate(original);
| } catch (Exception e) {
| e.printStackTrace();
| log.info(this.getClass().toString() + ":applyAlgorithm()");
| log.info(this.algorithm.toString() + " must support non parametized constructor" );
| log.info("algorithm not applied");
|
| results = original;
| }
| return results;
| }
|
| public boolean isPaginate() {
| return (Boolean)getProperty("paginate", this.paginate) ;
| }
|
| public void setPaginate(boolean paginate) {
| this.paginate = paginate;
| }
|
| public int getPageSize() {
| return (Integer)getProperty("pageSize", this.pageSize) ;
| }
|
| public void setPageSize(int pageSize) {
| this.pageSize = pageSize;
| }
|
| private Object getProperty(String att, Object field) {
| if (field != null) return field;
| ValueExpression ve = this.getValueExpression(att);
| if (ve != null) return (String) ve.getValue(this.getFacesContext().getELContext());
| return null;
| }
|
| public HtmlAjaxCommandLink getCmdLnkLast(FacesContext facesCtx) {
|
| HtmlAjaxCommandLink cmdLnkLast = (HtmlAjaxCommandLink)getComponent(facesCtx, HtmlAjaxCommandLink.COMPONENT_TYPE) ;
| cmdLnkLast.setParent(this) ;
| cmdLnkLast.setId(this.getId() + "_LAST");
| cmdLnkLast.setReRender(this.getId()) ;
| cmdLnkLast.setRequestDelay(this.requestDelay) ;
| cmdLnkLast.setEventsQueue(this.eventsQueue) ;
|
| HtmlOutputText text = (HtmlOutputText)getComponent(facesCtx, HtmlOutputText.COMPONENT_TYPE) ;
| text.setValue(this.lastTxt) ;
|
| cmdLnkLast.getChildren().add(text) ;
|
| return cmdLnkLast;
| }
|
| private Object getComponent(FacesContext facesCtx, String name) {
| return facesCtx.getApplication().createComponent(name) ;
| }
|
| public void setReRender(String reRender) {
| this.reRender = reRender;
| }
| }
|
|
| /*
| * Created on Jul 19, 2004
| *
| */
| package net.em.com.components;
|
| import com.sun.faces.renderkit.html_basic.TableRenderer;
| import java.io.IOException;
| import javax.faces.component.UIComponent;
| import javax.faces.context.FacesContext;
| import javax.faces.render.Renderer;
|
| public class UITableRenderer extends TableRenderer {
|
|
| public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
| UITable table = (UITable)component ;
|
| render(context, table.getCmdLnkLast(context)) ;
|
| super.encodeBegin(context, component) ;
| }
| public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
| super.encodeEnd(context, component) ;
| }
| public void decode(FacesContext context, UIComponent component) {
| super.decode(context, component) ;
| }
|
| private void render(FacesContext context, UIComponent component) throws IOException {
| Renderer renderer = getRendererFor(context, component) ;
| renderer.encodeBegin(context, component) ;
| renderer.encodeChildren(context, component) ;
| renderer.encodeEnd(context, component) ;
| }
|
| private Renderer getRendererFor(FacesContext context, UIComponent c) {
| return context.getRenderKit().getRenderer(c.getFamily(), c.getRendererType());
| }
|
| }
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4056149#4056149
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4056149
18Â years, 10Â months
[JBoss Portal] - Re: Portlet customization with respect to user rloes
by brownfielda
I am having problems with the same thing, actually.
web.xml contains:
| <security-role>
| <description/>
| <role-name>Administrators</role-name>
| </security-role>
| <security-role>
| <description/>
| <role-name>Users</role-name>
| </security-role>
|
portlet.xml contains:
| <security-role-ref>
| <role-name>Users</role-name>
| <role-link>Users</role-link>
| </security-role-ref>
| <security-role-ref>
| <role-name>Administrators</role-name>
| <role-link>Administrators</role-link>
| </security-role-ref>
|
and I'm trying to run the following code:
| if(request.isUserInRole("Administrators"))
| System.out.println("Administrators");
| else if(request.isUserInRole("Users"))
| System.out.println("Users");
| else
| System.out.println("user is in an unknown role");
|
The final else clause catches everything, no matter which account logs in. I've tried this in many different ways, changing capitalization and whether or not there is an 's' on the end. Nothing has worked so far.
Is there something I'm missing in the XML configs?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4056148#4056148
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4056148
18Â years, 10Â months
[JBossWS] - Re: change HTTP status code in a WS fault
by wpfeiffe
James,
Sorry I don't have an answer for you on this, but I just ran into this a few days ago and was wondering if you had a solution.
So far I considered creating my own wrapper obect that would be returned by all web services and would contain fault info.
Also considered dropping JBossWS and using xFire as I've seen examples on how to set the status code with xFire (some dissension concerning whether it actually works though).
Also considered just doing a rest style xml return which flex seems to handle quite nicely.
Really my preference is to do some kind of interceptor that would let me set the status code. I already do some pre-processing of my hibernate return objects to kill the proxies which is believe should be in an interceptor as well. Just not sure where to start there.
Anyway, I'd be interested in hearing how you solve this, if you do.
Thanks,
Bill Pfeiffer
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4056146#4056146
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4056146
18Â years, 10Â months