how to display images in list table

Help
2010-05-17
2013-04-29
  • jkoulwebster
    jkoulwebster
    2010-05-17

    Hi Luca:
      I wanna display image in person data list page,so I have added some code into PersonListable.java,below is the code segment::

    @ViewField(render = ViewConstants.RENDER_HTML)
          public String getPhoto() {
        return Utils.getPhoto(entity);
    }
    

    and Utils.java is here:

    String path = HttpAbstractSessionAspect.getServletRequest().getContextPath();
    return "<a href='" + path + "/app/direct/profile/" + user.getName().toLowerCase() + "'><img src='" + path
                    + "/static/images/users/" + user.getName().toLowerCase() + ".png'/></a>";
        }
    

    but unfortunately,I can not see the image but see "<a href="/roma/app/direct/profile/manson"><img src="/roma/static/images/users/manson.png"></a>",what can I do to display the image in list table?

    Thanks;
    JK.WST

     
  • Luca Molino
    Luca Molino
    2010-05-17

    Hi , what view module are you using? Janiculum or Echo2?

     
  • jkoulwebster
    jkoulwebster
    2010-05-17

    Hi,I am using Echo2 module,what's the trouble with it?
    Thanks.

     
  • Luca Molino
    Luca Molino
    2010-05-17

    In echo2 tables the problem is that any field is render as label, to avoid this problem you should render it as a TABLEEDIT like this:

    public class PersonMain{

    @ViewField(render = ViewConstants.RENDER_TABLEEDIT)
    List<PersonListable> result;

    }

    public class PersonListable{

    @ViewField(render = ViewConstants.RENDER_HTML) public String getPhoto() { return Utils.getPhoto(entity); }

    @ViewField(render = ViewConstants.RENDER_LABEL) public String getName() { return entity.getName(); }

    }

    I know it's a little bit complicated but unfortunately that's the only way to display images in a table.

     
  • jkoulwebster
    jkoulwebster
    2010-05-17

    Hi Luca,strange,very strange! I have done followed your advice,but I still can not see the image,only the "<a href=xxx>xxx</a>"displayed in the list table.why?
    Thanks.

     
  • jkoulwebster
    jkoulwebster
    2010-05-17

    Hi Luca,I have found the problem,though I have definied "render=ViewConstants.RENDER_TABLEEDIT" in PersonMain,but when I opens the designer module,I have found that the render of "result" is still the "table",not the "tableedit",so if I modify via the design module,it is ok now.
    Luca,I think maybe it is a bug.
    Thanks.

     
  • Luca Molino
    Luca Molino
    2010-05-17

    Ok, try that:

    @ViewField(render = ViewConstants.RENDER_IMAGE) public String getPhoto() { return Utils.getPhoto(entity); }

    Your Util.getPhoto Method:{
    return user.getName().toLowerCase() + ".png"; }

    And in your applicationContext-view-echo2.xml put your image folder as property like this

    <bean class="org.romaframework.aspect.view.echo2.look.LookAndFeelManager" dependency-check="default" id="LookAndFeelManager"
    singleton="true">
    <constructor-arg ref="AutoReloadManager" />
    <property name="imagePaths">
    <list>
    <!- ADDITIONAL PATHS TO DISCOVER IMAGES ->
    <value>file:./static/custom/photos</value>
    <value>file:./static/base/photos</value>
    </list>
    </property>

    That should work. If it doesn't try changing your getPhoto method like this:

    {return "$" + user.getName().toLowerCase() + ".png"; }

    If it still doesn't work keep this method behaviour and change your PersonListable method as:

    @ViewField(render = ViewConstants.RENDER_LINK, enabled = AnnotationContsants.FALSE) public String getPhoto() { return Utils.getPhoto(entity); }

    I'm sorry but echo2 table render works in a little strange way

     
  • Hi,
    I suggest you to use Janiculum. Is far better than Echo2 and much more flexible.

    However for you problem try to check of the annotaiton resides into the XML file as well.

    Chris

     
  • Luca Molino
    Luca Molino
    2010-05-17

    Ok , i read your reply too late… well i don't think that's a real bug, the problem is that you extend CRUDMain, and in CRUDMain the result rendering is a "table", or you have a PersonMain.xml that uses "table" as rendering for the result.

    Usually i simply override the getResult method like this and it works.

    @Override
    @ViewField(render = ViewConstants.RENDER_TABLEEDIT)
    public List<PersonListable> getResult() {
    return result;
    }

     
  • jkoulwebster
    jkoulwebster
    2010-05-18

    Luca,thanks a lot,it is fine now.