Results 1 to 3 of 3

Thread: What is the best way to display a string result of a static pojo method

  1. #1
    Join Date
    Nov 2010
    Location
    Santo Domingo, Albay Philippines
    Posts
    158

    Default What is the best way to display a string result of a static pojo method

    I have a page index.jspx in a web mvc application

    Code:
    <!-- selects a static view for rendering without the need for an explicit controller -->
    <mvc:view-controller path="/" view-name="index"/>
    I have a static method on an entity class that returns a string.

    In screens where I use a custom controller I use

    Code:
    @ModelAttribute("currentZone")
    public String getCurrentZone(){
    	return ZoneElement.getCurrentZone();
    }
    
    and
    
    ${currentZone} in the page to display the value
    What is the best way to display this same static method result in the index.jspx?

    I want to avoid creating a controller just for this one little bit of data, or a custom tag for that matter, but I suppose if that's the best way, so be it. I am probably over thinking this.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Create a HandlerInterceptor which adds this to the model, saves you also adding this method to all controllers. That way the property is always present.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Nov 2010
    Location
    Santo Domingo, Albay Philippines
    Posts
    158

    Default

    Excellent, and in that Interceptor I can branch so only those pages that need this attribute will make the call. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •