Custom View Screen

Hello Haulmont team,

My goal for this post is to create a custom “view” screen that displays an instance of an entity in a custom layout and doesn’t require the use of uneditable form elements. (By the way, I think this would be a very useful addition to the framework.) I’m halfway there, but I first want to know if what I’ve done so far could be done better, and second, want to figure out how to properly display variable elements in this screen.

So I created an entity and standard browse/edit screens. In my case, this is a simple “knowledgebase” type of collection. After I set this up with some simple show/hide logic on the edit screen, I began the custom “view” screen by adding a blank screen. I finally got this screen opening correctly by changing the controller class to extend StandardEditor instead of Screen and adding the @EditedEntityContainer annotation. This finally got me to the point where the screen is opening and sending in the instance’s ID. So, if any of that is being done incorrectly, please let me know.

I have initially set this “view” descriptor to include an htmlBox, and tried to send my data in that way from the controller file. It worked fine until I tried sending in variable content from the instance, which is when I got a “missing layout file” error. So now, I’m trying to figure out the right way to do this. My goals aren’t complicated on the surface. The “view” screen will just display the contents of the instance fields in text format.

I’ve been searching the manual and forum most of the day, without finding what I need (unless, of course, I simply didn’t make the connection that something I’ve seen is what I need to do.) I’ve attached a simple project sample for you to look at, if you need it.

kb.zip (105.5 KB)

Please let me know if there is any further information I can provide.

Thanks in advance,
Adam

Hi Adam,

I guess you are aware of the standard edit action, right? ViewAction - CUBA Platform. Developer’s Manual

In case yes, what is the Problem with uneditable Form fields, is it the Lay-out appearance on the screen?

Bye
Mario

Correct. It just looks forced/lazy being uneditable form fields, which is why I’m trying to get it to look like a normal web page with proper formatting.

Thanks,
Adam

Hi,

what I did in the past with similar requirements was to adjust the appearance using CSS and stylename attribute of the form component. Probably it is easier than building up a dedicated new screen. But this is obviously up to you to decide :slight_smile:

Cheers
Mario

Hello Mario,

So there is not a way to pass these instance variables to the screen from the controller using a blank screen?

Adam

No, this is totally possible. It is just a little bit bit more manual programming involved, depending on how you are planning to do it.

You can start with the label component e.g Label - CUBA Platform. Developer’s Manual. You can use setValue or alternatively also use the databinding against a data container.

Bye
Mario

Hi,

As far as I get your goal, HtmlBox doesn’t fit your needs. I’d recommend using the Label component with htmlEnabled="true", e.g.:

public class KnowledgeBaseView extends StandardEditor<KnowledgeBase> {

    @Inject
    private Label<String> content;

    @Subscribe
    protected void onAfterShow(AfterShowEvent event) {
        KnowledgeBase item = getEditedEntity();

        content.setValue(
                "<div class=\"box-container\">" +
                        "<h1>Title</h1>" +
                        "<h3>" + item.getTitle() + "</h3>" +
                        "</div>"
        );
    }
}

Regards,
Gleb

1 Like

Gleb,

Thank you so much for showing my a way to do this with a small example. This will suit my needs perfectly!

Adam