You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "K. Johnson" <in...@streetcookie.com> on 2006/11/20 16:43:08 UTC

problem with extended commandLink

I have extended the htmlCommandLink component in order to add some parameters to the tag, that will effect the rendered output of the component. This works fine, with one problem I cannot get passed. When i use it inside a dataTable,  the string value passed in to the parameter is accessbile and correct in the renderer when the page is first rendered. 

But when the page is 'refreshed' (through a null navigation outcome, or during a header sort in the dataTable) the parameter being passed in becomes null. 

Any help is appreciated. 

Thanks!


String parameter 'displayAdditionalText' is what i am adding to the component: 
String displayPlainText has been defined with standard getter and setter in both the tag and component.


The tag:

  /**
     * 
     * @see javax.faces.webapp.UIComponentTag#setProperties(javax.faces.component.UIComponent)
     * @param component UI Component
     */
    public void setProperties(UIComponent component) {
        // Pass through superclass-defined properties
        super.setProperties(component);

        // Pass through simple properties
        setStringAttribute(component, "displayAdditionalText", this.displayAdditionalText);
    }   
    
    /**
     * <p>
     * If the specified attribute value is not <code>null</code> use it to either store a value binding expression for
     * the specified attribute name, or store it as the literal value of the attribute.
     * </p>
     * 
     * @param component <code>UIComponent</code> whose attribute is to be set
     * @param name Attribute name
     * @param value Attribute value (or <code>null</code>)
     */
    protected void setStringAttribute(UIComponent component, String name, String value) {
        if (value == null) {
            return;
        }
        if (isValueReference(value)) {
            ValueBinding vb = getFacesContext().getApplication().createValueBinding(value);
            component.setValueBinding(name, vb);
        } else {
            component.getAttributes().put(name, value);
        }
    }



The renderer  (in the encode method i call wirteAdditionalText) :

   /**
     * Writes commandLink value out as text when insiteRendered is false
     * and displayPlainText is not false;
     * @param context
     * @param component
     */
    private void writeAdditionalText(FacesContext context, UIComponent component) {
        ResponseWriter writer = context.getResponseWriter();
        MyCommandLink myLink = (MyCommandLink) component;
        String displayText= myLink.getDisplayAdditionalText();
      
        if ((Boolean.FALSE.toString().equalsIgnoreCase(displayAdditionalText))) {
            return; 
        } else if (displayAdditionalText == null) {
          log.debug("why is displayAdditionalText null?");           }
       
        try {
            writer.write(String) myLink.getValue()); 
           } catch (Exception e) {
            LOG.warn("Problem writing commandLink value out as text", e);
        }   
    }